[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/cms/src/controller/ -> AdminObjectController.class.php (source)

   1  <?php
   2  /*

   3   * Limb PHP Framework

   4   *

   5   * @link http://limb-project.com

   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)

   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html

   8   */
   9  lmb_require('limb/web_app/src/controller/lmbController.class.php');
  10  
  11  /**

  12   * abstract class AdminObjectController.

  13   *

  14   * @package cms

  15   * @version $Id$

  16   */
  17  abstract class AdminObjectController extends lmbController
  18  {
  19    protected $_form_name = 'object_form';
  20    protected $_object_class_name = '';
  21  
  22    protected $item = null;
  23  
  24    function __construct()
  25    {
  26      parent :: __construct();
  27  
  28      if(!$this->_object_class_name)
  29        throw new lmbException('Object class name is not specified');
  30    }
  31  
  32    function doCreate()
  33    {
  34      $this->item = new $this->_object_class_name();
  35  
  36      $this->useForm($this->_form_name);
  37      $this->setFormDatasource($this->item);
  38  
  39      if($this->request->hasPost())
  40      {
  41        $this->_import();
  42        $this->_validateAndSave(true);
  43      }
  44      else
  45      {
  46        $this->_initCreateForm();
  47      }
  48    }
  49  
  50    function doEdit()
  51    {
  52      $this->item = lmbActiveRecord :: findById($this->_object_class_name, $this->request->getInteger('id'));
  53      $this->useForm($this->_form_name);
  54      $this->setFormDatasource($this->item);
  55  
  56      if($this->request->hasPost())
  57      {
  58        $this->_import();
  59        $this->_validateAndSave(false);
  60      }
  61      else
  62      {
  63        $this->_initEditForm();
  64      }
  65    }
  66  
  67    protected function _import()
  68    {
  69      $this->item->import($this->request);
  70    }
  71  
  72    protected function _validateAndSave($is_create = false)
  73    {
  74      $this->_onBeforeValidate();
  75      $this->item->validate($this->error_list);
  76      $this->_onAfterValidate();
  77  
  78      if($this->error_list->isValid())
  79      {
  80        if($is_create)
  81          $this->_onBeforeCreate();
  82        else
  83          $this->_onBeforeEdit();
  84  
  85        $this->_onBeforeSave();
  86        $this->item->saveSkipValidation();
  87        $this->_onAfterSave();
  88  
  89        if($is_create)
  90          $this->_onAfterCreate();
  91        else
  92          $this->_onAfterEdit();
  93  
  94        $this->closePopup();
  95      }
  96    }
  97  
  98    protected function _initCreateForm() {}
  99    protected function _initEditForm() {}
 100    protected function _onBeforeSave() {}
 101    protected function _onAfterSave() {}
 102    protected function _onBeforeCreate() {}
 103    protected function _onAfterCreate() {}
 104    protected function _onBeforeEdit() {}
 105    protected function _onAfterEdit() {}
 106    protected function _onBeforeDelete() {}
 107    protected function _onAfterDelete() {}
 108    protected function _onBeforeValidate() {}
 109    protected function _onAfterValidate() {}
 110  
 111    function performPublishCommand()
 112    {
 113      $this->performCommand('limb/cms/src/command/lmbCmsPublishObjectCommand', $this->_object_class_name);
 114    }
 115  
 116    function performUnpublishCommand()
 117    {
 118      $this->performCommand('limb/cms/src/command/lmbCmsUnpublishObjectCommand', $this->_object_class_name);
 119    }
 120  
 121    function doDelete()
 122    {
 123      if($this->request->hasPost())
 124        $this->_onBeforeDelete();
 125      $this->performCommand('limb/cms/src/command/lmbCmsDeleteObjectCommand', $this->_object_class_name);
 126      if($this->request->hasPost())
 127        $this->_onAfterDelete();
 128    }
 129  }
 130  
 131  ?>


Generated: Fri Aug 29 04:49:26 2008 Cross-referenced by PHPXref 0.7