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.         $array array(
  197.             'nimi' => null,
  198.             'kool' => null
  199.             'klass' => null,
  200.             '1.' => null,
  201.             '2.' => null
  202.             '3.' => null,
  203.             '4.' => null,
  204.             '5.' => null
  205.             '6.' => null,
  206.             'summa' => null,
  207.         );
  208.         $lastRow false;
  209.         foreach($tableRows as $i => $tableRow{
  210.             if($i == 0{
  211.                 foreach ($tableRow->childNodes as $j => $dataItem{
  212.                     foreach($array as $key => $arrayItem{
  213.                         if(strripos($dataItem->nodeValue$key!== false{
  214.                             $array[$key$j;
  215.                         }
  216.                     }
  217.                 }
  218.             else {
  219.                 foreach ($tableRow->childNodes as $j => $dataItem{
  220.                     if(strripos($dataItem->nodeValue'keskmine'!== false{
  221.                         $lastRow true;
  222.                     }
  223.                 }
  224.                 if(!$lastRow{
  225.                     $points $modelPunktid->createRow();
  226.                     foreach ($tableRow->childNodes as $j => $dataItem{
  227.                         $data trim($dataItem->nodeValue);
  228.                         switch($j{
  229.                             case $array['nimi']$personID $this->fetchPersonID($data)break;
  230.                             case $array['kool']$schoolID $this->fetchSchoolIDByString($data)break;
  231.                             case $array['klass']$classID $this->fetchClassIDByString($data)break;
  232.                             case $array['1.']$points->p1 = (int)$databreak;
  233.                             case $array['2.']$points->p2 = (int)$databreak;
  234.                             case $array['3.']$points->p3 = (int)$databreak;
  235.                             case $array['4.']$points->p4 = (int)$databreak;
  236.                             case $array['5.']$points->p5 = (int)$databreak;
  237.                             case $array['6.']$points->p6 = (int)$databreak;
  238.                             case $array['summa']$points->summa = (int)$databreak;
  239.                         }
  240.                     }
  241.                     if(!$this->checkValikExistance($dateID$personID$schoolID$classID)) {
  242.                         $points->save();
  243.                         $this->saveValikOverall($personID$dateID$points->id$classID$schoolID);
  244.                     else {
  245.                         $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  246.                     }
  247.                 }
  248.             }
  249.         }
  250.     }
  251.     /**
  252.      * Method for saving 'Lahtised võistlused' competition results.
  253.      * All data from given table URL is being inserted into database.
  254.      * 
  255.      * @access public
  256.      * @param int $date Competition date
  257.      * @param string $url HTML table URL
  258.      */
  259.     private function saveLahtine($date$url)
  260.     {
  261.         $modelPunktid new Model_Lahtinepunktid();
  262.  
  263.         $dateID $date;
  264.         $groupID $this->fetchGroupID($url);
  265.  
  266.         $tableRows $this->fetchTableRows($url);
  267.         $array array(
  268.             'nimi' => null,
  269.             'kool' => null
  270.             'klass' => null,
  271.             '1.' => null,
  272.             '2.' => null
  273.             '3.' => null,
  274.             '4.' => null,
  275.             '5.' => null
  276.             'summa' => null,
  277.         );
  278.         $lastRow false;
  279.         foreach($tableRows as $i => $tableRow{
  280.             if($i == 0{
  281.                 foreach ($tableRow->childNodes as $j => $dataItem{
  282.                     foreach($array as $key => $arrayItem{
  283.                         if(strripos($dataItem->nodeValue$key!== false{
  284.                             $array[$key$j;
  285.                         }
  286.                     }
  287.                 }
  288.             else {
  289.                 foreach ($tableRow->childNodes as $j => $dataItem{
  290.                     if(strripos($dataItem->nodeValue'keskmine'!== false{
  291.                         $lastRow true;
  292.                     }
  293.                 }
  294.                 if(!$lastRow{
  295.                     $points $modelPunktid->createRow();
  296.                     foreach ($tableRow->childNodes as $j => $dataItem{
  297.                         $data trim($dataItem->nodeValue);
  298.                         if($tableRow->childNodes->item(0)->nodeValue != ''{
  299.                             switch($j{
  300.                                 case $array['nimi']$personID $this->fetchPersonID($data)break;
  301.                                 case $array['kool']$schoolID $this->fetchSchoolIDByString($data)break;
  302.                                 case $array['klass']$classID $this->fetchClassIDByString($data)break;
  303.                                 case $array['1.']$points->p1 = (int)$databreak;
  304.                                 case $array['2.']$points->p2 = (int)$databreak;
  305.                                 case $array['3.']$points->p3 = (int)$databreak;
  306.                                 case $array['4.']$points->p4 = (int)$databreak;
  307.                                 case $array['5.']$points->p5 = (int)$databreak;
  308.                                 case $array['summa']$points->summa = (int)$databreak;
  309.                             }
  310.                         else {
  311.                             $lastRow true;
  312.                         }
  313.                     }
  314.                     if(!$this->checkLahtineExistance($dateID$personID$schoolID$classID)) {
  315.                         $points->save();
  316.                         $this->saveLahtineOverall($personID$dateID$points->id$classID$groupID$schoolID);
  317.                     else {
  318.                         $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  319.                     }
  320.                 }
  321.             }
  322.         }
  323.     }
  324.     /**
  325.      * Method for saving 'Lõppvoorud' competition results.
  326.      * All data from given table URL is being inserted into database.
  327.      * 
  328.      * @access public
  329.      * @param int $date Competition date
  330.      * @param string $url HTML table URL
  331.      */
  332.     private function saveLopp($date$url)
  333.     {
  334.         $modelPunktid new Model_Lopppunktid();
  335.  
  336.         $classID $this->fetchClassID($url);
  337.          $dateID $date;
  338.         
  339.         $tableRows $this->fetchTableRows($url);
  340.         $array array(
  341.             'nimi' => null,
  342.             'kool' => null
  343.             'klass' => null,
  344.             '1.' => null,
  345.             '2.' => null
  346.             '3.' => null,
  347.             '4.' => null,
  348.             '5.' => null
  349.             'summa' => null,
  350.             'kokku' => null,
  351.         );
  352.         $lastRow false;
  353.         foreach($tableRows as $i => $tableRow{
  354.             if($i == 0{
  355.                 foreach ($tableRow->childNodes as $j => $dataItem{
  356.                     foreach($array as $key => $arrayItem{
  357.                         if(strripos($dataItem->nodeValue$key!== false{
  358.                             $array[$key$j;
  359.                         }
  360.                     }
  361.                 }
  362.             else {
  363.                 foreach ($tableRow->childNodes as $j => $dataItem{
  364.                     if(strripos($dataItem->nodeValue'keskmine'!== false{
  365.                         $lastRow true;
  366.                     }
  367.                 }
  368.                 if(!$lastRow{
  369.                     $points $modelPunktid->createRow();
  370.                     foreach ($tableRow->childNodes as $j => $dataItem{
  371.                         $data trim($dataItem->nodeValue);
  372.                         switch($j{
  373.                             case $array['nimi']$personID $this->fetchPersonID($data)break;
  374.                             case $array['kool']$schoolID $this->fetchSchoolIDByString($data)break;
  375.                             case $array['1.']$points->p1 = (int)$databreak;
  376.                             case $array['2.']$points->p2 = (int)$databreak;
  377.                             case $array['3.']$points->p3 = (int)$databreak;
  378.                             case $array['4.']$points->p4 = (int)$databreak;
  379.                             case $array['5.']$points->p5 = (int)$databreak;
  380.                             case $array['summa']$points->summa = (int)$databreak;
  381.                             case $array['kokku']$points->summa = (int)$databreak;
  382.                         }
  383.                     }
  384.                     if(!$this->checkLoppExistance($dateID$personID$schoolID$classID)) {
  385.                         $points->save();
  386.                         $this->saveLoppOverall($personID$dateID$points->id$classID$schoolID);
  387.                     else {
  388.                         $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  389.                     }
  390.                 }
  391.             }
  392.         }
  393.     }
  394.     /**
  395.      * Method for saving 'Piirkonnavoorud' competition results.
  396.      * All data from given table URL is being inserted into database.
  397.      * 
  398.      * @access public
  399.      * @param int $date Competition date
  400.      * @param string $url HTML table URL
  401.      */
  402.     private function savePiirk($date$url)
  403.     {
  404.         $modelPunktid new Model_Piirkondpunktid();
  405.         $dateID $date;
  406.         $classID $this->fetchClassID($url);
  407.         
  408.         $tableRows $this->fetchTableRows($url);
  409.         
  410.         $array array(
  411.             'nimi' => null,
  412.             'piirkond' => null,
  413.             'kool' => null
  414.             'test' => null,
  415.             '1.' => null,
  416.             '2.' => null
  417.             '3.' => null,
  418.             '4.' => null,
  419.             '5.' => null
  420.             '6.' => null,
  421.             'summa' => null,
  422.         );
  423.         $lastRow false;
  424.         foreach($tableRows as $i => $tableRow{
  425.             if($i == 0{
  426.                 $addition 0;
  427.                 foreach ($tableRow->childNodes as $j => $dataItem{
  428.                     foreach($array as $key => $arrayItem{
  429.                         if(strripos($dataItem->nodeValue$key!== false{
  430.                             $array[$key$j+$addition;
  431.                             if($key == '1.' || $key == 'test' ||$addition != 0{
  432.                                 $sumTwo $array['nimi'$array['piirkond'];
  433.                                 $isEven ($sumTwo == 0)?true:false;
  434.                                 $addition += ($isEven)?2:1;
  435.                             }
  436.                         }
  437.                     }
  438.                 }
  439.             else {
  440.                 foreach ($tableRow->childNodes as $j => $dataItem{
  441.                     if(strripos($dataItem->nodeValue'keskmine'!== false{
  442.                         $lastRow true;
  443.                     }
  444.                 }
  445.                 if(!$lastRow{
  446.                     $points $modelPunktid->createRow();
  447.                     foreach ($tableRow->childNodes as $j => $dataItem{
  448.                         $data trim($dataItem->nodeValue);
  449.                         switch($j{
  450.                             case $array['nimi']$personID $this->fetchPersonID($data)break;
  451.                             case $array['piirkond']$areaID $this->fetchAreaID($data)break;
  452.                             case $array['kool']$schoolID $this->fetchSchoolID($data$areaID)break;
  453.                             case $array['test']$points->test = (int)$databreak;
  454.                             case $array['1.']$points->p1 = (int)$databreak;
  455.                             case $array['2.']$points->p2 = (int)$databreak;
  456.                             case $array['3.']$points->p3 = (int)$databreak;
  457.                             case $array['4.']$points->p4 = (int)$databreak;
  458.                             case $array['5.']$points->p5 = (int)$databreak;
  459.                             case $array['6.']$points->p6 = (int)$databreak;
  460.                             case $array['summa']$points->summa = (int)$databreak;
  461.                         }
  462.                     }
  463.                 }
  464.                 if(!$this->checkPiirkondExistance($dateID$personID$schoolID$classID)) {
  465.                     $points->save();
  466.                     $this->savePiirkondOverall($personID$dateID$points->id$classID$schoolID);
  467.                 else {
  468.                     $this->view->error 'Selline tabel on juba andmebaasi lisatud.';
  469.                 }
  470.             }
  471.         }
  472.     }
  473.     /**
  474.      * Method for fetching competition date ID.
  475.      * Competition date is being fetched from database by its string presentation.
  476.      * 
  477.      * @access public
  478.      * @param string $date Competition date
  479.      * @return int $dateID Competition date ID
  480.      */
  481.     private function getDateIDByDateString($date)
  482.     {
  483.         $modelDates new Model_Kuupaevad();
  484.            $result $modelDates->fetchByDate($date);
  485.         if($result == null{
  486.             $result $modelDates->createRow();
  487.             $result->AineID 1;
  488.             $result->VoistluseID 2;
  489.             $result->Kuupaev $date;
  490.             $result->save();
  491.         }
  492.         $dateID $result->VoistluseKuupaevaID;
  493.         return $dateID;
  494.     }
  495.     /**
  496.      * Method for fetching competition date ID.
  497.      * Competition date is being fetched from database by its ID.
  498.      * 
  499.      * @access public
  500.      * @param int $date Competition date
  501.      * @return int $dateID Competition date ID
  502.      */
  503.     private function getDateIDByDateID($date)
  504.     {
  505.         $modelDates new Model_Kuupaevad();
  506.            $result $modelDates->fetchRow('VoistluseKuupaevaID=' . (int)$date);
  507.         if($result == null{
  508.             $result $modelDates->createRow();
  509.             $result->AineID 1;
  510.             $result->VoistluseID 2;
  511.             $result->Kuupaev $date;
  512.             $result->save();
  513.         }
  514.         $dateID $result->VoistluseKuupaevaID;
  515.         return $dateID;
  516.     }
  517.     /**
  518.      * Method for fetching competition group ID.
  519.      * Group is being fetched from database by result table URL,
  520.      * which contains information about the group.
  521.      * 
  522.      * @access public
  523.      * @param string $url Result table URL
  524.      * @return int $groupID Group ID
  525.      */
  526.     private function fetchGroupID($url{
  527.         $group explode('_'$url);
  528.         $group substr($group[1]0,1);
  529.         $groupID ($group == 'n')?1:2;
  530.         
  531.         return $groupID;
  532.     }
  533.     /**
  534.      * Method for fetching participant's class ID.
  535.      * Class is being fetched from database by result table URL,
  536.      * which contains information about the class.
  537.      * 
  538.      * @access public
  539.      * @param string $url Result table URL
  540.      * @return int $classID Class ID
  541.      */
  542.     private function fetchClassID($url)
  543.     {
  544.         $modelKlass new Model_Klass();
  545.         $data explode('/'$url);
  546.         $data explode('klass'$data[6]);
  547.         $data $data[0];
  548.         $class $modelKlass->fetchByName($data);
  549.         if($class == null{
  550.             $class $modelKlass->createRow();
  551.             $class->number = (int)$data;
  552.             $class->save();
  553.         }
  554.         $classID $class->id;
  555.         return $classID;
  556.     }
  557.     /**
  558.      * Method for fetching participant's class ID.
  559.      * Class ID is being fetched from database by its string presentation.
  560.      * 
  561.      * @access public
  562.      * @param string $data Class number
  563.      * @return int $classID Class ID
  564.      */
  565.     private function fetchClassIDByString($data)
  566.     {
  567.         $modelKlass new Model_Klass();
  568.         $class $modelKlass->fetchByName($data);
  569.         if($class == null{
  570.             $class $modelKlass->createRow();
  571.             $class->number = (int)$data;
  572.             $class->save();
  573.         }
  574.         $classID $class->id;
  575.         return $classID;
  576.     }
  577.     /**
  578.      * Method for fetching participant's ID.
  579.      * Participant is being fetched from database by his/her name.
  580.      * 
  581.      * @access public
  582.      * @param string $data Participant name
  583.      * @return int $personID Participant ID
  584.      */
  585.     private function fetchPersonID($data)
  586.     {
  587.         $newData split('\('$data);
  588.         $realClass new Zend_Session_Namespace('realClass');
  589.         $realClass->value null;
  590.         if(count($newData== 2{
  591.             $class substr($newData[1]0-4);
  592.             $realClass->value $class;
  593.             $data $newData[0];
  594.         }
  595.         $modelOsaleja new Model_Osaleja();
  596.         $person $modelOsaleja->fetchByName($data);
  597.         if($person == null{
  598.             $person $modelOsaleja->createRow();
  599.             $person->nimi $data;
  600.             $person->save();
  601.         }
  602.         $personID $person->id;
  603.         return $personID;
  604.     }
  605.     /**
  606.      * Method for fetching area ID.
  607.      * Area ID is being fetched from database by area name.
  608.      * 
  609.      * @access public
  610.      * @param string $data Area name
  611.      * @return int $areaID Area ID
  612.      */
  613.     private function fetchAreaID($data)
  614.     {
  615.         $modelPiirkond new Model_Piirkond();
  616.         if(strpos($data'Tallinn'!== false{
  617.             return 1;
  618.         }
  619.         $area $modelPiirkond->fetchByName($data);
  620.         if($area == null{
  621.             $area $modelPiirkond->createRow();
  622.             $area->nimetus $data;
  623.             $area->save();
  624.         }
  625.         $areaID $area->id;
  626.         return $areaID;
  627.     }
  628.     /**
  629.      * Method for fetching school ID and editing its area ID.
  630.      * School ID is being fetched from database by school name.
  631.      * In case school's area ID is empty, it is being replaced
  632.      * with given area ID;
  633.      * 
  634.      * @access public
  635.      * @param string $data School name
  636.      * @param int $areaID Area ID
  637.      * @return int $schoolID School ID
  638.      */
  639.     private function fetchSchoolID($data$areaID)
  640.     {
  641.         $modelKool new Model_Kool();
  642.           $school $modelKool->fetchByName($data);
  643.         if($school == null{
  644.             $school $modelKool->createRow();
  645.             $school->nimi $data;
  646.             if($school->piirkondID == ''{
  647.                 $school->piirkondID $areaID;
  648.             }
  649.             $school->save();
  650.         }
  651.         $schoolID $school->id;
  652.         return $schoolID;
  653.     }
  654.     /**
  655.      * Method for fetching school ID.
  656.      * School ID is being fetched from database by school name.
  657.      * 
  658.      * @access public
  659.      * @param string $data School name
  660.      * @return int $schoolID School ID
  661.      */
  662.     private function fetchSchoolIDByString($data)
  663.     {
  664.         $modelKool new Model_Kool();
  665.           $school $modelKool->fetchByName($data);
  666.         if($school == null{
  667.             $school $modelKool->createRow();
  668.             $school->nimi $data;
  669.             $school->save();
  670.         }
  671.         $schoolID $school->id;
  672.         return $schoolID;
  673.     }
  674.     /**
  675.      * Method for saving 'Piirkonnavoorud' competition.
  676.      * A row is inserted to aggregate table with all the necessary ID fields.
  677.      * 
  678.      * @access public
  679.      * @param int $personID Participant ID
  680.      * @param int $dateID Date ID
  681.      * @param int $pointsID Points ID
  682.      * @param int $classID Class ID
  683.      * @param int $schoolID School ID
  684.      */
  685.     private function savePiirkondOverall($personID$dateID$pointsID$classID$schoolID)
  686.     {
  687.         $modelKoond new Model_Piirkondkoond();
  688.         $overall $modelKoond->createRow();
  689.         $overall->osalejaID $personID;
  690.         $overall->kuupaevID $dateID;
  691.         $overall->punktidID $pointsID;
  692.         $overall->klassID $classID;
  693.         $overall->koolID $schoolID;
  694.         $realClass new Zend_Session_Namespace('realClass');
  695.         if($realClass->value != null{
  696.             $overall->tegelikKlassID $this->fetchClassIDByString($realClass->value);
  697.             $realClass->value null;
  698.         else {
  699.             $overall->tegelikKlassID $classID;
  700.         }
  701.         $overall->save();
  702.     }
  703.     /**
  704.      * Method for saving 'Valikvõistlused' competition.
  705.      * A row is inserted to aggregate table with all the necessary ID fields.
  706.      * 
  707.      * @access public
  708.      * @param int $personID Participant ID
  709.      * @param int $dateID Date ID
  710.      * @param int $pointsID Points ID
  711.      * @param int $classID Class ID
  712.      * @param int $schoolID School ID
  713.      */
  714.     private function saveValikOverall($personID$dateID$pointsID$classID$schoolID)
  715.     {
  716.         $modelKoond new Model_Valikkoond();
  717.         $overall $modelKoond->createRow();
  718.         $overall->osalejaID $personID;
  719.         $overall->kuupaevID $dateID;
  720.         $overall->punktidID $pointsID;
  721.         $overall->klassID $classID;
  722.         $overall->koolID $schoolID;
  723.         $overall->save();
  724.     }
  725.     /**
  726.      * Method for saving 'Lahtised võistlused' competition.
  727.      * A row is inserted to aggregate table with all the necessary ID fields.
  728.      * 
  729.      * @access public
  730.      * @param int $personID Participant ID
  731.      * @param int $dateID Date ID
  732.      * @param int $pointsID Points ID
  733.      * @param int $classID Class ID
  734.      * @param int $groupID Group ID
  735.      * @param int $schoolID School ID
  736.      */
  737.     private function saveLahtineOverall($personID$dateID$pointsID$classID$groupID$schoolID)
  738.     {
  739.         $modelKoond new Model_Lahtinekoond();
  740.         $overall $modelKoond->createRow();
  741.         $overall->osalejaID $personID;
  742.         $overall->kuupaevID $dateID;
  743.         $overall->punktidID $pointsID;
  744.         $overall->klassID $classID;
  745.         $overall->ryhmID $groupID;
  746.         $overall->koolID $schoolID;
  747.         $overall->save();
  748.     }
  749.     /**
  750.      * Method for saving 'Lõppvoorud' competition.
  751.      * A row is inserted to aggregate table with all the necessary ID fields.
  752.      * 
  753.      * @access public
  754.      * @param int $personID Participant ID
  755.      * @param int $dateID Date ID
  756.      * @param int $pointsID Points ID
  757.      * @param int $classID Class ID
  758.      * @param int $schoolID School ID
  759.      */
  760.     private function saveLoppOverall($personID$dateID$pointsID$classID$schoolID)
  761.     {
  762.         $modelKoond new Model_Loppkoond();
  763.         $overall $modelKoond->createRow();
  764.         $overall->osalejaID $personID;
  765.         $overall->kuupaevID $dateID;
  766.         $overall->punktidID $pointsID;
  767.         $overall->klassID $classID;
  768.         $overall->koolID $schoolID;
  769.         $realClass new Zend_Session_Namespace('realClass');
  770.         if($realClass->value != null{
  771.             $overall->tegelikKlassID $this->fetchClassIDByString($realClass->value);
  772.             $realClass->value null;
  773.         else {
  774.             $overall->tegelikKlassID $classID;
  775.         }
  776.         $overall->save();
  777.     }
  778.     /**
  779.      * Method for getting URL table rows..
  780.      * Table rows are fetched from given URL and returned as DOM elements.
  781.      * 
  782.      * @access public
  783.      * @param string $url Result table URL
  784.      * @return mixed $rows Table rows
  785.      */
  786.     private function fetchTableRows($url)
  787.     {
  788.         $client new Zend_Http_Client($url);
  789.         $dom new Zend_Dom_Query($client->request()->getBody());
  790.         $rows $dom->query('tr');
  791.         return $rows;
  792.     }
  793.     /**
  794.      * Method for fetching class number.
  795.      * Class number is being fetched from database by class ID.
  796.      * 
  797.      * @access public
  798.      * @param int $classID Class ID
  799.      * @return string $classNumber Class number
  800.      */
  801.     private function classByID($classID{
  802.         $modelKlass new Model_Klass();
  803.         $class $modelKlass->fetchRow('id=' . (int)$classID);
  804.         $classNumber $class->number;
  805.         return $classNumber;
  806.     }
  807.     /**
  808.      * Method for checking 'Piirkonnavoorud' competition record existance.
  809.      * Database is being checked if there already is a record with given
  810.      * parameters or not.
  811.      * Based on the result boolean is returned.
  812.      * 
  813.      * @access public
  814.      * @param int $dateID Date ID
  815.      * @param int $personID Participant ID
  816.      * @param int $schoolID School ID
  817.      * @param int $classID Class ID
  818.      * @return boolean 
  819.      */
  820.     private function checkPiirkondExistance($dateID$personID$schoolID$classID{
  821.         $modelKoond new Model_Piirkondkoond();
  822.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  823.         if(count($exists!= 0{
  824.             return true;
  825.         }
  826.         return false;
  827.     }
  828.     /**
  829.      * Method for checking 'Lõppvoorud' competition record existance.
  830.      * Database is being checked if there already is a record with given
  831.      * parameters or not.
  832.      * Based on the result boolean is returned.
  833.      * 
  834.      * @access public
  835.      * @param int $dateID Date ID
  836.      * @param int $personID Participant ID
  837.      * @param int $schoolID School ID
  838.      * @param int $classID Class ID
  839.      * @return boolean 
  840.      */
  841.     private function checkLoppExistance($dateID$personID$schoolID$classID{
  842.         $modelKoond new Model_Loppkoond();
  843.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  844.         if(count($exists!= 0{
  845.             return true;
  846.         }
  847.         return false;
  848.     }
  849.     /**
  850.      * Method for checking 'Valikvõistlused' competition record existance.
  851.      * Database is being checked if there already is a record with given
  852.      * parameters or not.
  853.      * Based on the result boolean is returned.
  854.      * 
  855.      * @access public
  856.      * @param int $dateID Date ID
  857.      * @param int $personID Participant ID
  858.      * @param int $schoolID School ID
  859.      * @param int $classID Class ID
  860.      * @return boolean 
  861.      */
  862.     private function checkValikExistance($dateID$personID$schoolID$classID{
  863.         $modelKoond new Model_Valikkoond();
  864.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  865.         if(count($exists!= 0{
  866.             return true;
  867.         }
  868.         return false;
  869.     }
  870.     /**
  871.      * Method for checking 'Lahtised võistlused' competition record existance.
  872.      * Database is being checked if there already is a record with given
  873.      * parameters or not.
  874.      * Based on the result boolean is returned.
  875.      * 
  876.      * @access public
  877.      * @param int $dateID Date ID
  878.      * @param int $personID Participant ID
  879.      * @param int $schoolID School ID
  880.      * @param int $classID Class ID
  881.      * @return boolean 
  882.      */
  883.     private function checkLahtineExistance($dateID$personID$schoolID$classID{
  884.         $modelKoond new Model_Lahtinekoond();
  885.         $exists $modelKoond->fetchResult($dateID$personID$schoolID$classID);
  886.         if(count($exists!= 0{
  887.             return true;
  888.         }
  889.         return false;
  890.     }
  891. }

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