Ejemplo n.º 1
0
 public function treatAction()
 {
     $groupMapper = new GroupMapper();
     $userGroupMapper = new UserGroupMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('manageGroups'), array('action' => 'index'))->add($this->getTranslator()->trans('treatGroup'), array('action' => 'treat'));
         $groups = $groupMapper->getGroupById($this->getRequest()->getParam('id'));
         $this->getView()->set('groups', $groups);
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('manageGroups'), array('action' => 'index'))->add($this->getTranslator()->trans('manageNewGroup'), array('action' => 'treat'));
     }
     $userGroupList = $userGroupMapper->getGroupList();
     $this->getView()->set('userGroupList', $userGroupList);
     if ($this->getRequest()->isPost()) {
         $groupModel = new GroupModel();
         if ($this->getRequest()->getParam('id')) {
             $groupModel->setId($this->getRequest()->getParam('id'));
         }
         $groupName = trim($this->getRequest()->getPost('groupName'));
         $groupTag = trim($this->getRequest()->getPost('groupTag'));
         $groupImage = trim($this->getRequest()->getPost('groupImage'));
         $groupMember = $this->getRequest()->getPost('userGroup');
         if (empty($groupName)) {
             $this->addMessage('missingGroupName', 'danger');
         } elseif (empty($groupImage)) {
             $this->addMessage('missingGroupImage', 'danger');
         } elseif (empty($groupMember)) {
             $this->addMessage('missingGroupMember', 'danger');
         } elseif (empty($groupTag)) {
             $this->addMessage('missingGroupTag', 'danger');
         } else {
             $groupModel->setGroupMember($groupMember);
             $groupModel->setGroupName($groupName);
             $groupModel->setGroupTag($groupTag);
             $groupModel->setGroupImage($groupImage);
             $groupMapper->save($groupModel);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Inserts or updates group entry.
  *
  * @param GroupModel $model
  */
 public function save(GroupModel $model)
 {
     $fields = array('name' => $model->getGroupName(), 'tag' => $model->getGroupTag(), 'image' => $model->getGroupImage(), 'member' => $model->getGroupMember());
     if ($model->getId()) {
         $this->db()->update('war_groups')->values($fields)->where(array('id' => $model->getId()))->execute();
     } else {
         $this->db()->insert('war_groups')->values($fields)->execute();
     }
 }