/** * Edit a group * * @access public */ public function editAction() { $groupRow = new Admin_Model_DbRow_Group($this->dbGroups->find($this->checkGroupIdParam())); $form = new Admin_Form_Group_Edit($groupRow); $form->setAction('/noc/admin/group/edit'); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getParams())) { $groupRow->fromArray(array('name' => $this->getRequest()->getParam('name'), 'description' => $this->getRequest()->getParam('description'))); $this->dbGroups->update($groupRow->toDbArray(), $groupRow->get('id')); $this->_redirect('admin/group/index'); } else { $form->setDescription('An error occured'); } } $this->view->form = $form; }
/** * Update the group informations in the database * a * @return array */ public function saveEditGroupAction() { $params = Zend_Json_Decoder::decode($this->request->getParam('groups')); $groupModel = new Admin_Model_DbTable_Groups(); $groupRow = new Admin_Model_DbRow_Group($groupModel->find($params['id'])); $errors = array(); if (strtolower($params['name']) !== strtolower($groupRow->get('name'))) { $dubGroupRow = $groupModel->fetchRowByGroupName($params['name']); if ($dubGroupRow) { $errors[] = 'The group already exists'; } } if ($groupRow->get('id') && count($errors) === 0) { $groupRow->fromArray($params); $groupModel->update($groupRow->toDbArray(), $groupRow->get('id')); return $this->responseSuccess(array($groupRow->toDbArray())); } return $this->responseFailure('Error editing the group', $errors); }