_objData['parentId']; if ($id) { if ($this->_action == 'reorder' && $parentId == 0) { $this->dataObj->itemsName = 'Sub-departments'; } else { $this->dataObj->itemsName = 'Processes'; } } $form = parent::_getReorderForm(); $form->addElement('hidden', 'itemsName', array('value' => $this->dataObj->itemsName)); return $form; } protected function _doUpdateOrder() { $form = $this->_getReorderForm(); $form->validate(); $order = $form->getValue('order'); $this->_setBackMessage($form->getValue('itemsName') . ' have been reordered'); $this->dataObj->updateOrder($order); $this->_doBack(); } protected function _initAction() { if (!$this->doc->acl->isAllowed($this->doc->getAuthData('id'), 'department', 'add')) { $this->_actions = Qs_Array::excludeValue($this->_actions, 'new'); if (Qs_Request::getGetValue('action') == 'reorder' && !Qs_Request::getGetValue('id')) { $this->_actions = Qs_Array::excludeValue($this->_actions, 'reorder'); } } $params = $this->getRestParams(); if ($this->getConfig('type') == 'landing') { if (count($params) == 1 && ctype_digit($params[0])) { $this->dataObj->setPrimaryKey($params[0]); if (null === $this->dataObj->getData()) { $this->doc->display404(); } $this->_defaultAction = 'landingView'; } else { $this->doc->display404(); } } elseif ($id = (int) Qs_Request::getGetValue('id')) { if ($this->dataObj->getData('parentId')) { $id = $this->dataObj->getData('parentId'); } if (!$this->doc->acl->isAllowed($this->doc->getAuthData('id'), App_Acl_Obj::DEPARTMENT_PREFIX . $id, App_Acl_Obj::DEPARTMENT_PRIVILEGE)) { $this->_actions = array('wideList', 'landingView'); } } if ($this->dataObj->getPrimaryKey()) { $this->doc->setTitle($this->doc->getTitle() . ' :: ' . $this->dataObj->getData('name')); } parent::_initAction(); $this->_objData = $this->dataObj->getData(); if ($this->_objData['parentId'] != 0) { $this->dataObj->itemName = 'Sub-department'; } return $this; } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); if ($data['parentId'] != 0) { $this->dataObj->itemName = 'Sub-department'; } $this->dataObj->initFromForm($data); return $this; } protected function _bindListColumns(Qs_ViewController_List $list) { $list->addColumn('no', 'No') ->addColumn('text', 'name') ->addColumn( 'options', 'options', array( 'actions' => array('edit', 'addSubDepartment', 'reorder', 'addProcess', 'delete') ) ); return $this; } protected function _doWideList() { if ($this->doc->acl->isAllowed($this->doc->getAuthData('id'), 'department', 'add')) { $this->_addLinksItem(); } $leaveEmptyDepartments = $this->doc->acl->isAllowed($this->doc->getAuthData('id'), 'department', 'add') || $this->doc->acl->isAllowed($this->doc->getAuthData('id'), 'process', 'add'); $item = $this->dataObj->getWideList(0, $leaveEmptyDepartments); $item['tpl'] = $this->getTemplate('wideList.tpl'); $item['processPageUrl'] = Qs_Sys_SiteMap::findFirst( null, array('type' => 'Process_'), array('type' => 'default'), 'url' ); $this->_addItem($item); $this->_setBackUrl(Qs_Request::getUrl(), 'process'); } protected function _doLandingView() { $item = $this->dataObj->getWideList($this->dataObj->getPrimaryKey()); if ($this->_objData['parentId']) { $data = $this->dataObj->getParentData((int) $this->_objData['parentId']); $this->doc->setHeader('Sub-Department: ' . $data['name'] . ' >> ' . $this->_objData['name']); } else { $this->doc->setHeader('Department: ' . $this->_objData['name']); } $item['tpl'] = $this->getTemplate('landingView.tpl'); $this->_addItem($item); } protected function _bindFormFields(Qs_Form $form) { $options = array(); if ($this->doc->acl->isAllowed($this->doc->getAuthData('id'), 'department', 'add')) { $options = array('0' => '-------'); } if ($this->doc->getAuthData('id') == App_Doc_Site::ADMIN_ID) { $options = $options + $this->dataObj->getDepartment4Select(array('id', 'name'), null, 'parentId = 0'); } else { $options = $options + $this->dataObj->getTopLevelDepartment($this->doc->getAuthData('id')); } $form->addElement( 'select', 'parentId', array( 'label' => 'Choose The Appropriate Department', 'value' => $this->dataObj->getPrimaryKey(), 'multiOptions' => $options ) ); $parentId = Qs_Request::getRequestValue('parentId'); $form->addElement('text', 'name', array('label' => 'Department Name', 'required' => true)); if (($this->_action == 'addSubDepartment' && !$this->dataObj->getparentIdById($this->dataObj->getPrimaryKey())) || ($this->_action == 'edit' && $this->dataObj->getParentIdById($this->dataObj->getPrimaryKey())) || (in_array($this->_action, array('insert', 'update'))&& !empty($parentId)) ) { $form->name->setDescription(App_Department_View::SUB_DEPARTMENT_DESCRIPTION); $form->name->setLabel(App_Department_View::SUB_DEPARTMENT_LABEL); } else { $form->removeElement('parentId'); } return $this; } protected function _doAddSubDepartment() { parent::_doNew(); } protected function _doDelete() { if ($this->dataObj->getChildCountByKey() || $this->dataObj->getProcessCountByKey()) { if ($this->_objData['parentId'] == 0) { $this->_setBackError(App_Department_View::NOT_ALLOWED_DELETE); } else { $this->_setBackError(App_Department_View::NOT_ALLOWED_DELETE_SUB); } $this->_doBack(); } parent::_doDelete(); } public function fillConfigForm(Qs_Form $form) { $form->addElement( 'select', 'type', array( 'label' => 'Block Type', 'multiOptions' => array( 'default' => 'Default', 'landing' => 'Landing Page' ) ) ); return $this; } }