Source for file ScriptController.php

Documentation is available at ScriptController.php

  1. <?php
  2. /**
  3.  * Controller class for automated script logic and all other actions/methods
  4.  * that are needed to make this portal function.
  5.  * 
  6.  * @author Margus Sellin <margus@bitweb.ee>
  7.  * @copyright Copyright (C) 2011. All rights reserved. Margus Sellin
  8.  * @package Controller
  9.  * @project olymp
  10.  * 
  11.  */
  12. class ScriptController extends Zend_Controller_Action
  13. {
  14.     /**
  15.      * Init method.
  16.      * Built-in method in Zend Framework that applies to all actions in given controller.
  17.      * In this very controller it restricts common user who are not logged in to access
  18.      * administrative actions and functions of this portal.
  19.      * 
  20.      * If user is not logged in and tries to access actions/methods that are meant
  21.      * for administrators only, he/she is redirected to login page.
  22.      */
  23.     public function init()
  24.     {
  25.         if(!Zend_Auth::getInstance()->hasIdentity()) {
  26.             $this->_redirect('/login');
  27.         }
  28.     }
  29.     /**
  30.      * Menu action.
  31.      * Action that is used to display admin menu on the right.
  32.      * This action is called only when user is logged in as administrator.
  33.      */
  34.     public function menuAction({
  35.         
  36.     }
  37.     /**
  38.      * Pages action.
  39.      * Action that is used to display static pages' management page.
  40.      */
  41.     public function pagesAction({
  42.         $modelPage new Model_Page();
  43.         $pages $modelPage->fetchAll();
  44.         
  45.         $this->view->pages $pages;
  46.     }
  47.     /**
  48.      * Edit page action.
  49.      * Action that is used to edit static pages' content.
  50.      */
  51.     public function editPageAction({
  52.         $form new Form_Page();
  53.         
  54.         $pageId $this->_getParam('pageId');
  55.         $modelPage new Model_Page();
  56.         $page $modelPage->fetchRow('id=' . (int)$pageId);
  57.         
  58.         if($pageId != null{
  59.             $page $modelPage->fetchRow('id=' . (int)$pageId);
  60.             $form->populate($page->toArray());
  61.         else {
  62.             $page $modelPage->createRow();
  63.         }
  64.         if($this->_request->isPost()) {
  65.             if ($form->isValid($this->_request->getPost())) {
  66.                 $page->title $form->title->getValue();
  67.                 $page->value $form->value->getValue();
  68.                 $page->save();
  69.                 $this->_helper->redirector('pages''script');
  70.             }
  71.         }
  72.         $this->view->form $form;
  73.     }
  74.      /**
  75.      * Add results action.
  76.      * Used to display a view where user can choose between two adding options.
  77.      */
  78.      public function addResultsAction()
  79.     {
  80.  
  81.     }
  82.     /**
  83.      * Add file action.
  84.      * User inserts a file with result table URL's.
  85.      * The file is read line by line and data from tables given by the URL's
  86.      * in the file is being inserted into database.
  87.      * 
  88.      * Used to insert many tables at the same time.
  89.      */
  90.     public function addFileAction({
  91.         $message '';
  92.         
  93.         if($this->_request->isPost()) {
  94.             $filename $this->_getParam('file');
  95.             set_time_limit(0);
  96.             
  97.             if(file_exists($filename)) {
  98.                 $firstFile file($filename);
  99.                 foreach($firstFile as $file{
  100.                     $file trim($file);
  101.                     if(file_exists($file)) {
  102.                         $date basename($file'.txt');
  103.                         $dateID $this->getDateIDByDateString($date);
  104.                         $fileLines file($file);
  105.                         foreach($fileLines as $url{
  106.                             $str explode('/'$url);
  107.                             $competition $str[4];
  108.                             switch ($competition{
  109.                                 case 'lahtine'$this->saveLahtine($dateIDtrim($url))break;
  110.                                 case 'piirk'$this->savePiirk($dateIDtrim($url))break;
  111.                                 case 'valik'$this->saveValik($dateIDtrim($url))break;
  112.                                 case 'loppv'$this->saveLopp($dateIDtrim($url))break;
  113.                             }
  114.                         }
  115.                         $message 'Andmed edukalt lisatud.';
  116.                     else {
  117.                         $message =  'Faili nimega '.$file.' ei leitud.';
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.         $this->view->message $message;
  123.     }
  124.     /**
  125.      * Add table action.
  126.      * User inserts a table URL with HTML table and a date.
  127.      * 
  128.      * 
  129.      * Used to insert single tables.
  130.      */
  131.      public function addTableAction({
  132.         $modelDates new Model_Kuupaevad();
  133.         $form new Form_Result();
  134.         
  135.         $dates $modelDates->fetchByDates();
  136.         $form->populate($form->getValues());
  137.         
  138.         $message '';
  139.         
  140.         set_time_limit(0);
  141.         $url $this->_getParam('url');
  142.         $date $this->_getParam('date');
  143.         
  144.         if($this->_request->isPost(&& $form->isValid($this->_request->getPost())) {
  145.             if($date == 0{
  146.                 $year $this->_getParam('year');
  147.                 $month $this->_getParam('month');
  148.                 $day $this->_getParam('day');
  149.                 $date $year.'-'.$month.'-'.$day;
  150.             }
  151.             $dateID $this->getDateIDByDateID($date);
  152.             set_time_limit(0);
  153.  
  154.             $str explode('/'$url);
  155.             $competition $str[4];
  156.             
  157.             $info '';
  158.             switch ($competition{
  159.                 case 'lahtine'
  160.                     $this->saveLahtine($dateIDtrim($url))
  161.                     $info 'Lahtiste võistluste andmed edukalt lisatud.';
  162.                     break;
  163.                 case 'piirk'
  164.                     $this->savePiirk($dateIDtrim($url))
  165.                     $info 'Piirkonnavooru andmed edukalt lisatud.';
  166.                     break;
  167.                 case 'valik':
  168.                     $this->saveValik($dateIDtrim($url));
  169.                     $info 'Valikvõistluste andmed edukalt lisatud.';
  170.                     break;
  171.                 case 'loppv':
  172.                     $this->saveLopp($dateIDtrim($url));
  173.                     $info 'Lõppvooru andmed edukalt lisatud.';
  174.                     break;
  175.             }
  176.             $message $info;
  177.         }
  178.         $this->view->message $message;
  179.         $this->view->dates $dates;
  180.         $this->view->form $form;
  181.     }
  182.     /**
  183.      * Method for saving 'Valikvõistlused' competition results.
  184.      * All data from given table URL is being inserted into database.
  185.      * 
  186.      * @access public
  187.      * @param int $date Competition date
  188.      * @param string $url HTML table URL
  189.      */
  190.     private function saveValik($date$url)
  191.     {
  192.         $modelPunktid new Model_Valikpunktid();
  193.         
  194.         $dateID $date;
  195.         $tableRows $this->fetchTableRows($url);
  196.         
  197.         foreach($tableRows as $i => $tableRow{
  198.             if($i 0{
  199.                 $points $modelPunktid->createRow();
  200.                 foreach ($tableRow->childNodes as $j => $dataItem{
  201.                     $length $tableRow->childNodes->length;
  202.                     $length ($length 14)?$length*2:$length;
  203.                     $j ($tableRow->childNodes->length 14)?$j*2:$j;
  204.                     $k $length-18;
  205.                     $data trim($dataItem->nodeValue);
  206.                     if($i == count($tableRows)-&& $tableRow->childNodes->item(0)->nodeValue == ''{
  207.                         $break true;
  208.                         break;
  209.                     }
  210.                     switch($j{
  211.                         case ((int)($length/22))*2$personID $this->fetchPersonID($data)break;
  212.                         case (((int)($length/22))*2)+2$schoolID $this->fetchSchoolIDByString($data)break;
  213.                         case (((int)($length/22))*2)+4$classID ($length != 18)?$this->fetchClassIDByString($data):0;
  214.                         case $k+4$points->p1 = (int)$databreak;
  215.                         case $k+6$points->p2 = (int)$databreak;
  216.                         case $k+8$points->p3 = (int)$databreak;
  217.                         case $k+10$points->p4 = (int)$databreak;
  218.                         case $k+12$points->p5 = (int)$databreak;
  219.                         case $k+14$points->p6 = (int)$databreak;
  220.                         case $k+16$points->summa = (int)$databreak
  221.                     }
  222.                 }
  223.                 if(!isset($break)) {
  224.                     if(!$this->checkValikExistance($dateID$personID$schoolID$classID)) {
  225.                         
  226.                         $points->save();
  227.                         $this->saveValikOverall($personID$dateID$points->id$classID$schoolID);
  228.                     else {
  229.                         $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  230.                     }
  231.                 }
  232.             }    
  233.         }
  234.     }
  235.     /**
  236.      * Method for saving 'Lahtised võistlused' competition results.
  237.      * All data from given table URL is being inserted into database.
  238.      * 
  239.      * @access public
  240.      * @param int $date Competition date
  241.      * @param string $url HTML table URL
  242.      */
  243.     private function saveLahtine($date$url)
  244.     {
  245.         $modelPunktid new Model_Lahtinepunktid();
  246.  
  247.         $dateID $date;
  248.         $groupID $this->fetchGroupID($url);
  249.  
  250.         $tableRows $this->fetchTableRows($url);
  251.         
  252.         foreach($tableRows as $i => $tableRow{
  253.             if($i 0{
  254.                 $points $modelPunktid->createRow();
  255.                 foreach ($tableRow->childNodes as $j => $dataItem{
  256.                     $length $tableRow->childNodes->length;
  257.                     $length ($length 14)?$length*2:$length;
  258.                     $j ($tableRow->childNodes->length 14)?$j*2:$j;
  259.                     $k $length-20;
  260.                     $data trim($dataItem->nodeValue);
  261.                     if($i == count($tableRows)-&& $tableRow->childNodes->item(0)->nodeValue == ''{
  262.                         $break true;
  263.                         break;
  264.                     }
  265.                     switch($j{
  266.                         case $k+0$personID $this->fetchPersonID($data);
  267.                         case $k+2$schoolID $this->fetchSchoolIDByString($data);
  268.                         case $k+4$classID $this->fetchClassIDByString($data);
  269.                         case $k+6$points->p1 = (int)$databreak;
  270.                         case $k+8$points->p2 = (int)$databreak;
  271.                         case $k+10$points->p3 = (int)$databreak;
  272.                         case $k+12$points->p4 = (int)$databreak;
  273.                         case $k+14$points->p5 = (int)$databreak;
  274.                         case $k+16$points->summa = (int)$databreak
  275.                     }
  276.                 }
  277.                 if(!isset($break)) {
  278.                     if(!$this->checkLahtineExistance($dateID$personID$schoolID$classID)) {
  279.                         $points->save();
  280.                         $this->saveLahtineOverall($personID$dateID$points->id$classID$groupID$schoolID);
  281.                     else {
  282.                         $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  283.                     }
  284.                 }
  285.             }
  286.         }
  287.     }
  288.     /**
  289.      * Method for saving 'Lõppvoorud' competition results.
  290.      * All data from given table URL is being inserted into database.
  291.      * 
  292.      * @access public
  293.      * @param int $date Competition date
  294.      * @param string $url HTML table URL
  295.      */
  296.     private function saveLopp($date$url)
  297.     {
  298.         $modelPunktid new Model_Lopppunktid();
  299.  
  300.         $classID $this->fetchClassID($url);
  301.          $dateID $date;
  302.         
  303.         $tableRows $this->fetchTableRows($url);
  304.         
  305.         foreach($tableRows as $i => $tableRow{
  306.             if($i 0{
  307.                 $points $modelPunktid->createRow();
  308.                 foreach ($tableRow->childNodes as $j => $dataItem{
  309.                     $length $tableRow->childNodes->length;
  310.                     $length ($length 14)?$length*2:$length;
  311.                     $j ($tableRow->childNodes->length 14)?$j*2:$j;
  312.                     $data trim($dataItem->nodeValue);
  313.                     if($i >= count($tableRows)-&& $tableRow->childNodes->item(0)->nodeValue == ''{
  314.                         $break true;
  315.                         break;
  316.                     }
  317.                     switch($j{
  318.                         case 0$personID $this->fetchPersonID($data);
  319.                         case 2$schoolID $this->fetchSchoolIDByString($data);
  320.                         case 4$points->p1 = (int)$databreak;
  321.                         case 6$points->p2 = (int)$databreak;
  322.                         case 8$points->p3 = (int)$databreak;
  323.                         case 10$points->p4 = (int)$databreak;
  324.                         case 12$points->p5 = (int)$databreak;
  325.                         case 14$points->summa = (int)$databreak
  326.                     }
  327.                 }
  328.                 if(!isset($break)) {
  329.                     if(!$this->checkLoppExistance($dateID$personID$schoolID$classID)) {
  330.                         $points->save();
  331.                         $this->saveLoppOverall($personID$dateID$points->id$classID$schoolID);
  332.                     else {
  333.                         $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  334.                     }
  335.                 }
  336.             }
  337.         }
  338.     }
  339.     /**
  340.      * Method for saving 'Piirkonnavoorud' competition results.
  341.      * All data from given table URL is being inserted into database.
  342.      * 
  343.      * @access public
  344.      * @param int $date Competition date
  345.      * @param string $url HTML table URL
  346.      */
  347.     private function savePiirk($date$url)
  348.     {
  349.         $modelPunktid new Model_Piirkondpunktid();
  350.         $dateID $date;
  351.         $classID $this->fetchClassID($url);
  352.         
  353.         $tableRows $this->fetchTableRows($url);
  354.         
  355.         
  356.         $class $this->classByID($classID);
  357.         
  358.         foreach($tableRows as $i => $tableRow{
  359.             if($i 0{
  360.                 $points $modelPunktid->createRow();
  361.                 foreach ($tableRow->childNodes as $k => $dataItem{
  362.                     $data trim($dataItem->nodeValue);
  363.                     $k ($tableRow->childNodes->length 20)?$k*2:$k;
  364.                     switch($k{
  365.                         case 0$personID $this->fetchPersonID($data)break;
  366.                         case 2$areaID $this->fetchAreaID($data)break;
  367.                         case 4$schoolID $this->fetchSchoolID($data$areaID)break;
  368.                     }
  369.                     if($k == && $this->checkPiirkondExistance($dateID$personID$schoolID$classID)) {
  370.                         break;
  371.                     }
  372.                     
  373.                     if($class 9{
  374.                         switch($k{
  375.                             case 6$points->test = (int)$databreak;
  376.                             case 10$points->p1 = (int)$databreak;
  377.                             case 14$points->p2 = (int)$databreak;
  378.                             case 18$points->p3 = (int)$databreak;
  379.                             case 22$points->summa = (int)$databreak;
  380.                         }
  381.                     else if($class == 9{
  382.                         switch($k{
  383.                             case 6$points->test = (int)$databreak;
  384.                             case 10$points->p1 = (int)$databreak;
  385.                             case 14$points->p2 = (int)$databreak;
  386.                             case 18$points->p3 = (int)$databreak;
  387.                             case 22$points->p4 = (int)$databreak;
  388.                             case 26$points->summa = (int)$databreak;
  389.                         }
  390.                     else {
  391.                         switch($k{
  392.                             case 6$points->p1 = (int)$databreak;
  393.                             case 10$points->p2 = (int)$databreak;
  394.                             case 14$points->p3 = (int)$databreak;
  395.                             case 18$points->p4 = (int)$databreak;
  396.                             case 22$points->p5 = (int)$databreak;
  397.                             case 26:
  398.                                 if($tableRow->childNodes->length%15 == 0{
  399.                                     $points->summa = (int)$data;
  400.                                 else {
  401.                                     $points->p6 = (int)$data;
  402.                                 break;
  403.                             case 30$points->summa = (int)$databreak;
  404.                         }
  405.                     }
  406.                     
  407.                 }
  408.                 $points->save();
  409.                 $this->savePiirkondOverall($personID$dateID$points->id$classID$schoolID);
  410.             }
  411.         }
  412.     }
  413.     /**
  414.      * Method for fetching competition date ID.
  415.      * Competition date is being fetched from database by its string presentation.
  416.      * 
  417.      * @access public
  418.      * @param string $date Competition date
  419.      * @return int $dateID Competition date ID
  420.      */
  421.     private function getDateIDByDateString($date)
  422.     {
  423.         $modelDates new Model_Kuupaevad();
  424.            $result $modelDates->fetchByDate($date);
  425.         if($result == null{
  426.             $result $modelDates->createRow();
  427.             $result->AineID 1;
  428.             $result->VoistluseID 2;
  429.             $result->Kuupaev $date;
  430.             $result->save();
  431.         }
  432.         $dateID $result->VoistluseKuupaevaID;
  433.         return $dateID;
  434.     }
  435.     /**
  436.      * Method for fetching competition date ID.
  437.      * Competition date is being fetched from database by its ID.
  438.      * 
  439.      * @access public
  440.      * @param int $date Competition date
  441.      * @return int $dateID Competition date ID
  442.      */
  443.     private function getDateIDByDateID($date)
  444.     {
  445.         $modelDates new Model_Kuupaevad();
  446.            $result $modelDates->fetchRow('VoistluseKuupaevaID=' . (int)$date);
  447.         if($result == null{
  448.             $result $modelDates->createRow();
  449.             $result->AineID 1;
  450.             $result->VoistluseID 2;
  451.             $result->Kuupaev $date;
  452.             $result->save();
  453.         }
  454.         $dateID $result->VoistluseKuupaevaID;
  455.         return $dateID;
  456.     }
  457.     /**
  458.      * Method for fetching competition group ID.
  459.      * Group is being fetched from database by result table URL,
  460.      * which contains information about the group.
  461.      * 
  462.      * @access public
  463.      * @param string $url Result table URL
  464.      * @return int $groupID Group ID
  465.      */
  466.     private function fetchGroupID($url{
  467.         $group explode('_'$url);
  468.         $group substr($group[1]0,1);
  469.         $groupID ($group == 'n')?1:2;
  470.         
  471.         return $groupID;
  472.     }
  473.     /**
  474.      * Method for fetching participant's class ID.
  475.      * Class is being fetched from database by result table URL,
  476.      * which contains information about the class.
  477.      * 
  478.      * @access public
  479.      * @param string $url Result table URL
  480.      * @return int $classID Class ID
  481.      */
  482.     private function fetchClassID($url)
  483.     {
  484.         $modelKlass new Model_Klass();
  485.         $data explode('/'$url);
  486.         $data explode('klass'$data[6]);
  487.         $data $data[0];
  488.         $class $modelKlass->fetchByName($data);
  489.         if($class == null{
  490.             $class $modelKlass->createRow();
  491.             $class->number = (int)$data;
  492.             $class->save();
  493.         }
  494.         $classID $class->id;
  495.         return $classID;
  496.     }
  497.     /**
  498.      * Method for fetching participant's class ID.
  499.      * Class ID is being fetched from database by its string presentation.
  500.      * 
  501.      * @access public
  502.      * @param string $data Class number
  503.      * @return int $classID Class ID
  504.      */
  505.     private function fetchClassIDByString($data)
  506.     {
  507.         $modelKlass new Model_Klass();
  508.         $class $modelKlass->fetchByName($data);
  509.         if($class == null{
  510.             $class $modelKlass->createRow();
  511.             $class->number = (int)$data;
  512.             $class->save();
  513.         }
  514.         $classID $class->id;
  515.         return $classID;
  516.     }
  517.     /**
  518.      * Method for fetching participant's ID.
  519.      * Participant is being fetched from database by his/her name.
  520.      * 
  521.      * @access public
  522.      * @param string $data Participant name
  523.      * @return int $personID Participant ID
  524.      */
  525.     private function fetchPersonID($data)
  526.     {
  527.                 
  528.         $modelOsaleja new Model_Osaleja();
  529.         $person $modelOsaleja->fetchByName($data);
  530.         if($person == null{
  531.             $person $modelOsaleja->createRow();
  532.             $person->nimi $data;
  533.             $person->save();
  534.         }
  535.         $personID $person->id;
  536.         return $personID;
  537.     }
  538.     /**
  539.      * Method for fetching area ID.
  540.      * Area ID is being fetched from database by area name.
  541.      * 
  542.      * @access public
  543.      * @param string $data Area name
  544.      * @return int $areaID Area ID
  545.      */
  546.     private function fetchAreaID($data)
  547.     {
  548.         $modelPiirkond new Model_Piirkond();
  549.         if(strpos($data'Tallinn'!== false{
  550.             return 1;
  551.         }
  552.         $area $modelPiirkond->fetchByName($data);
  553.         if($area == null{
  554.             $area $modelPiirkond->createRow();
  555.             $area->nimetus $data;
  556.             $area->save();
  557.         }
  558.         $areaID $area->id;
  559.         return $areaID;
  560.     }
  561.     /**
  562.      * Method for fetching school ID and editing its area ID.
  563.      * School ID is being fetched from database by school name.
  564.      * In case school's area ID is empty, it is being replaced
  565.      * with given area ID;
  566.      * 
  567.      * @access public
  568.      * @param string $data School name
  569.      * @param int $areaID Area ID
  570.      * @return int $schoolID School ID
  571.      */
  572.     private function fetchSchoolID($data$areaID)
  573.     {
  574.         $modelKool new Model_Kool();
  575.           $school $modelKool->fetchByName($data);
  576.         if($school == null{
  577.             $school $modelKool->createRow();
  578.             $school->nimi $data;
  579.             if($school->piirkondID == ''{
  580.                 $school->piirkondID $areaID;
  581.             }
  582.             $school->save();
  583.         }
  584.         $schoolID $school->id;
  585.         return $schoolID;
  586.     }
  587.     /**
  588.      * Method for fetching school ID.
  589.      * School ID is being fetched from database by school name.
  590.      * 
  591.      * @access public
  592.      * @param string $data School name
  593.      * @return int $schoolID School ID
  594.      */
  595.     private function fetchSchoolIDByString($data)
  596.     {
  597.         $modelKool new Model_Kool();
  598.           $school $modelKool->fetchByName($data);
  599.         if($school == null{
  600.             $school $modelKool->createRow();
  601.             $school->nimi $data;
  602.             $school->save();
  603.         }
  604.         $schoolID $school->id;
  605.         return $schoolID;
  606.     }
  607.     /**
  608.      * Method for saving 'Piirkonnavoorud' competition.
  609.      * A row is inserted to aggregate table with all the necessary ID fields.
  610.      * 
  611.      * @access public
  612.      * @param int $personID Participant ID
  613.      * @param int $dateID Date ID
  614.      * @param int $pointsID Points ID
  615.      * @param int $classID Class ID
  616.      * @param int $schoolID School ID
  617.      */
  618.     private function savePiirkondOverall($personID$dateID$pointsID$classID$schoolID)
  619.     {
  620.         $modelKoond new Model_Piirkondkoond();
  621.         $overall $modelKoond->createRow();
  622.         $overall->osalejaID $personID;
  623.         $overall->kuupaevID $dateID;
  624.         $overall->punktidID $pointsID;
  625.         $overall->klassID $classID;
  626.         $overall->koolID $schoolID;
  627.         $overall->save();
  628.     }
  629.     /**
  630.      * Method for saving 'Valikvõistlused' competition.
  631.      * A row is inserted to aggregate table with all the necessary ID fields.
  632.      * 
  633.      * @access public
  634.      * @param int $personID Participant ID
  635.      * @param int $dateID Date ID
  636.      * @param int $pointsID Points ID
  637.      * @param int $classID Class ID
  638.      * @param int $schoolID School ID
  639.      */
  640.     private function saveValikOverall($personID$dateID$pointsID$classID$schoolID)
  641.     {
  642.         $modelKoond new Model_Valikkoond();
  643.         $overall $modelKoond->createRow();
  644.         $overall->osalejaID $personID;
  645.         $overall->kuupaevID $dateID;
  646.         $overall->punktidID $pointsID;
  647.         $overall->klassID $classID;
  648.         $overall->koolID $schoolID;
  649.         $overall->save();
  650.     }
  651.     /**
  652.      * Method for saving 'Lahtised võistlused' competition.
  653.      * A row is inserted to aggregate table with all the necessary ID fields.
  654.      * 
  655.      * @access public
  656.      * @param int $personID Participant ID
  657.      * @param int $dateID Date ID
  658.      * @param int $pointsID Points ID
  659.      * @param int $classID Class ID
  660.      * @param int $groupID Group ID
  661.      * @param int $schoolID School ID
  662.      */
  663.     private function saveLahtineOverall($personID$dateID$pointsID$classID$groupID$schoolID)
  664.     {
  665.         $modelKoond new Model_Lahtinekoond();
  666.         $overall $modelKoond->createRow();
  667.         $overall->osalejaID $personID;
  668.         $overall->kuupaevID $dateID;
  669.         $overall->punktidID $pointsID;
  670.         $overall->klassID $classID;
  671.         $overall->ryhmID $groupID;
  672.         $overall->koolID $schoolID;
  673.         $overall->save();
  674.     }
  675.     /**
  676.      * Method for saving 'Lõppvoorud' competition.
  677.      * A row is inserted to aggregate table with all the necessary ID fields.
  678.      * 
  679.      * @access public
  680.      * @param int $personID Participant ID
  681.      * @param int $dateID Date ID
  682.      * @param int $pointsID Points ID
  683.      * @param int $classID Class ID
  684.      * @param int $schoolID School ID
  685.      */
  686.     private function saveLoppOverall($personID$dateID$pointsID$classID$schoolID)
  687.     {
  688.         $modelKoond new Model_Loppkoond();
  689.         $overall $modelKoond->createRow();
  690.         $overall->osalejaID $personID;
  691.         $overall->kuupaevID $dateID;
  692.         $overall->punktidID $pointsID;
  693.         $overall->klassID $classID;
  694.         $overall->koolID $schoolID;
  695.         $overall->save();
  696.     }
  697.     /**
  698.      * Method for getting URL table rows..
  699.      * Table rows are fetched from given URL and returned as DOM elements.
  700.      * 
  701.      * @access public
  702.      * @param string $url Result table URL
  703.      * @return mixed $rows Table rows
  704.      */
  705.     private function fetchTableRows($url)
  706.     {
  707.         $client new Zend_Http_Client($url);
  708.         $dom new Zend_Dom_Query($client->request()->getBody());
  709.         $rows $dom->query('tr');
  710.         return $rows;
  711.     }
  712.     /**
  713.      * Method for fetching class number.
  714.      * Class number is being fetched from database by class ID.
  715.      * 
  716.      * @access public
  717.      * @param int $classID Class ID
  718.      * @return string $classNumber Class number
  719.      */
  720.     private function classByID($classID{
  721.         $modelKlass new Model_Klass();
  722.         $class $modelKlass->fetchRow('id=' . (int)$classID);
  723.         $classNumber $class->number;
  724.         return $classNumber;
  725.     }
  726.     /**
  727.      * Method for checking 'Piirkonnavoorud' competition record existance.
  728.      * Database is being checked if there already is a record with given
  729.      * parameters or not.
  730.      * Based on the result boolean is returned.
  731.      * 
  732.      * @access public
  733.      * @param int $dateID Date ID
  734.      * @param int $personID Participant ID
  735.      * @param int $schoolID School ID
  736.      * @param int $classID Class ID
  737.      * @return boolean 
  738.      */
  739.     private function checkPiirkondExistance($dateID$personID$schoolID$classID{
  740.         $modelKoond new Model_Piirkondkoond();
  741.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  742.         if(count($exists!= 0{
  743.             return true;
  744.         }
  745.         return false;
  746.     }
  747.     /**
  748.      * Method for checking 'Lõppvoorud' competition record existance.
  749.      * Database is being checked if there already is a record with given
  750.      * parameters or not.
  751.      * Based on the result boolean is returned.
  752.      * 
  753.      * @access public
  754.      * @param int $dateID Date ID
  755.      * @param int $personID Participant ID
  756.      * @param int $schoolID School ID
  757.      * @param int $classID Class ID
  758.      * @return boolean 
  759.      */
  760.     private function checkLoppExistance($dateID$personID$schoolID$classID{
  761.         $modelKoond new Model_Loppkoond();
  762.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  763.         if(count($exists!= 0{
  764.             return true;
  765.         }
  766.         return false;
  767.     }
  768.     /**
  769.      * Method for checking 'Valikvõistlused' competition record existance.
  770.      * Database is being checked if there already is a record with given
  771.      * parameters or not.
  772.      * Based on the result boolean is returned.
  773.      * 
  774.      * @access public
  775.      * @param int $dateID Date ID
  776.      * @param int $personID Participant ID
  777.      * @param int $schoolID School ID
  778.      * @param int $classID Class ID
  779.      * @return boolean 
  780.      */
  781.     private function checkValikExistance($dateID$personID$schoolID$classID{
  782.         $modelKoond new Model_Valikkoond();
  783.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  784.         if(count($exists!= 0{
  785.             return true;
  786.         }
  787.         return false;
  788.     }
  789.     /**
  790.      * Method for checking 'Lahtised võistlused' competition record existance.
  791.      * Database is being checked if there already is a record with given
  792.      * parameters or not.
  793.      * Based on the result boolean is returned.
  794.      * 
  795.      * @access public
  796.      * @param int $dateID Date ID
  797.      * @param int $personID Participant ID
  798.      * @param int $schoolID School ID
  799.      * @param int $classID Class ID
  800.      * @return boolean 
  801.      */
  802.     private function checkLahtineExistance($dateID$personID$schoolID$classID{
  803.         $modelKoond new Model_Lahtinekoond();
  804.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  805.         if(count($exists!= 0{
  806.             return true;
  807.         }
  808.         return false;
  809.     }
  810. }

Documentation generated on Wed, 15 Jun 2011 15:50:39 +0300 by phpDocumentor 1.4.1