From: <pan...@us...> - 2008-09-29 13:40:03
|
Revision: 394 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=394&view=rev Author: panzaboi Date: 2008-09-29 13:39:49 +0000 (Mon, 29 Sep 2008) Log Message: ----------- update Modified Paths: -------------- website/library/Ostacium/Controller/CrudAction.php Modified: website/library/Ostacium/Controller/CrudAction.php =================================================================== --- website/library/Ostacium/Controller/CrudAction.php 2008-09-28 18:32:15 UTC (rev 393) +++ website/library/Ostacium/Controller/CrudAction.php 2008-09-29 13:39:49 UTC (rev 394) @@ -6,21 +6,25 @@ protected $primary; protected $reference; - /*protected $reference = array( + /* + protected $reference = array( 'categories' => array( 'refColumns' => array('books.categoryid = categories.id'), 'columns' => array('books.name AS category'), ) - );*/ + ); + */ protected $listFields;// listFields = array( 'name' => array( 'label' => ' ) ) - protected $listActions; + protected $listActions = array( + 'edit', + 'delete' + ); protected $createFields; protected $updateFields; - /* - array( + /*array( 'decorators' => $this->elementDecorators, 'filters' => array('StringTrim', 'StringToLower'), 'validators' => array( @@ -31,10 +35,12 @@ 'tabindex' => 1, 'title' => 'Емейл', 'label' => 'Ваш емейл:', - ) - */ + )*/ - protected $generalActions; + protected $generalActions = array( + 'new', + ); + protected $defaultSort; public function init() @@ -42,7 +48,8 @@ parent::init(); // Setup Model - try { + try + { $this->_model = new Ostacium_Db_CrudTable($this->table, $this->primary, array( 'listFields' => $this->listFields, 'createFields' => $this->createFields, @@ -53,24 +60,14 @@ } catch(Exception $e){} - $scriptPath = $this->_helper->viewRenderer->getModuleDirectory() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'crud'; + $scriptPath = $this->_helper->viewRenderer->getModuleDirectory() . '/views/scripts/crud'; $this->_helper->getHelper('viewRenderer')->setNoController(true); - $this->_helper->getHelper('viewRenderer')->view->addScriptPath($scriptPath); - - if (!$this->listActions) - { - $this->listActions = array( - 'edit' => 'Редагувати', - 'delete' => 'Стерти' - ); - } + $this->view->addScriptPath($scriptPath); - if (!$this->generalActions) + if (!$this->defaultSort) { - $this->generalActions = array( - 'new' => 'Створити', - ); + $this->defaultSort = array($this->primary => 'ASC'); } } @@ -102,23 +99,24 @@ public function newAction() { $form = $this->buildForm('create'); + echo $form; - $this->view->form = $form; - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } public function createAction() { - if (!$this->getRequest()->isPost()) { + if (!$this->getRequest()->isPost()) + { return $this->_forward('new'); } $form = $this->buildForm('create'); - if (!$form->isValid($_POST)) { - $this->view->form = $form; - - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + if (!$form->isValid($_POST)) + { + echo $form; + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } $values = $form->getValues(); @@ -132,51 +130,55 @@ public function editAction() { - $id = (int)$this->_getParam($this->primary); + $id = $this->_getParam($this->primary); $values = $this->_model->getData($id); - $form = $this->buildForm('update', $this->primary . '/' . $id); - - foreach ($form->getElements() as $key => $element) - { - if (isset($values[$key])) - { - $element->setValue($values[$key]); - } - } + $form = $this->buildForm('update', array($this->primary => $id)); - $this->view->form = $form; - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + $this->beforeEdit($values, $id); + $form->populate($values); + + echo $form; + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } public function updateAction() { - $id = (int)$this->_getParam($this->primary); + $id = $this->_getParam($this->primary); - if (!$this->getRequest()->isPost()) { + if (!$this->getRequest()->isPost()) + { return $this->_forward('edit', null, null, array($this->primary => $id)); } - $form = $this->buildForm('update', $this->primary . '/' . $id); + $form = $this->buildForm('update', array($this->primary => $id)); - if (!$form->isValid($_POST)) { - $this->view->form = $form; - - return $this->_helper->getHelper('viewRenderer')->setScriptAction('form'); + if (!$form->isValid($_POST)) + { + echo $form; + return $this->_helper->getHelper('viewRenderer')->setNoRender(true); } $values = $form->getValues(); + $result = $this->_model->updateData($values, $id); + $this->afterUpdate($values, $form, $id, $result); if (!$result) { return $this->_forward('edit', null, null, array($this->primary => $id, 'message' => 'updateError')); } + else + { + return $this->_forward('list', null, null, $this->_getAllParams() + array('message' => 'recordUpdated')); + } } public function deleteAction() { - if ($this->_getParam('delete')) + $msg = $this->view->translate('deleteErrors'); + + if ($this->_getParam('delete') && count($this->_getParam('cruditems')) > 0) { $Dcount = 0; $count = 0; @@ -198,9 +200,9 @@ $msg = $this->view->translate('recordsDeleted', array($Dcount, $count)); } - else + elseif($this->_getParam($this->primary)) { - $id = (int)$this->_getParam($this->primary); + $id = $this->_getParam($this->primary); $this->beforeDelete($id); $result = $this->_model->deleteData($id); @@ -226,8 +228,7 @@ public function upAction() { - $id = (int)$this->_getParam('id'); - + $id = $this->_getParam('id'); $this->_model->up($id); return $this->_forward('list', null, null, $this->_getAllParams() + array('message' => 'recordUp')); @@ -235,8 +236,7 @@ public function downAction() { - $id = (int)$this->_getParam('id'); - + $id = $this->_getParam('id'); $this->_model->down($id); return $this->_forward('list', null, null, $this->_getAllParams() + array('message' => 'recordDown')); @@ -262,12 +262,22 @@ { } + + protected function beforeEdit(&$values, $id) + { + + } + + protected function afterUpdate(&$values, &$form, $id, $result) + { + + } /****************************/ protected function buildForm($action, $other = null) { $form = new CrudForm(); - $form->setAction( $this->getRequest()->getBaseUrl() . ($this->getRequest()->getModuleName() != 'default' ? '/' . $this->getRequest()->getModuleName() : '') . '/' . $this->getRequest()->getControllerName() . '/' . $action . ($other ? '/' . $other : '')) + $form->setAction( $this->view->url(array('module' => $this->getRequest()->getModuleName(), 'controller' => $this->getRequest()->getControllerName(), 'action' => $action) + (array)$other, false, true) ) ->setMethod('post'); foreach ($this->{$action . 'Fields'} as $field => $options) @@ -277,9 +287,10 @@ $form->addElement($options['type'], $field, $options['options']); } - $label = $this->getLabel(); + $label = $this->getLabel($action); - $form->addElement('submit', 'login', array('label' => $label)); + $form->addElement('submit', 'submit', array('label' => $label)); + $form->addElement('button', 'goback', array('label' => 'Назад', 'onclick' => 'return goTo(\'' . $this->view->url(array('module' => $this->getRequest()->getModuleName(), 'controller' => $this->getRequest()->getControllerName(), 'action' => 'index'), false, true) . '\');')); return $form; } @@ -318,57 +329,12 @@ protected function getLabel() { - $label = $this->getRequest()-> getActionName(); - - $label = (isset($this->listActions[$label]) ? $this->listActions[$label] : (isset($this->generalActions[$label]) ? $this->generalActions[$label] : ucfirst($label) ) ); + $label = $this->getRequest()->getActionName(); + //$label = (isset($this->labels[$label]) ? $this->labels[$label] : ucfirst($label)); + $label = mb_ucfirst($this->translate($label)); return $label; } - - protected function saveUploadedImage($from, $to, $maxheight, $maxwidth) - { - $newfrom = $to . '.tmp'; - move_uploaded_file($from, $newfrom); - - $from_type = exif_imagetype($newfrom); - - switch ($from_type) { - case IMAGETYPE_GIF: - $im = imagecreatefromgif($newfrom); - break; - case IMAGETYPE_JPEG: - $im = imagecreatefromjpeg($newfrom); - break; - case IMAGETYPE_PNG: - $im = imagecreatefrompng($newfrom); - break; - default: - return false; - break; - } - - $width = Imagesx($im); - $height = Imagesy($im); - - $width_alpha = $maxwidth/$width; - $height_alpha = $maxheight/$height; - - $alpha = min($width_alpha, $height_alpha); - - $newwidth = $width * $alpha; - $newheight = $height * $alpha; - - $newim = imagecreatetruecolor($newwidth, $newheight); - imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); - - imagejpeg($newim, $to . '.jpg', 100); - - imagedestroy($newim); - imagedestroy($im); - @unlink($newfrom); - - return true; - } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |