Source for file Valikkoond.php

Documentation is available at Valikkoond.php

  1. <?php
  2. /**
  3.  * Model for handling queries with database table 'valikkoond'.
  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_Valikkoond extends Zend_Db_Table_Abstract {
  12.         /**
  13.          * Database table name
  14.          * @access protected
  15.          * @var string 
  16.          */
  17.         protected $_name = 'valikkoond';
  18.         
  19.         /**
  20.          * Query fetchResult.
  21.          * Database query that fetches a row from 'valikkoond' 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('koolID = ?'$school);
  39.             if($class != null{
  40.                 $select->where('klassID = ?'$class);
  41.             }
  42.                     
  43.             $result $this->fetchRow($select);
  44.             return $result;
  45.         }
  46.  
  47.         /**
  48.          * Query fetchAreaStatistics.
  49.          * Database query that fetches statistics about 'Valik võistlused'
  50.          * competition. If parameters are given, the query is narrowed down
  51.          * according to them.
  52.          * 
  53.          * @access public
  54.          * @param int $year Year number
  55.          * @param string $class Class number
  56.          * @return mixed $result Query resultset
  57.          */
  58.         public function fetchAreaStatistics($year$class{
  59.             $select $this->select();
  60.             $select->setIntegrityCheck(false);
  61.             $select->from($thisarray(
  62.                     'area' => 'Piirkond.nimetus',
  63.                     'resultsPerArea' => new Zend_Db_Expr('COUNT(Valikkoond.id)'),
  64.                     'pointsTotal' => new Zend_Db_Expr('SUM(Valikpunktid.summa)'),
  65.                     'averageResult' => new Zend_Db_Expr('SUM(Valikpunktid.summa)/COUNT(Valikkoond.id)'),
  66.                     'minimumResult' => new Zend_Db_Expr('MIN(Valikpunktid.summa)'),
  67.                     'maximumResult' => new Zend_Db_Expr('MAX(Valikpunktid.summa)'),                    
  68.                 ))
  69.                 ->join('Kool''Kool.id = Valikkoond.koolID'array())
  70.                 ->join('Klass','Klass.id = Valikkoond.klassID'array())
  71.                 ->join('Voistlustekuupaevad''Voistlustekuupaevad.VoistluseKuupaevaID = Valikkoond.kuupaevID'array())
  72.                 ->join('Piirkond''Piirkond.id = Kool.piirkondID'array())
  73.                 ->join('Valikpunktid''Valikpunktid.id = Valikkoond.punktidID'array());
  74.                 if($class != 0{
  75.                     $select->where('Klass.number = ?'$class);
  76.                 }
  77.                 if($year != 0{
  78.                     $select->where('Voistlustekuupaevad.Kuupaev > ?'$year)
  79.                     ->where('Voistlustekuupaevad.Kuupaev > ?'$year+1);
  80.                 }
  81.                 $select->group('Piirkond.nimetus');
  82.                 
  83.             return $this->fetchAll($select);
  84.         }
  85.     }
  86. ?>

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