From: <pan...@us...> - 2009-01-31 20:38:20
|
Revision: 465 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=465&view=rev Author: panzaboi Date: 2009-01-31 20:38:09 +0000 (Sat, 31 Jan 2009) Log Message: ----------- 1) Added Zend_Paginator, to split data across pages. 2) Changed login action, to work with new design. 3) Added view user action. 4) Implemented Action pattern to calculate score of submitted problem. 5) Changed structure. Tables are in models/Table/ and Forms in models/Form 6) Layout changes in Forms 7) Implemeneted multilanguage support in Forms and etc 8) Added Tester module, to transport data between tester and site. 9) Fixed small redirect issue 10) Fixed Db_Table::get with different primary keys 11) Improved Measure helper 12) Added Admin module, including crud action + table to the library. 13) Changed forms to Dojo Forms. 14) Modified HtmlTag to library, to contain markup Modified Paths: -------------- website/application/modules/acm/controllers/ContestController.php website/application/modules/acm/controllers/IndexController.php website/application/modules/acm/controllers/UserController.php website/application/modules/acm/models/Contest.php website/application/modules/acm/models/Form/Login.php website/application/modules/acm/models/Form/Register.php website/application/modules/acm/models/Form/Submit.php website/application/modules/acm/models/Tester.php website/application/modules/acm/models/User.php website/library/Application.php website/library/Ostacium/Acl.php website/library/Ostacium/Controller/Action.php website/library/Ostacium/Controller/CrudAction.php website/library/Ostacium/Controller/Plugin/ErrorHandler.php website/library/Ostacium/Date.php website/library/Ostacium/Db/Table.php website/library/Ostacium/View/Helper/Measure.php Added Paths: ----------- website/application/modules/acm/models/Calc/ website/application/modules/acm/models/Calc/ACM.php website/application/modules/acm/models/Calc.php website/application/modules/acm/models/Form/SmallLogin.php website/application/modules/acm/models/Table/ website/application/modules/acm/models/Table/ArchiveResults.php website/application/modules/acm/models/Table/Challenges.php website/application/modules/acm/models/Table/Contests.php website/application/modules/acm/models/Table/ContestsApplicants.php website/application/modules/acm/models/Table/ContestsResults.php website/application/modules/acm/models/Table/Submits.php website/application/modules/acm/models/Table/Users.php website/application/modules/acm/models/Table/UsersDetails.php website/application/modules/acm/models/Table/UsersStats.php website/application/modules/admin/controllers/ website/application/modules/admin/controllers/IndexController.php website/application/modules/admin/controllers/SettingsController.php website/application/modules/admin/models/ website/application/modules/admin/models/Form/ website/application/modules/admin/models/Form/Settings.php website/application/modules/admin/models/Table/ website/application/modules/admin/models/Table/Settings.php website/library/Ostacium/Controller/Action/ website/library/Ostacium/Controller/Action/Crud.php website/library/Ostacium/Db/Table/Crud.php website/library/Ostacium/Dojo/ website/library/Ostacium/Dojo/Form/ website/library/Ostacium/Dojo/Form/Crud.php website/library/Ostacium/Form/Decorator/HtmlTag.php website/library/Ostacium/View/Helper/CrudList.php Modified: website/application/modules/acm/controllers/ContestController.php =================================================================== --- website/application/modules/acm/controllers/ContestController.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/controllers/ContestController.php 2009-01-31 20:38:09 UTC (rev 465) @@ -1,12 +1,27 @@ <?php class Acm_ContestController extends Ostacium_Controller_Action -{ +{ public function indexAction() { - $this->view->contests = $this->_model->getContests(); + $contests = $this->_model->getContests(); + $paginator = Zend_Paginator::factory($contests); + $paginator->setItemCountPerPage($this->_config->table->perpage); + $paginator->setCurrentPageNumber($this->_getParam('page')); + + $this->view->contests = $paginator; } + public function newAction() + { + + } + + public function addAction() + { + + } + public function registerAction() { $contestid = $this->_getParam('contestid'); @@ -43,7 +58,10 @@ { $contestid = $this->_getParam('contestid'); - // check if user is in this contest + if (!$this->_model->isInContest($contestid)) + { + return $this->render('notincontest'); + } $this->view->challenges = $this->_model->getChallenges($contestid); } Modified: website/application/modules/acm/controllers/IndexController.php =================================================================== --- website/application/modules/acm/controllers/IndexController.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/controllers/IndexController.php 2009-01-31 20:38:09 UTC (rev 465) @@ -4,24 +4,32 @@ { public function indexAction() { - $form = new Form_Login(); - echo $form; + var_dump('sadfasdf'); } public function loginAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + $form = new Form_Login(); + if ($this->_getParam('message')) + { + $form->setDescription($this->view->translate($this->_getParam('message'))); + $this->view->message = null; + } if (!$this->getRequest()->isPost()) { - return $this->_forward('index', null, null, $this->_getAllParams()); + echo $form; + + return; } if (!$form->isValid($this->getRequest()->getPost())) { - $this->view->form = $form; - $this->renderScript('layout/loginform.phtml', 'login'); - return $this->_forward('index'); + echo $form; + + return; } $values = $form->getValues(); @@ -30,11 +38,10 @@ if (!$result) { - $form->setDescription($this->view->translate('wrongEmailPwd')); - $this->view->form = $form; - //$this->renderScript('layout/loginform.phtml', 'login'); + $form->setDescription($this->view->translate('error_bad_login')); + echo $form; - return $this->_forward('index'); + return; } $redirect = new Zend_Session_Namespace('Redirect'); @@ -47,12 +54,12 @@ { return $this->_redirect('/acm/index/index'); } - - $this->_helper->getHelper('viewRenderer')->setNoRender(true); } public function logoutAction() { Zend_Auth::getInstance()->clearIdentity(); + + $this->_redirect('/acm/index/index'); } } \ No newline at end of file Modified: website/application/modules/acm/controllers/UserController.php =================================================================== --- website/application/modules/acm/controllers/UserController.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/controllers/UserController.php 2009-01-31 20:38:09 UTC (rev 465) @@ -71,6 +71,10 @@ public function viewAction() { + $username = $this->_getParam('username'); + $this->view->assign($this->_model->getUser($username)); + var_dump($this->_model->getUser($username)); + //var_dump($this->view->user); } } \ No newline at end of file Property changes on: website/application/modules/acm/models/Calc ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/models/Calc/ACM.php =================================================================== --- website/application/modules/acm/models/Calc/ACM.php (rev 0) +++ website/application/modules/acm/models/Calc/ACM.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,39 @@ +<?php + +class Calc_ACM implements Calc +{ + public function calcCost(array $submit, array $result, array $contest) + { + if ($submit['firsttest'] == 1) return false; + + $_config = Zend_Registry::get('config'); + + if (!count($result)) + { + $result = array( + 'contestid' => $submit['contestid'], + 'username' => $submit['username'], + 'challengeid' => $submit['challengeid'], + 'tries' => 0, + 'penalty' => 0, + 'accepted' => 0, + ); + } + + if ($result['accepted']) return false; + + $result['tries']++; + + if ($submit['state'] == 1) + { + $result['accepted'] = 1; + $result['penalty'] += floor((time() - $contest['start'])/60); + } + elseif ($submit['state'] > 1) + { + $result['penalty'] += $_config->calc->acm->penalty; + } + + return $result; + } +} \ No newline at end of file Added: website/application/modules/acm/models/Calc.php =================================================================== --- website/application/modules/acm/models/Calc.php (rev 0) +++ website/application/modules/acm/models/Calc.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,6 @@ +<?php + +interface Calc +{ + public function calcCost(array $submit, array $result, array $contest); +} \ No newline at end of file Modified: website/application/modules/acm/models/Contest.php =================================================================== --- website/application/modules/acm/models/Contest.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/models/Contest.php 2009-01-31 20:38:09 UTC (rev 465) @@ -2,9 +2,22 @@ class Contest extends Ostacium_Model { + protected $calc = null; + + public function __construct(Calc $calc = null) + { + parent::__construct(); + if ($calc) $this->calc = $calc; + } + + public function setCalc(Calc $calc) + { + $this->calc = $calc; + } + public function getContests() { - $contests = new Contests(); + $contests = new Table_Contests(); return $contests->getAll(); } @@ -12,7 +25,7 @@ { $username = Zend_Auth::getInstance()->getStorage()->read()->username; - $ca = new ContestsApplicants(); + $ca = new Table_ContestsApplicants(); $ca->insert(array('username' => $username, 'contestid' => $id)); return true; @@ -20,28 +33,28 @@ public function isContestRunning($contestid) { - $contest = new Contests(); + $contest = new Table_Contests(); return $contest->isRunning($contestid); } public function isInContest($contestid) { $username = Zend_Auth::getInstance()->getStorage()->read()->username; - $contest = new Contests(); + $contest = new Table_Contests(); return $contest->isInContest($contestid, $username); } public function getChallenges($contestid) { - $challenges = new Challenges(); - return $challenges->getAll($contestid); + $challenges = new Table_Challenges(); + return $challenges->getAllFromContest($contestid); } public function getChallenge($id, $contestid) { - $challenges = new Challenges(); - return $challenges->get($id, $contestid); + $challenges = new Table_Challenges(); + return $challenges->getFromContest($id, $contestid); } public function addSubmit($values) @@ -55,11 +68,11 @@ 'when' => time() ); - $contest = new Contests(); + $contest = new Table_Contests(); if ($contest->isRunning($values['contestid'])) { - $submits = new Submits(); + $submits = new Table_Submits(); return $submits->insert($data); } else @@ -68,98 +81,43 @@ public function getSubmits($contestid) { - $submits = new Submits(); - return $submits->getAll($contestid); + $submits = new Table_Submits(); + return $submits->getAllFromContest($contestid); } -} - -class Challenges extends Ostacium_Db_Table -{ - protected $_name = 'challenges'; - protected $_primary = 'id'; - public function getAll($contestid) - { - return $this->selectLang(array('name', 'description')) - ->joinLeft(array('c' => 'contests'), $this->getAdapter()->quoteInto('c.id = ? AND c.start <= UNIX_TIMESTAMP() AND c.end > UNIX_TIMESTAMP()', $contestid), array()) - ->joinLeft(array('cc' => 'contests_challenges'), 'cc.contestid = c.id', 'contestid') - ->where('challenges.id = cc.challengeid') - ->query()->fetchAll(); - } - - public function get($id, $contestid) + public function updateResults($submit) { - return $this->selectLang(array('name', 'description')) - ->joinLeft(array('c' => 'contests'), $this->getAdapter()->quoteInto('c.id = ? AND c.start <= UNIX_TIMESTAMP() AND c.end > UNIX_TIMESTAMP()', $contestid), array()) - ->joinLeft(array('cc' => 'contests_challenges'), $this->getAdapter()->quoteInto('cc.contestid = c.id AND cc.challengeid = ?', $id), 'contestid') - ->where('challenges.id = cc.challengeid') - ->query()->fetch(); - } -} - -class Submits extends Ostacium_Db_Table -{ - protected $_name = 'submits'; - protected $_primary = 'id'; - - public function getAll($contestid) - { - return $this->select()->setIntegrityCheck(false) - ->from($this) - ->joinLeft('code_languages', 'code_languages.id = submits.codelangid', array('codelang' => 'name')) - ->joinLeft(array('c' => 'contests'), $this->getAdapter()->quoteInto('c.id = ?', $contestid), array()) - ->where('submits.contestid = c.id')->order('submits.id DESC') - ->query()->fetchAll(); - } -} - -class Contests extends Ostacium_Db_Table -{ - protected $_name = 'contests'; - protected $_primary = 'id'; - - public function isRunning($contestid) - { - $id = $this->select()->from($this, 'id') - ->where('id = ? AND start <= UNIX_TIMESTAMP() AND end >= UNIX_TIMESTAMP() AND enabled = 1', $contestid) - ->query()->fetchColumn('id'); + // LOG THIS/FAIL! + if (!$this->calc) return false; - if ($id && $id == $contestid) - return true; + $contests = new Table_Contests(); + $contest = $contests->get($submit['contestid'])->toArray(); + + $results = new Table_ContestsResults(); + $result = $results->get(array($submit['contestid'], $submit['username'], $submit['challengeid'])); + + if ($result) + $result = $result->toArray(); else - return false; + $result = array(); + + $newresult = $this->calc->calcCost($submit, $result, $contest); + + if (!count($result) && $newresult !== false) + { + $results->insert($newresult); + } + elseif ($newresult != $result && $newresult !== false) + { + $where = array( + $this->_db->quoteInto('contestid = ?', $newresult['contestid']), + $this->_db->quoteInto('username = ?', $newresult['username']), + $this->_db->quoteInto('challengeid = ?', $newresult['challengeid']), + ); + + $results->update($newresult, $where); + } } - - public function getAll() - { - return $this->selectLang(array('name', 'description')) - ->where('enabled = 1 AND start <= UNIX_TIMESTAMP() AND end > UNIX_TIMESTAMP()') - ->query()->fetchAll(); - } - - public function isInContest($contestid, $username) - { - $id = $this->select()->setIntegrityCheck(false) - ->from(array('c' => $this->_name), 'id') - ->joinInner(array('a' => 'contests_applicants'), 'c.id=a.contestid', array()) - ->where('c.id = ?', $contestid) - ->where('a.username = ?', $username) - ->query()->fetchColumn('username'); - - if ($id && $id == $contestid) return true; - else return false; - } } -class ContestsApplicants extends Ostacium_Db_Table -{ - protected $_name = 'contests_applicants'; - protected $_primary = array('contestid', 'username'); -} - -class Users extends Ostacium_Db_Table -{ - protected $_name = 'users'; - protected $_primaty = 'username'; -} \ No newline at end of file Modified: website/application/modules/acm/models/Form/Login.php =================================================================== --- website/application/modules/acm/models/Form/Login.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/models/Form/Login.php 2009-01-31 20:38:09 UTC (rev 465) @@ -5,12 +5,13 @@ public $elementDecorators = array( 'DijitElement', 'Errors', - array('Label', array('class' => 'overlabel')), - array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) + array('Label', array('class' => 'label')), + array('HtmlTag', array('tag' => 'div', 'class' => 'line')) ); public $buttonDecorators = array( 'DijitElement', + array('HtmlTag', array('tag' => 'div', 'class' => 'line tr')) ); public function init() @@ -21,6 +22,7 @@ $this->setAction($router->assemble(array('action' => 'login', 'controller' => 'index'), null)); $this->setMethod('post'); $this->setName('loginform'); + $this->setAttrib('class', 'form'); $this->addElement('ValidationTextBox', 'username', array( 'decorators' => $this->elementDecorators, @@ -32,11 +34,11 @@ 'maxlength' => 50, 'trim' => true, 'lowercase' => true, - 'style' => 'height: 18px; width: 100px;', 'regExp' => '[\w]{5,50}', 'invalidMessage' => sprintf($translate->_('wordErrorBetween'), 5, 50), - 'title' => 'Username', - 'label' => 'Username:', + 'title' => $translate->_('username'), + 'label' => $translate->_('username').':', + 'class' => 'text', )); $this->addElement('PasswordTextBox', 'password', array( @@ -48,35 +50,34 @@ ), 'required' => true, 'trim' => true, - 'style' => 'height: 18px; width: 100px;', 'regExp' => '[\S]{5,32}', 'invalidMessage' => sprintf($translate->_('errorBetween'), 5, 32), - 'title' => 'Password', - 'label' => 'Password:', + 'title' => $translate->_('password'), + 'label' => $translate->_('password').':', + 'class' => 'text', )); - - $this->addElement('SubmitButton', 'loginbutton', array( 'decorators' => $this->buttonDecorators, 'required' => false, 'ignore' => true, - 'label' => 'Login', + 'label' => $translate->_('login'), + 'class' => 'submit' )); } public function loadDefaultDecorators() { -// $this->setDecorators(array( -// 'FormElements', -// 'Form', -// array('Description', array('placement' => 'prepend', 'tag' => 'div', 'class' => 'error')), -// )); - + //$this->addElementPrefixPath('Ostacium/Form/Decorator', 'Ostacium_Form_Decorator', 'Decorator'); + $this->addPrefixPath('Ostacium_Form_Decorator', 'Ostacium/Form/Decorator', 'Decorator'); + $translate = Zend_Registry::get('Zend_Translate'); + $this->setDecorators(array( 'FormElements', 'DijitForm', array('Description', array('placement' => 'prepend', 'tag' => 'div', 'class' => 'error')), + array(array('h2' => 'HtmlTag'), array('tag' => 'h2', 'placement' => 'prepend', 'markup' => $translate->_('login'))), + array(array('div' => 'HtmlTag'), array('tag' => 'div', 'class' => 'box c')) )); } } \ No newline at end of file Modified: website/application/modules/acm/models/Form/Register.php =================================================================== --- website/application/modules/acm/models/Form/Register.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/models/Form/Register.php 2009-01-31 20:38:09 UTC (rev 465) @@ -5,18 +5,19 @@ public $elementDecorators = array( 'DijitElement', 'Errors', - array('Label', array('class' => 'overlabel')), + array('Label', array('class' => 'label')), array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) ); public $simpleDecorators = array( 'Errors', - array('Label', array('class' => 'overlabel')), + array('Label', array('class' => 'label')), array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) ); public $buttonDecorators = array( 'DijitElement', + array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer tc')) ); public function init() @@ -28,6 +29,7 @@ $this->setAction($router->assemble(array('action' => 'register'), null)); $this->setMethod('post'); $this->setName('registerform'); + $this->setAttrib('class', 'registerform c'); $this->addElement('ValidationTextBox', 'username', array( 'decorators' => $this->elementDecorators, @@ -41,6 +43,7 @@ 'invalidMessage' => sprintf($translate->_('errorBetween'), 5, 50), 'title' => $translate->_('username'), 'label' => $translate->_('username').': ', + 'id' => 'username_reg' )); $this->addElement('PasswordTextBox', 'password', array( @@ -55,6 +58,7 @@ 'invalidMessage' => sprintf($translate->_('errorBetween'), 5, 32), 'title' => $translate->_('password'), 'label' => $translate->_('password').': ', + 'id' => 'password_reg' )); $this->addElement('PasswordTextBox', 'cpassword', array( @@ -91,8 +95,8 @@ $this->addElement('Checkbox', 'hideemail', array( 'decorators' => $this->elementDecorators, 'required' => true, - 'title' => $translate->_('hideemail'), - 'label' => $translate->_('hideemail').': ', + 'title' => $translate->_('hide_email'), + 'label' => $translate->_('hide_email').': ', 'multiOptions' => array($translate->_('no'), $translate->_('yes')), )); @@ -134,8 +138,8 @@ 'required' => false, 'regExp' => '[\w ]{0,50}', 'invalidMessage' => sprintf($translate->_('errorMore'), 50), - 'title' => $translate->_('study'), - 'label' => $translate->_('study').': ', + 'title' => $translate->_('edu_place'), + 'label' => $translate->_('edu_place').': ', )); $this->addElement('DateTextBox', 'birthday', array( @@ -171,8 +175,8 @@ 'required' => false, 'regExp' => '[\S]{0,50}', 'invalidMessage' => sprintf($translate->_('errorMore'), 50), - 'title' => $translate->_('icq'), - 'label' => $translate->_('icq').': ', + 'title' => $translate->_('icq_handle'), + 'label' => $translate->_('icq_handle').': ', )); $this->addElement('ValidationTextBox', 'msn', array( @@ -185,8 +189,8 @@ 'required' => false, 'regExp' => '[\S]{0,100}', 'invalidMessage' => sprintf($translate->_('errorMore'), 100), - 'title' => $translate->_('msn'), - 'label' => $translate->_('msn').': ', + 'title' => $translate->_('msn_handle'), + 'label' => $translate->_('msn_handle').': ', )); $this->addElement('ValidationTextBox', 'skype', array( @@ -199,8 +203,8 @@ 'required' => false, 'regExp' => '[\S]{0,50}', 'invalidMessage' => sprintf($translate->_('errorMore'), 50), - 'title' => $translate->_('skype'), - 'label' => $translate->_('skype').': ', + 'title' => $translate->_('skype_handle'), + 'label' => $translate->_('skype_handle').': ', )); $this->addElement('ValidationTextBox', 'yahoo', array( @@ -213,8 +217,8 @@ 'required' => false, 'regExp' => '[\S]{0,50}', 'invalidMessage' => sprintf($translate->_('errorMore'), 50), - 'title' => $translate->_('yahoo'), - 'label' => $translate->_('yahoo').': ', + 'title' => $translate->_('yahoo_handle'), + 'label' => $translate->_('yahoo_handle').': ', )); $this->addElement('ValidationTextBox', 'web', array( @@ -227,8 +231,8 @@ 'required' => false, 'regExp' => '[\S]{0,100}', 'invalidMessage' => sprintf($translate->_('errorMore'), 100), - 'title' => $translate->_('web'), - 'label' => $translate->_('web').': ', + 'title' => $translate->_('website'), + 'label' => $translate->_('website').': ', )); $this->addElement('ValidationTextBox', 'topcoder', array( @@ -241,8 +245,8 @@ 'required' => false, 'regExp' => '[\S]{0,50}', 'invalidMessage' => sprintf($translate->_('errorMore'), 50), - 'title' => $translate->_('topcoder'), - 'label' => $translate->_('topcoder').': ', + 'title' => $translate->_('tc_handle'), + 'label' => $translate->_('tc_handle').': ', )); $this->addElement('ValidationTextBox', 'timus', array( @@ -255,8 +259,8 @@ 'required' => false, 'regExp' => '[\S]{0,50}', 'invalidMessage' => sprintf($translate->_('errorMore'), 50), - 'title' => $translate->_('timus'), - 'label' => $translate->_('timus').': ', + 'title' => $translate->_('timus_handle'), + 'label' => $translate->_('timus_handle').': ', )); $offset = array(-12 => -12, -11 => -11, -10 => -10, -9 => -9, -8 => -8, -7 => -7, -6 => -6, -5 => -5, -4 => -4, -3 => -3, -2 => -2, -1 => -1, 0 => 0, '+1' => '+1', '+2' => '+2', '+3' => '+3', '+4' => '+4', '+5' => '+5', '+6' => '+6', '+7' => '+7', '+8' => '+8', '+9' => '+9', '+10' => '+10', '+11' => '+11', '+12' => '+12', '+13' => '+13'); Added: website/application/modules/acm/models/Form/SmallLogin.php =================================================================== --- website/application/modules/acm/models/Form/SmallLogin.php (rev 0) +++ website/application/modules/acm/models/Form/SmallLogin.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,85 @@ +<?php + +class Form_SmallLogin extends Zend_Dojo_Form +{ + public $elementDecorators = array( + 'DijitElement', + array('Label', array('class' => 'label2')), + array('HtmlTag', array('tag' => 'div', 'class' => 'line')) + ); + + public $buttonDecorators = array( + 'DijitElement', + array('HtmlTag', array('tag' => 'div', 'class' => 'line tr')) + ); + + public function init() + { + $translate = Zend_Registry::get('Zend_Translate'); + $router = Zend_Controller_Front::getInstance()->getRouter(); + + $this->setAction($router->assemble(array('action' => 'login', 'controller' => 'index'), null)); + $this->setMethod('post'); + $this->setName('loginform'); + $this->setAttrib('class', 'form'); + + $this->addElement('ValidationTextBox', 'username', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim', 'StringToLower'), + 'validators' => array( + array('StringLength', false, array(5, 50)), + ), + 'required' => true, + 'maxlength' => 50, + 'trim' => true, + 'lowercase' => true, + 'regExp' => '[\w]{5,50}', + 'invalidMessage' => sprintf($translate->_('enter_username_between'), 5, 50), + 'title' => $translate->_('username'), + 'label' => $translate->_('username').':', + 'class' => 'text', + )); + + $this->addElement('PasswordTextBox', 'password', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim'), + 'validators' => array( + 'Alnum', + array('StringLength', false, array(5, 32)), + ), + 'required' => true, + 'trim' => true, + 'regExp' => '[\S]{5,32}', + 'invalidMessage' => sprintf($translate->_('enter_password_between'), 5, 32), + 'title' => $translate->_('password'), + 'label' => $translate->_('password').':', + 'class' => 'text', + )); + + $this->addElement('Button', 'signupbutton', array( + 'decorators' => $this->buttonDecorators, + 'required' => false, + 'ignore' => true, + 'label' => $translate->_('signup'), + 'class' => 'signup2', + 'onclick' => 'return goToUrl("'.$router->assemble(array('action' => 'register', 'controller' => 'user'), null).'")' + )); + + $this->addElement('SubmitButton', 'loginbutton', array( + 'decorators' => $this->buttonDecorators, + 'required' => false, + 'ignore' => true, + 'label' => $translate->_('login'), + 'class' => 'submit2' + )); + } + + public function loadDefaultDecorators() + { + $this->setDecorators(array( + 'FormElements', + 'DijitForm', + array('HtmlTag', array('tag' => 'div', 'class' => 'box2 c')) + )); + } +} \ No newline at end of file Modified: website/application/modules/acm/models/Form/Submit.php =================================================================== --- website/application/modules/acm/models/Form/Submit.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/models/Form/Submit.php 2009-01-31 20:38:09 UTC (rev 465) @@ -5,18 +5,19 @@ public $elementDecorators = array( 'DijitElement', 'Errors', - array('Label', array('class' => 'overlabel')), + array('Label', array('class' => 'label')), array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) ); public $simpleDecorators = array( 'Errors', - array('Label', array('class' => 'overlabel')), + array('Label', array('class' => 'label')), array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) ); public $buttonDecorators = array( 'DijitElement', + array('HtmlTag', array('tag' => 'div', 'class' => 'elcontainer')) ); public function init() @@ -27,16 +28,19 @@ $request = Zend_Controller_Front::getInstance()->getRequest(); $this->setAttrib('enctype', 'multipart/form-data'); + $this->setAttrib('class', 'submitform'); $this->setAction($router->assemble(array('action' => 'upload', 'id' => $request->getParam('id')), null)); $this->setMethod('post'); $this->setName('submitform'); + $this->getView()->addHelperPath('Ostacium/Dojo/View/Helper', 'Ostacium_Dojo_View_Helper'); + $this->addElement('FilteringSelect', 'languageid', array( 'decorators' => $this->elementDecorators, 'required' => true, - 'style' => 'height: 18px; width: 100px;', - 'title' => $translate->_('code_language'), - 'label' => $translate->_('code_language').': ', + 'style' => 'width: 100px;', + 'title' => $translate->_('language'), + 'label' => $translate->_('language').': ', 'multiOptions' => $db->fetchPairs($db->select()->from('code_languages', array('id', 'name'))), 'value' => (Zend_Auth::getInstance()->getStorage()->read()->codelangid) )); @@ -44,45 +48,46 @@ $this->addElement('RadioButton', 'type', array( 'decorators' => $this->elementDecorators, 'required' => true, - 'title' => $translate->_('upload_type'), - 'label' => $translate->_('upload_type ').': ', - 'multiOptions' => array($translate->_('editor'), $translate->_('file_upload')), + 'title' => $translate->_('submit_type'), + 'label' => $translate->_('submit_type').': ', + 'multiOptions' => array($translate->_('source_code'), $translate->_('file')), 'onclick' => 'changeEditor(this.value);', + 'separator' => "\n", 'value' => 0 )); $this->addElement('SimpleTextarea', 'code', array( 'decorators' => $this->elementDecorators, 'style' => 'height: 400px; width: 500px;', - 'title' => $translate->_('enter_code'), - 'label' => $translate->_('enter_code'), + 'title' => $translate->_('source_code'), + 'label' => $translate->_('source_code').': ', )); $this->addElement('File', 'codefile', array( 'decorators' => array_merge(array('File'), $this->simpleDecorators), 'validators' => array(array('Count', false, 1)), 'destination' => Application::getDocRoot().'/other/uploads/', - 'label' => $translate->_('enter_code'), + 'label' => $translate->_('choose_file').': ', )); $this->addElement('Checkbox', 'firsttest', array( 'decorators' => $this->elementDecorators, 'title' => $translate->_('first_test'), - 'label' => $translate->_('first_test ').': ' + 'label' => $translate->_('first_test').': ' )); $this->addElement('SubmitButton', 'submitbutton', array( 'decorators' => $this->buttonDecorators, 'required' => false, 'ignore' => true, - 'label' => $translate->_('submit'), + 'label' => $translate->_('submit_solution'), )); } public function loadDefaultDecorators() { $this->setDecorators(array( - 'FormElements', + 'FormElements', 'DijitForm', array('Description', array('placement' => 'prepend', 'tag' => 'div', 'class' => 'error')), )); Property changes on: website/application/modules/acm/models/Table ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/acm/models/Table/ArchiveResults.php =================================================================== --- website/application/modules/acm/models/Table/ArchiveResults.php (rev 0) +++ website/application/modules/acm/models/Table/ArchiveResults.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,7 @@ +<?php + +class Table_ArchiveResults extends Ostacium_Db_Table +{ + protected $_name = 'archive_results'; + protected $_primary = array('username', 'challengeid'); +} \ No newline at end of file Added: website/application/modules/acm/models/Table/Challenges.php =================================================================== --- website/application/modules/acm/models/Table/Challenges.php (rev 0) +++ website/application/modules/acm/models/Table/Challenges.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,50 @@ +<?php + +class Table_Challenges extends Ostacium_Db_Table +{ + protected $_name = 'challenges'; + protected $_primary = 'id'; + + public function getAllFromContest($contestid) + { + return $this->selectLang(array('name', 'description')) + ->joinLeft(array('c' => 'contests'), $this->getAdapter()->quoteInto('c.id = ? AND c.start <= UNIX_TIMESTAMP() AND c.end > UNIX_TIMESTAMP()', $contestid), array()) + ->joinLeft(array('cc' => 'contests_challenges'), 'cc.contestid = c.id', 'contestid') + ->where('challenges.id = cc.challengeid') + ->query()->fetchAll(); + } + + public function getFromContest($id, $contestid) + { + return $this->selectLang(array('name', 'description')) + ->joinLeft(array('c' => 'contests'), $this->getAdapter()->quoteInto('c.id = ? AND c.start <= UNIX_TIMESTAMP() AND c.end > UNIX_TIMESTAMP()', $contestid), array()) + ->joinLeft(array('cc' => 'contests_challenges'), $this->getAdapter()->quoteInto('cc.contestid = c.id AND cc.challengeid = ?', $id), 'contestid') + ->where('challenges.id = cc.challengeid') + ->query()->fetch(); + } + + /*public function getSubmitsFromContest($contestid, $username, $ignore_id) + { + return $this->select()->from(array('c' => $this->_name), array('*', 'COUNT(s.id) as tries', 'IF(sac.state,1,0) AS accepted', 'MIN(sac.when) AS actime')) + ->joinLeft(array('cc' => 'contests_challenges'), $this->getAdapter()->quoteInto('cc.contestid = ?', $contestid), array()) + ->joinLeft(array('s' => 'submits'), $this->getAdapter()->quoteInto('s.contestid = cc.contestid AND s.challengeid = cc.challengeid AND s.state > 1 AND s.username = ?', $username), array()) + ->joinLeft(array('sac' => 'submits'), $this->getAdapter()->quoteInto('sac.contestid = cc.contestid AND sac.challengeid = cc.challengeid AND sac.state = 1 AND s.username = ?', $username), array()) + ->where('s.id <> ?', $ignore_id) + ->where('sac.id <> ?', $ignore_id) + ->group(array('s.challengeid', 'sac.challengeid'))->query()->fetchAll(); + }*/ + + public function get($id) + { + return $this->selectLang(array('name', 'description')) + ->where('challenges.id = ? AND enabled = 1', $id) + ->query()->fetch(); + } + + public function getAll() + { + return $this->selectLang(array('name', 'description')) + ->where('challenges.enabled = 1') + ->query()->fetchAll(); + } +} \ No newline at end of file Added: website/application/modules/acm/models/Table/Contests.php =================================================================== --- website/application/modules/acm/models/Table/Contests.php (rev 0) +++ website/application/modules/acm/models/Table/Contests.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,39 @@ +<?php + +class Table_Contests extends Ostacium_Db_Table +{ + protected $_name = 'contests'; + protected $_primary = 'id'; + + public function isRunning($contestid) + { + $id = $this->select()->from($this, 'id') + ->where('id = ? AND start <= UNIX_TIMESTAMP() AND end >= UNIX_TIMESTAMP() AND enabled = 1', $contestid) + ->query()->fetchColumn('id'); + + if ($id && $id == $contestid) + return true; + else + return false; + } + + public function getAll() + { + return $this->selectLang(array('name', 'description')) + ->where('enabled = 1 AND start <= UNIX_TIMESTAMP() AND end > UNIX_TIMESTAMP()') + ->query()->fetchAll(); + } + + public function isInContest($contestid, $username) + { + $id = $this->select()->setIntegrityCheck(false) + ->from(array('c' => $this->_name), 'id') + ->joinInner(array('a' => 'contests_applicants'), 'c.id=a.contestid', array()) + ->where('c.id = ?', $contestid) + ->where('a.username = ?', $username) + ->query()->fetchColumn('username'); + + if ($id && $id == $contestid) return true; + else return false; + } +} \ No newline at end of file Added: website/application/modules/acm/models/Table/ContestsApplicants.php =================================================================== --- website/application/modules/acm/models/Table/ContestsApplicants.php (rev 0) +++ website/application/modules/acm/models/Table/ContestsApplicants.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,7 @@ +<?php + +class Table_ContestsApplicants extends Ostacium_Db_Table +{ + protected $_name = 'contests_applicants'; + protected $_primary = array('contestid', 'username'); +} \ No newline at end of file Added: website/application/modules/acm/models/Table/ContestsResults.php =================================================================== --- website/application/modules/acm/models/Table/ContestsResults.php (rev 0) +++ website/application/modules/acm/models/Table/ContestsResults.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,7 @@ +<?php + +class Table_ContestsResults extends Ostacium_Db_Table +{ + protected $_name = 'contests_results'; + protected $_primary = array('contestid', 'username', 'challengeid'); +} \ No newline at end of file Added: website/application/modules/acm/models/Table/Submits.php =================================================================== --- website/application/modules/acm/models/Table/Submits.php (rev 0) +++ website/application/modules/acm/models/Table/Submits.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,47 @@ +<?php + +class Table_Submits extends Ostacium_Db_Table +{ + protected $_name = 'submits'; + protected $_primary = 'id'; + + public function getAllFromContest($contestid) + { + return $this->select()->setIntegrityCheck(false) + ->from($this) + ->joinLeft('code_languages', 'code_languages.id = submits.codelangid', array('codelang' => 'name')) + ->joinLeft(array('c' => 'contests'), $this->getAdapter()->quoteInto('c.id = ?', $contestid), array()) + ->where('submits.contestid = c.id') + ->order('submits.id DESC') + ->query()->fetchAll(); + } + + public function getAll() + { + return $this->select()->setIntegrityCheck(false) + ->from($this) + ->joinLeft('code_languages', 'code_languages.id = submits.codelangid', array('codelang' => 'name')) + ->where('contestid = 0') + ->order('submits.id DESC') + ->query()->fetchAll(); + } + + public function getUntested() + { + return $this->select()->setIntegrityCheck(false) + ->from($this) + ->joinLeft('code_languages', 'code_languages.id = submits.codelangid', array('codelang' => 'name')) + ->where('state = 0') + ->order('id ASC') + ->query()->fetchAll(); + } + + public function getNotAccepted($id) + { + return $this->select()->setIntegrityCheck(false) + ->from(array('s' => $this->_name)) + ->joinLeft(array('ss' => 'submits'), 'ss.challengeid = s.challengeid AND ss.contestid = s.contestid AND ss.username = s.username AND ss.state = 1', array('IF(ss.id,1,0) AS aced')) + ->where('s.id = ?', $id) + ->query()->fetch(); + } +} \ No newline at end of file Added: website/application/modules/acm/models/Table/Users.php =================================================================== --- website/application/modules/acm/models/Table/Users.php (rev 0) +++ website/application/modules/acm/models/Table/Users.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,16 @@ +<?php + +class Table_Users extends Ostacium_Db_Table +{ + protected $_name = 'users'; + protected $_primaty = 'username'; + + function getUser($username) + { + return $this->select()->setIntegrityCheck(false)->from($this) + ->joinLeft(array('r' => 'roles'), 'r.id=users.roleid', array('role' => 'name')) + ->joinLeft(array('d' => 'usersdetails'), 'd.username=users.username') + ->where('users.username = ?', $username) + ->query()->fetch(); + } +} \ No newline at end of file Added: website/application/modules/acm/models/Table/UsersDetails.php =================================================================== --- website/application/modules/acm/models/Table/UsersDetails.php (rev 0) +++ website/application/modules/acm/models/Table/UsersDetails.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,7 @@ +<?php + +class Table_UsersDetails extends Ostacium_Db_Table +{ + protected $_name = 'usersdetails'; + protected $_primaty = 'username'; +} \ No newline at end of file Added: website/application/modules/acm/models/Table/UsersStats.php =================================================================== --- website/application/modules/acm/models/Table/UsersStats.php (rev 0) +++ website/application/modules/acm/models/Table/UsersStats.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,7 @@ +<?php + +class Table_UsersStats extends Ostacium_Db_Table +{ + protected $_name = 'usersstats'; + protected $_primaty = 'username'; +} \ No newline at end of file Modified: website/application/modules/acm/models/Tester.php =================================================================== --- website/application/modules/acm/models/Tester.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/models/Tester.php 2009-01-31 20:38:09 UTC (rev 465) @@ -4,24 +4,35 @@ { public function getSubmits() { - $submits = new Submits(); + $submits = new Table_Submits(); return $submits->getUntested(); } public function updateSubmit($id, $data) { - $submits = new Submits(); - return $submits->update($data, $this->_db->quoteInto('id = ? AND state = 0', $id)); + $submits = new Table_Submits(); + $submit = $submits->getNotAccepted($id); + + if ($submit['state'] != 0) + return false; + + $submit = $data + $submit; + $submits->update($data, $this->_db->quoteInto('id = ? AND state = 0', $id)); + + if ($submit['aced'] == 1) + return false; + + if ($submit['contestid'] != 0) + { + $contest = new Contest(new Calc_ACM()); + $contest->updateResults($submit); + } + else + { + $archive = new Archive(); + $archive->updateResults($submit); + } + + return true; } -} - -class Submits extends Ostacium_Db_Table -{ - protected $_name = 'archieve_submits'; - protected $_primary = 'id'; - - public function getUntested() - { - return $this->select()->from($this)->setIntegrityCheck(false)->joinLeft('code_languages', 'code_languages.id = archieve_submits.codelangid', array('codelang' => 'name'))->where('state = 0')->order('id ASC')->query()->fetchAll(); - } } \ No newline at end of file Modified: website/application/modules/acm/models/User.php =================================================================== --- website/application/modules/acm/models/User.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/application/modules/acm/models/User.php 2009-01-31 20:38:09 UTC (rev 465) @@ -10,13 +10,13 @@ $data['activated'] = $code; $data['password'] = md5($data['password']); - $users = new Users(); + $users = new Table_Users(); $users->insert($data); - $usersdetails = new UsersDetails(); + $usersdetails = new Table_UsersDetails(); $usersdetails->insert($data); - $usersstats = new UsersStats(); + $usersstats = new Table_UsersStats(); $usersstats->insert($data); return true; @@ -27,25 +27,13 @@ $where = $this->_db->quoteInto('username = ?', $username).' AND activated = ?'; $where = $this->_db->quoteInto($where, $code); - $users = new Users(); + $users = new Table_Users(); return $users->update(array('activated' => null), $where); } -} - -class Users extends Ostacium_Db_Table -{ - protected $_name = 'users'; - protected $_primaty = 'username'; -} - -class UsersDetails extends Ostacium_Db_Table -{ - protected $_name = 'usersdetails'; - protected $_primaty = 'username'; -} - -class UsersStats extends Ostacium_Db_Table -{ - protected $_name = 'usersstats'; - protected $_primaty = 'username'; + + public function getUser($username) + { + $users = new Table_Users(); + return $users->getUser($username); + } } \ No newline at end of file Property changes on: website/application/modules/admin/controllers ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/admin/controllers/IndexController.php =================================================================== --- website/application/modules/admin/controllers/IndexController.php (rev 0) +++ website/application/modules/admin/controllers/IndexController.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,10 @@ +<?php + +class Admin_IndexController extends Ostacium_Controller_Action +{ + public function indexAction() + { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + echo "WORKED!"; + } +} \ No newline at end of file Added: website/application/modules/admin/controllers/SettingsController.php =================================================================== --- website/application/modules/admin/controllers/SettingsController.php (rev 0) +++ website/application/modules/admin/controllers/SettingsController.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,18 @@ +<?php + +class Admin_SettingsController extends Ostacium_Controller_Action_Crud +{ + protected function _load() + { + $this->_list = array( + 'name' => array('label' => 'name', 'sort' => true, 'helper' => false, 'align' => 'center'), + 'value' => array('label' => 'value', 'sort' => true, 'helper' => false, 'align' => 'center') + ); + + /*$this->_reference = array( + array('tablename', 'tablename.field = thisname.field', array('field1', 'field2')) + );*/ + + $this->_sort = array('name' => 'ASC'); + } +} \ No newline at end of file Property changes on: website/application/modules/admin/models ___________________________________________________________________ Added: tsvn:logminsize + 5 Property changes on: website/application/modules/admin/models/Form ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/admin/models/Form/Settings.php =================================================================== --- website/application/modules/admin/models/Form/Settings.php (rev 0) +++ website/application/modules/admin/models/Form/Settings.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,56 @@ +<?php + +class Form_Settings extends Ostacium_Dojo_Form_Crud +{ + protected function fillNewFields() + { + $this->addElement('ValidationTextBox', 'name', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim', 'StringToLower'), + 'validators' => array( + array('StringLength', false, array(5, 30)), + ), + 'required' => true, + 'maxlength' => 50, + 'trim' => true, + 'lowercase' => true, + 'regExp' => '[\w]{5,50}', + 'invalidMessage' => sprintf($this->_translate->_('wordErrorBetween'), 5, 30), + 'title' => 'Name', + 'label' => 'Name:', + )); + + $this->addElement('ValidationTextBox', 'value', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim'), + 'validators' => array( + 'Alnum', + array('StringLength', false, array(0, 200)), + ), + 'required' => true, + 'trim' => true, + 'regExp' => '.{0,200}', + 'invalidMessage' => sprintf($this->_translate->_('errorBetween'), 0, 200), + 'title' => 'Value', + 'label' => 'Value:', + )); + } + + protected function fillEditFields() + { + $this->addElement('ValidationTextBox', 'value', array( + 'decorators' => $this->elementDecorators, + 'filters' => array('StringTrim'), + 'validators' => array( + 'Alnum', + array('StringLength', false, array(0, 200)), + ), + 'required' => true, + 'trim' => true, + 'regExp' => '.{0,200}', + 'invalidMessage' => sprintf($this->_translate->_('errorBetween'), 0, 200), + 'title' => 'Value', + 'label' => 'Value:', + )); + } +} \ No newline at end of file Property changes on: website/application/modules/admin/models/Table ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/application/modules/admin/models/Table/Settings.php =================================================================== --- website/application/modules/admin/models/Table/Settings.php (rev 0) +++ website/application/modules/admin/models/Table/Settings.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,6 @@ +<?php + +class Table_Settings extends Ostacium_Db_Table_Crud +{ + protected $_name = 'settings'; +} \ No newline at end of file Modified: website/library/Application.php =================================================================== --- website/library/Application.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/library/Application.php 2009-01-31 20:38:09 UTC (rev 465) @@ -92,6 +92,10 @@ // Setup Helpers Ostacium_View_Helper_Truncate::setDefault($_config->truncate->toArray()); Ostacium_View_Helper_listTable::setDefaultAttribs($_config->listtable->toArray()); + Zend_View_Helper_PaginationControl::setDefaultViewPartial($_config->paginator->file); + + // Paginator + Zend_Paginator::setDefaultScrollingStyle($_config->paginator->style); // Setup Log $this->_setupLog(); Modified: website/library/Ostacium/Acl.php =================================================================== --- website/library/Ostacium/Acl.php 2009-01-31 18:14:16 UTC (rev 464) +++ website/library/Ostacium/Acl.php 2009-01-31 20:38:09 UTC (rev 465) @@ -2,9 +2,9 @@ class Ostacium_Acl extends Zend_Acl { - protected $_resources; - protected $_roles; - protected $_rolesxresources; + protected $resources; + protected $roles; + protected $rolesxresources; protected $_idtorole; @@ -34,7 +34,7 @@ $this->addRole($r); } - $roles[$role['id']] = $role['name'] == '*' ? null : $role['name']; + $roles[$role['id']] = ($role['name'] == '*' ? null : $role['name']); $this->_idtorole[(int)$role['id']] = $role['name']; } @@ -67,5 +67,4 @@ { return (isset($this->_idtorole[$id]) ? $this->_idtorole[$id] : 'guest' ); } - } \ No newline at end of file Property changes on: website/library/Ostacium/Controller/Action ___________________________________________________________________ Added: tsvn:logminsize + 5 Added: website/library/Ostacium/Controller/Action/Crud.php =================================================================== --- website/library/Ostacium/Controller/Action/Crud.php (rev 0) +++ website/library/Ostacium/Controller/Action/Crud.php 2009-01-31 20:38:09 UTC (rev 465) @@ -0,0 +1,235 @@ +<?php + +abstract class Ostacium_Controller_Action_Crud extends Ostacium_Controller_Action +{ + protected $_table; + protected $_form; + + protected $_list = array(); + protected $_reference = array(); + protected $_sort = array(); + protected $_actions = array('edit' => 'edit', 'delete' => array('set', array('field' => 'delete', 'value' => 1))); + protected $_multiactions = array('deleteSelected' => 'delete'); + protected $_newaction = true; + + public function init() + { + parent::init(false); + + $name = ucfirst($this->getRequest()->getControllerName()); + + $this->_helper->getHelper('viewRenderer')->setNoController(true); + $scriptPath = $this->_helper->getHelper('viewRenderer')->getModuleDirectory() . '/views/scripts/crud'; + $this->view->addScriptPath($scriptPath); + + $table = 'Table_' . $name; + $form = 'Form_' . $name; + + $this->_table = new $table(); + $this->_form = new $form(); + + $this->_load(); + } + + protected function _load() {} + + protected function getSinglePrimaryKeys() + { + $primaries = (array)$this->_table->getPrimaryKeys(); + $values = array(); + + foreach ($primaries as $primary) + { + $values[$primary] = $this->_getParam($primary); + + $this->_setParam($primary, null); + if ($values[$primary] === null) return false; + } + + return array($values); + } + + protected function getMultiPrimaryKeys() + { + $post = $this->getRequest()->getPost(); + $primaries = (array)$this->_table->getPrimaryKeys(); + $primary = implode('-', $primaries); + $values = array(); + + $this->_setParam($primary, null); + + foreach ($post[$primary] as $key => $value) + { + $value = explode('-', $value); + + foreach ($primaries as $primary) + { + $values[$key][$primary] = array_shift($value); + + if ($values[$key][$primary] === null) return false; + } + } + + return $values; + } + + protected function getPrimaryKeys() + { + if ($this->getRequest()->isPost()) + { + if ($this->getRequest()->getParam('multiaction', null)) + { + $ids = $this->getMultiPrimaryKeys(); + } + else + return false; + } + else + { + $ids = $this->getSinglePrimaryKeys(); + } + } + + /************************************************************************************/ + + public function indexAction() + { + return $this->_forward('list', null, null, $this->_getAllParams()); + } + + public function listAction() + { + $sort = array($this->_getParam('sort') => $this->_getParam('by')); + if (!$sort) $sort = $this->_sort; + + $data = $this->_table->getData(array_keys($this->_list), $this->_reference, $sort); + + $paginator = Zend_Paginator::factory($data->toArray()); + $paginator->setItemCountPerPage($this->_config->crud->perpage); + $paginator->setCurrentPageNumber($this->_getParam('page')); + + $this->view->paginator = $paginator; + $this->view->sort = $sort; + $this->view->headers = $this->_list; + $this->view->actions = $this->_actions; + $this->view->multiactions = $this->_multiactions; + $this->view->newaction = $this->_newaction; + $this->view->primary = $this->_table->getPrimaryKeys(); + } + + public function newAction() + { + $this->_form->fillFields('new'); + + echo $this->_form; + } + + public function addAction() + { + $this->_form->fillFields('new'); + + if (!$this->getRequest()->isPost()) + { + return $this->_forward('new', null, null, $this->_getAllParams()); + } + + if ($this->_form->isValid($this->getRequest()->getPost())) + { + echo $this->_form; + + return; + } + + $values = $this->_form->getValues(); + $result = $this->_model->addData($values); + + if (!$result) + { + $this->_form->setDescription($this->_('crudAddError')); + echo $form; + + return; + } + else + { + return $this->_redirect($this->view->url(array('action' => 'list', 'message' => 'crudAddSuccess'))); + } + } + + public function editAction() + { + $this->_form->fillFields('edit'); + + echo $this->_form; + } + + public function updateAction() + { + $this->_form->fillFields('edit'); + $ids = $this->getSinglePrimaryKeys(); + + if (!$this->getRequest()->isPost()) + { + return $this->_forward('edit', null, null, $this->_getAllParams()); + } + + if ($this->_form->isValid($this->getRequest()->getPost())) + { + echo $this->_form; + + return; + } + + $values = $this->_form->getValues(); + $result = $this->_model->updateData($values, $ids); + + if (!$result) + { + $this->_form->setDescription($this->_('crudEditError')); + echo $form; + + return; + } + else + { + return $this->_redirect($this->view->url(array('action' => 'list', 'message' => 'crudEditSuccess'))); + } + } + + public function deleteAction() + { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + $ids = $this->getPrimaryKeys(); + + if (!$ids) + return $this->_forward('list', null, null, $this->_getAllParams()); + + $result = $this->_table->deleteData($ids); + + if (!$result) + $msg = $translate->_('crudDeleteError'); + else + $msg = sprintf($translate->_('deletedOverall'), $result, count($ids)); + + return $this->_redirect($this->view->url(array('action' => 'list', 'message' => $msg))); + } + + public function setAction() + { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + $ids = $this->getPrimaryKeys(); + +... [truncated message content] |