Source for file ScriptController.php
Documentation is available at ScriptController.php
* Controller class for automated script logic and all other actions/methods
* that are needed to make this portal function.
* @author Margus Sellin <margus@bitweb.ee>
* @copyright Copyright (C) 2011. All rights reserved. Margus Sellin
* Built-in method in Zend Framework that applies to all actions in given controller.
* In this very controller it restricts common user who are not logged in to access
* administrative actions and functions of this portal.
* If user is not logged in and tries to access actions/methods that are meant
* for administrators only, he/she is redirected to login page.
if(!Zend_Auth::getInstance()->hasIdentity()) {
$this->_redirect('/login');
* Action that is used to display admin menu on the right.
* This action is called only when user is logged in as administrator.
* Action that is used to display static pages' management page.
$pages =
$modelPage->fetchAll();
$this->view->pages =
$pages;
* Action that is used to edit static pages' content.
$pageId =
$this->_getParam('pageId');
$page =
$modelPage->fetchRow('id=' . (int)
$pageId);
$page =
$modelPage->fetchRow('id=' . (int)
$pageId);
$form->populate($page->toArray());
$page =
$modelPage->createRow();
if($this->_request->isPost()) {
if ($form->isValid($this->_request->getPost())) {
$page->title =
$form->title->getValue();
$page->value =
$form->value->getValue();
$this->_helper->redirector('pages', 'script');
$this->view->form =
$form;
* Used to display a view where user can choose between two adding options.
* User inserts a file with result table URL's.
* The file is read line by line and data from tables given by the URL's
* in the file is being inserted into database.
* Used to insert many tables at the same time.
if($this->_request->isPost()) {
$filename =
$this->_getParam('file');
$firstFile =
file($filename);
foreach($firstFile as $file) {
$fileLines =
file($file);
foreach($fileLines as $url) {
$message =
'Andmed edukalt lisatud.';
$message =
'Faili nimega '.
$file.
' ei leitud.';
$this->view->message =
$message;
* User inserts a table URL with HTML table and a date.
* Used to insert single tables.
$dates =
$modelDates->fetchByDates();
$form->populate($form->getValues());
$url =
$this->_getParam('url');
$date =
$this->_getParam('date');
if($this->_request->isPost() &&
$form->isValid($this->_request->getPost())) {
$year =
$this->_getParam('year');
$month =
$this->_getParam('month');
$day =
$this->_getParam('day');
$date =
$year.
'-'.
$month.
'-'.
$day;
$info =
'Lahtiste võistluste andmed edukalt lisatud.';
$info =
'Piirkonnavooru andmed edukalt lisatud.';
$info =
'Valikvõistluste andmed edukalt lisatud.';
$info =
'Lõppvooru andmed edukalt lisatud.';
$this->view->message =
$message;
$this->view->dates =
$dates;
$this->view->form =
$form;
* Method for saving 'Valikvõistlused' competition results.
* All data from given table URL is being inserted into database.
* @param int $date Competition date
* @param string $url HTML table URL
foreach($tableRows as $i =>
$tableRow) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
foreach($array as $key =>
$arrayItem) {
if(strripos($dataItem->nodeValue, $key) !==
false) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
if(strripos($dataItem->nodeValue, 'keskmine') !==
false) {
$points =
$modelPunktid->createRow();
foreach ($tableRow->childNodes as $j =>
$dataItem) {
$data =
trim($dataItem->nodeValue);
case $array['nimi']:
$personID =
$this->fetchPersonID($data); break;
case $array['1.']:
$points->p1 = (int)
$data; break;
case $array['2.']:
$points->p2 = (int)
$data; break;
case $array['3.']:
$points->p3 = (int)
$data; break;
case $array['4.']:
$points->p4 = (int)
$data; break;
case $array['5.']:
$points->p5 = (int)
$data; break;
case $array['6.']:
$points->p6 = (int)
$data; break;
case $array['summa']:
$points->summa = (int)
$data; break;
$this->view->error =
'Selline tabel on juba andmebaasi lisatud.';
* Method for saving 'Lahtised võistlused' competition results.
* All data from given table URL is being inserted into database.
* @param int $date Competition date
* @param string $url HTML table URL
foreach($tableRows as $i =>
$tableRow) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
foreach($array as $key =>
$arrayItem) {
if(strripos($dataItem->nodeValue, $key) !==
false) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
if(strripos($dataItem->nodeValue, 'keskmine') !==
false) {
$points =
$modelPunktid->createRow();
foreach ($tableRow->childNodes as $j =>
$dataItem) {
$data =
trim($dataItem->nodeValue);
if($tableRow->childNodes->item(0)->nodeValue !=
'') {
case $array['nimi']:
$personID =
$this->fetchPersonID($data); break;
case $array['1.']:
$points->p1 = (int)
$data; break;
case $array['2.']:
$points->p2 = (int)
$data; break;
case $array['3.']:
$points->p3 = (int)
$data; break;
case $array['4.']:
$points->p4 = (int)
$data; break;
case $array['5.']:
$points->p5 = (int)
$data; break;
case $array['summa']:
$points->summa = (int)
$data; break;
$this->saveLahtineOverall($personID, $dateID, $points->id, $classID, $groupID, $schoolID);
$this->view->error =
'Selline tabel on juba andmebaasi lisatud.';
* Method for saving 'Lõppvoorud' competition results.
* All data from given table URL is being inserted into database.
* @param int $date Competition date
* @param string $url HTML table URL
foreach($tableRows as $i =>
$tableRow) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
foreach($array as $key =>
$arrayItem) {
if(strripos($dataItem->nodeValue, $key) !==
false) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
if(strripos($dataItem->nodeValue, 'keskmine') !==
false) {
$points =
$modelPunktid->createRow();
foreach ($tableRow->childNodes as $j =>
$dataItem) {
$data =
trim($dataItem->nodeValue);
case $array['nimi']:
$personID =
$this->fetchPersonID($data); break;
case $array['1.']:
$points->p1 = (int)
$data; break;
case $array['2.']:
$points->p2 = (int)
$data; break;
case $array['3.']:
$points->p3 = (int)
$data; break;
case $array['4.']:
$points->p4 = (int)
$data; break;
case $array['5.']:
$points->p5 = (int)
$data; break;
case $array['summa']:
$points->summa = (int)
$data; break;
case $array['kokku']:
$points->summa = (int)
$data; break;
$this->saveLoppOverall($personID, $dateID, $points->id, $classID, $schoolID);
$this->view->error =
'Selline tabel on juba andmebaasi lisatud.';
* Method for saving 'Piirkonnavoorud' competition results.
* All data from given table URL is being inserted into database.
* @param int $date Competition date
* @param string $url HTML table URL
foreach($tableRows as $i =>
$tableRow) {
foreach ($tableRow->childNodes as $j =>
$dataItem) {
foreach($array as $key =>
$arrayItem) {
if(strripos($dataItem->nodeValue, $key) !==
false) {
$array[$key] =
$j+
$addition;
if($key ==
'1.' ||
$key ==
'test' ||
$addition !=
0) {
$sumTwo =
$array['nimi'] +
$array['piirkond'];
$isEven =
($sumTwo %
2 ==
0)?
true:
false;
$addition +=
($isEven)?
2:
1;
foreach ($tableRow->childNodes as $j =>
$dataItem) {
if(strripos($dataItem->nodeValue, 'keskmine') !==
false) {
$points =
$modelPunktid->createRow();
foreach ($tableRow->childNodes as $j =>
$dataItem) {
$data =
trim($dataItem->nodeValue);
case $array['nimi']:
$personID =
$this->fetchPersonID($data); break;
case $array['piirkond']:
$areaID =
$this->fetchAreaID($data); break;
case $array['kool']:
$schoolID =
$this->fetchSchoolID($data, $areaID); break;
case $array['test']:
$points->test = (int)
$data; break;
case $array['1.']:
$points->p1 = (int)
$data; break;
case $array['2.']:
$points->p2 = (int)
$data; break;
case $array['3.']:
$points->p3 = (int)
$data; break;
case $array['4.']:
$points->p4 = (int)
$data; break;
case $array['5.']:
$points->p5 = (int)
$data; break;
case $array['6.']:
$points->p6 = (int)
$data; break;
case $array['summa']:
$points->summa = (int)
$data; break;
$this->view->error =
'Selline tabel on juba andmebaasi lisatud.';
* Method for fetching competition date ID.
* Competition date is being fetched from database by its string presentation.
* @param string $date Competition date
* @return int $dateID Competition date ID
$result =
$modelDates->fetchByDate($date);
$result =
$modelDates->createRow();
$result->VoistluseID =
2;
$result->Kuupaev =
$date;
$dateID =
$result->VoistluseKuupaevaID;
* Method for fetching competition date ID.
* Competition date is being fetched from database by its ID.
* @param int $date Competition date
* @return int $dateID Competition date ID
$result =
$modelDates->fetchRow('VoistluseKuupaevaID=' . (int)
$date);
$result =
$modelDates->createRow();
$result->VoistluseID =
2;
$result->Kuupaev =
$date;
$dateID =
$result->VoistluseKuupaevaID;
* Method for fetching competition group ID.
* Group is being fetched from database by result table URL,
* which contains information about the group.
* @param string $url Result table URL
* @return int $groupID Group ID
$group =
substr($group[1], 0,1);
$groupID =
($group ==
'n')?
1:
2;
* Method for fetching participant's class ID.
* Class is being fetched from database by result table URL,
* which contains information about the class.
* @param string $url Result table URL
* @return int $classID Class ID
$data =
explode('klass', $data[6]);
$class =
$modelKlass->fetchByName($data);
$class =
$modelKlass->createRow();
$class->number = (int)
$data;
* Method for fetching participant's class ID.
* Class ID is being fetched from database by its string presentation.
* @param string $data Class number
* @return int $classID Class ID
$class =
$modelKlass->fetchByName($data);
$class =
$modelKlass->createRow();
$class->number = (int)
$data;
* Method for fetching participant's ID.
* Participant is being fetched from database by his/her name.
* @param string $data Participant name
* @return int $personID Participant ID
$newData =
split('\(', $data);
$realClass =
new Zend_Session_Namespace('realClass');
$realClass->value =
null;
if(count($newData) ==
2) {
$class =
substr($newData[1], 0, -
4);
$realClass->value =
$class;
$person =
$modelOsaleja->fetchByName($data);
$person =
$modelOsaleja->createRow();
* Method for fetching area ID.
* Area ID is being fetched from database by area name.
* @param string $data Area name
* @return int $areaID Area ID
if(strpos($data, 'Tallinn') !==
false) {
$area =
$modelPiirkond->fetchByName($data);
$area =
$modelPiirkond->createRow();
* Method for fetching school ID and editing its area ID.
* School ID is being fetched from database by school name.
* In case school's area ID is empty, it is being replaced
* @param string $data School name
* @param int $areaID Area ID
* @return int $schoolID School ID
$school =
$modelKool->fetchByName($data);
$school =
$modelKool->createRow();
if($school->piirkondID ==
'') {
$school->piirkondID =
$areaID;
* Method for fetching school ID.
* School ID is being fetched from database by school name.
* @param string $data School name
* @return int $schoolID School ID
$school =
$modelKool->fetchByName($data);
$school =
$modelKool->createRow();
* Method for saving 'Piirkonnavoorud' competition.
* A row is inserted to aggregate table with all the necessary ID fields.
* @param int $personID Participant ID
* @param int $dateID Date ID
* @param int $pointsID Points ID
* @param int $classID Class ID
* @param int $schoolID School ID
$overall =
$modelKoond->createRow();
$overall->osalejaID =
$personID;
$overall->kuupaevID =
$dateID;
$overall->punktidID =
$pointsID;
$overall->klassID =
$classID;
$overall->koolID =
$schoolID;
$realClass =
new Zend_Session_Namespace('realClass');
if($realClass->value !=
null) {
$realClass->value =
null;
$overall->tegelikKlassID =
$classID;
* Method for saving 'Valikvõistlused' competition.
* A row is inserted to aggregate table with all the necessary ID fields.
* @param int $personID Participant ID
* @param int $dateID Date ID
* @param int $pointsID Points ID
* @param int $classID Class ID
* @param int $schoolID School ID
private function saveValikOverall($personID, $dateID, $pointsID, $classID, $schoolID)
$overall =
$modelKoond->createRow();
$overall->osalejaID =
$personID;
$overall->kuupaevID =
$dateID;
$overall->punktidID =
$pointsID;
$overall->klassID =
$classID;
$overall->koolID =
$schoolID;
* Method for saving 'Lahtised võistlused' competition.
* A row is inserted to aggregate table with all the necessary ID fields.
* @param int $personID Participant ID
* @param int $dateID Date ID
* @param int $pointsID Points ID
* @param int $classID Class ID
* @param int $groupID Group ID
* @param int $schoolID School ID
private function saveLahtineOverall($personID, $dateID, $pointsID, $classID, $groupID, $schoolID)
$overall =
$modelKoond->createRow();
$overall->osalejaID =
$personID;
$overall->kuupaevID =
$dateID;
$overall->punktidID =
$pointsID;
$overall->klassID =
$classID;
$overall->ryhmID =
$groupID;
$overall->koolID =
$schoolID;
* Method for saving 'Lõppvoorud' competition.
* A row is inserted to aggregate table with all the necessary ID fields.
* @param int $personID Participant ID
* @param int $dateID Date ID
* @param int $pointsID Points ID
* @param int $classID Class ID
* @param int $schoolID School ID
private function saveLoppOverall($personID, $dateID, $pointsID, $classID, $schoolID)
$overall =
$modelKoond->createRow();
$overall->osalejaID =
$personID;
$overall->kuupaevID =
$dateID;
$overall->punktidID =
$pointsID;
$overall->klassID =
$classID;
$overall->koolID =
$schoolID;
$realClass =
new Zend_Session_Namespace('realClass');
if($realClass->value !=
null) {
$realClass->value =
null;
$overall->tegelikKlassID =
$classID;
* Method for getting URL table rows..
* Table rows are fetched from given URL and returned as DOM elements.
* @param string $url Result table URL
* @return mixed $rows Table rows
$client =
new Zend_Http_Client($url);
$dom =
new Zend_Dom_Query($client->request()->getBody());
$rows =
$dom->query('tr');
* Method for fetching class number.
* Class number is being fetched from database by class ID.
* @param int $classID Class ID
* @return string $classNumber Class number
$class =
$modelKlass->fetchRow('id=' . (int)
$classID);
$classNumber =
$class->number;
* Method for checking 'Piirkonnavoorud' competition record existance.
* Database is being checked if there already is a record with given
* Based on the result boolean is returned.
* @param int $dateID Date ID
* @param int $personID Participant ID
* @param int $schoolID School ID
* @param int $classID Class ID
$exists =
$modelKoond->fetchResult($dateID, $personID, $schoolID, $classID);
if(count($exists) !=
0) {
* Method for checking 'Lõppvoorud' competition record existance.
* Database is being checked if there already is a record with given
* Based on the result boolean is returned.
* @param int $dateID Date ID
* @param int $personID Participant ID
* @param int $schoolID School ID
* @param int $classID Class ID
$exists =
$modelKoond->fetchResult($dateID, $personID, $schoolID, $classID);
if(count($exists) !=
0) {
* Method for checking 'Valikvõistlused' competition record existance.
* Database is being checked if there already is a record with given
* Based on the result boolean is returned.
* @param int $dateID Date ID
* @param int $personID Participant ID
* @param int $schoolID School ID
* @param int $classID Class ID
$exists =
$modelKoond->fetchResult($dateID, $personID, $schoolID, $classID);
if(count($exists) !=
0) {
* Method for checking 'Lahtised võistlused' competition record existance.
* Database is being checked if there already is a record with given
* Based on the result boolean is returned.
* @param int $dateID Date ID
* @param int $personID Participant ID
* @param int $schoolID School ID
* @param int $classID Class ID
$exists =
$modelKoond->fetchResult($dateID, $personID, $schoolID, $classID);
if(count($exists) !=
0) {
Documentation generated on Mon, 20 Jun 2011 05:43:09 +0300 by phpDocumentor 1.4.1