Source for file Loppkoond.php

Documentation is available at Loppkoond.php

  1. <?php
  2. /**
  3.  * Model for handling queries with database table 'loppkoond'.
  4.  * 
  5.  * @author Margus Sellin <margus@bitweb.ee>
  6.  * @copyright Copyright (C) 2011. All rights reserved. Margus Sellin
  7.  * @package Model
  8.  * @project olymp
  9.  * 
  10.  */
  11.     class Model_Loppkoond extends Zend_Db_Table_Abstract {
  12.         /**
  13.          * Database table name
  14.          * @access protected
  15.          * @var string 
  16.          */
  17.         protected $_name = 'loppkoond';
  18.         
  19.         /**
  20.          * Query fetchResult.
  21.          * Database query that fetches a row from 'loppkoond' table
  22.          * where columns 'kuupaevID', 'osalejaID','klassID' and 'koolID'
  23.          * equal the given parameters.
  24.          * 
  25.          * @access public
  26.          * @param int $date Date ID
  27.          * @param int $name Participant ID
  28.          * @param int $class Class ID
  29.          * @param int $school School ID
  30.          * @return mixed $result Query resultset
  31.          */
  32.         public function fetchResult($date$name$school$class)
  33.         {
  34.             $select $this->select();
  35.             $select->from($this)
  36.                     ->where('kuupaevID = ?'$date)
  37.                     ->where('osalejaID = ?'$name)
  38.                     ->where('klassID = ?'$class)
  39.                     ->where('koolID = ?'$school);
  40.             $result $this->fetchRow($select);
  41.             return $result;
  42.         }
  43.         
  44.         /**
  45.          * Query fetchAreaStatistics.
  46.          * Database query that fetches statistics about 'Lõppvoorud'
  47.          * competition. If parameters are given, the query is narrowed down
  48.          * according to them.
  49.          * 
  50.          * @access public
  51.          * @param int $year Year number
  52.          * @param string $class Class number
  53.          * @return mixed $result Query resultset
  54.          */
  55.         public function fetchAreaStatistics($year$class{
  56.             $select $this->select();
  57.             $select->setIntegrityCheck(false);
  58.             $select->from($thisarray(
  59.                     'area' => 'Piirkond.nimetus',
  60.                     'resultsPerArea' => new Zend_Db_Expr('COUNT(Loppkoond.id)'),
  61.                     'pointsTotal' => new Zend_Db_Expr('SUM(Lopppunktid.summa)'),
  62.                     'averageResult' => new Zend_Db_Expr('SUM(Lopppunktid.summa)/COUNT(Loppkoond.id)'),
  63.                     'minimumResult' => new Zend_Db_Expr('MIN(Lopppunktid.summa)'),
  64.                     'maximumResult' => new Zend_Db_Expr('MAX(Lopppunktid.summa)'),                    
  65.                 ))
  66.                 ->join('Kool''Kool.id = Loppkoond.koolID'array())
  67.                 ->join('Klass','Klass.id = Loppkoond.klassID'array())
  68.                 ->join('Voistlustekuupaevad''Voistlustekuupaevad.VoistluseKuupaevaID = Loppkoond.kuupaevID'array())
  69.                 ->join('Piirkond''Piirkond.id = Kool.piirkondID'array())
  70.                 ->join('Lopppunktid''Lopppunktid.id = Loppkoond.punktidID'array());
  71.                 if($class != 0{
  72.                     $select->where('Klass.number = ?'$class);
  73.                 }
  74.                 if($year != 0{
  75.                     $select->where('Voistlustekuupaevad.Kuupaev > ?'$year)
  76.                     ->where('Voistlustekuupaevad.Kuupaev > ?'$year+1);
  77.                 }
  78.                 $select->group('Piirkond.nimetus');
  79.                 
  80.             return $this->fetchAll($select);
  81.         }
  82.     }
  83. ?>

Documentation generated on Mon, 20 Jun 2011 05:43:06 +0300 by phpDocumentor 1.4.1