| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 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 lmb_require('limb/cms/src/model/lmbCmsNode.class.php'); 11 12 /** 13 * abstract class AdminNodeWithObjectController. 14 * 15 * @package cms 16 * @version $Id$ 17 */ 18 abstract class AdminNodeWithObjectController extends lmbController 19 { 20 protected $_form_name = 'object_form'; 21 protected $_controller_name = ''; 22 protected $_node_class_name = 'lmbCmsNode'; 23 protected $_object_class_name = ''; 24 protected $_generate_identifier = false; 25 26 protected $node = null; 27 protected $item = null; 28 29 function __construct() 30 { 31 parent :: __construct(); 32 33 if(!$this->_object_class_name || !$this->_controller_name) 34 throw new lmbException('Object class name or(and) controller name is not specified'); 35 } 36 37 function doCreate() 38 { 39 $this->node = new $this->_node_class_name(); 40 $this->item = new $this->_object_class_name(); 41 42 $this->useForm($this->_form_name); 43 $this->setFormDatasource($this->request); 44 45 if($this->request->hasPost()) 46 { 47 $this->node->setControllerName($this->_controller_name); 48 $this->node->setObject($this->item); 49 $this->item->setNode($this->node); 50 $this->_import(); 51 52 if($this->_generate_identifier || $this->request->get('auto_identifier')) 53 $this->node->setIdentifier(lmbCmsNode :: generateIdentifier($this->request->get('parent'))); 54 55 $this->_validateAndSave(true); 56 } 57 else 58 { 59 $this->_initCreateForm(); 60 } 61 } 62 63 function doEdit() 64 { 65 $this->node = lmbActiveRecord :: findById($this->_node_class_name, $this->request->getInteger('id')); 66 $this->item = $this->node->getObject(); 67 $this->useForm($this->_form_name); 68 $this->setFormDatasource($this->request); 69 70 if($this->request->hasPost()) 71 { 72 $this->_import(); 73 $this->_validateAndSave(false); 74 } 75 else 76 { 77 $this->_initEditForm(); 78 } 79 } 80 81 protected function _import() 82 { 83 $this->node->import($this->request); 84 $this->item->import($this->request); 85 } 86 87 protected function _validateAndSave($is_create = false) 88 { 89 $this->_onBeforeValidate(); 90 $this->node->validate($this->error_list); 91 $this->item->validate($this->error_list); 92 $this->_onAfterValidate(); 93 94 if($this->error_list->isValid()) 95 { 96 if($is_create) 97 $this->_onBeforeCreate(); 98 else 99 $this->_onBeforeEdit(); 100 101 $this->_onBeforeSave(); 102 $this->node->saveSkipValidation(); 103 $this->item->saveSkipValidation(); 104 $this->_onAfterSave(); 105 106 if($is_create) 107 $this->_onAfterCreate(); 108 else 109 $this->_onAfterEdit(); 110 111 $this->closePopup(); 112 } 113 } 114 115 protected function _initEditForm() 116 { 117 $this->request->merge($this->node->export()); 118 $this->request->merge($this->item->export()); 119 $this->request->set('node', $this->node); 120 $this->request->set('item', $this->item); 121 } 122 123 function performPublishCommand() 124 { 125 $this->performCommand('limb/cms/src/command/lmbCmsPublishObjectCommand', $this->_object_class_name); 126 } 127 128 function performUnpublishCommand() 129 { 130 $this->performCommand('limb/cms/src/command/lmbCmsUnpublishObjectCommand', $this->_object_class_name); 131 } 132 133 function doDelete() 134 { 135 if($this->request->hasPost()) 136 $this->_onBeforeDelete(); 137 $this->performCommand('limb/cms/src/command/lmbCmsDeleteNodeCommand'); 138 if($this->request->hasPost()) 139 $this->_onAfterDelete(); 140 } 141 142 protected function _initCreateForm() {} 143 protected function _onBeforeSave() {} 144 protected function _onAfterSave() {} 145 protected function _onBeforeCreate() {} 146 protected function _onAfterCreate() {} 147 protected function _onBeforeEdit() {} 148 protected function _onAfterEdit() {} 149 protected function _onBeforeDelete() {} 150 protected function _onAfterDelete() {} 151 protected function _onBeforeValidate() {} 152 protected function _onAfterValidate() {} 153 } 154 155 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Oct 16 04:42:25 2008 | Cross-referenced by PHPXref 0.7 |