Esempio n. 1
0
 /**
  * Shows a form to create or edit a new group.
  */
 public function treatAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuUser'), array('controller' => 'index', 'action' => 'index'))->add($this->getTranslator()->trans('menuGroup'), array('action' => 'index'))->add($this->getTranslator()->trans('editGroup'), array('action' => 'treat', 'id' => $this->getRequest()->getParam('id')));
     $groupId = $this->getRequest()->getParam('id');
     $groupMapper = new GroupMapper();
     if ($groupMapper->groupWithIdExists($groupId)) {
         $group = $groupMapper->getGroupById($groupId);
     } else {
         $group = new GroupModel();
     }
     $this->getView()->set('group', $group);
     $this->getView()->set('groupList', $groupMapper->getGroupList());
 }
Esempio n. 2
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'));
         }
     }
 }
Esempio n. 3
0
 /**
  * Shows a table with all groups.
  */
 public function indexAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuAccess'), array('action' => 'index'));
     $postData = $this->getRequest()->getPost();
     $groupMapper = new GroupMapper();
     $groups = $groupMapper->getGroupList();
     $this->getView()->set('activeGroupId', 0);
     $this->getView()->set('activeGroup', null);
     foreach ($groups as $key => $group) {
         if ($group->getId() == 1) {
             unset($groups[$key]);
         }
     }
     $this->getView()->set('groups', $groups);
     if (isset($postData['groupId'])) {
         $groupId = (int) $postData['groupId'];
         $_SESSION['user']['accessGroup'] = $groupId;
     } elseif (isset($_SESSION['user']['accessGroup'])) {
         $groupId = (int) $_SESSION['user']['accessGroup'];
     } else {
         $groupId = 0;
     }
     if ($groupId) {
         $groupAccessList = $groupMapper->getGroupAccessList($groupId);
         $activeGroup = $groupMapper->getGroupById($groupId);
         $this->getView()->set('groupAccessList', $groupAccessList);
         $this->getView()->set('activeGroupId', $groupId);
         $this->getView()->set('activeGroup', $activeGroup);
     }
     $moduleMapper = new ModuleMapper();
     $modules = $moduleMapper->getModules();
     $pageMapper = new PageMapper();
     $pages = $pageMapper->getPageList();
     $articleMapper = new ArticleMapper();
     $articles = $articleMapper->getArticles();
     $boxMapper = new BoxMapper();
     $boxes = $boxMapper->getBoxList($this->getTranslator()->getLocale());
     $accessTypes = array('module' => $modules, 'page' => $pages, 'article' => $articles, 'box' => $boxes);
     $this->getView()->set('accessTypes', $accessTypes);
 }
Esempio n. 4
0
 /**
  * Shows a form to create or edit a new user.
  */
 public function treatAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuUser'), array('action' => 'index'))->add($this->getTranslator()->trans('editUser'), array('action' => 'treat'));
     $userMapper = new UserMapper();
     if ($this->getRequest()->isPost()) {
         $userData = $this->getRequest()->getPost('user');
         if (!empty($userData['password'])) {
             $userData['password'] = (new PasswordService())->hash($userData['password']);
         }
         $user = $userMapper->loadFromArray($userData);
         if (!empty($userData['groups'])) {
             foreach ($userData['groups'] as $groupId) {
                 $group = new GroupModel();
                 $group->setId($groupId);
                 $user->addGroup($group);
             }
         }
         $date = new \Ilch\Date();
         $user->setDateCreated($date);
         $userId = $userMapper->save($user);
         if (!empty($userId) && empty($userData['id'])) {
             $this->addMessage('newUserMsg');
         }
     }
     if (empty($userId)) {
         $userId = $this->getRequest()->getParam('id');
     }
     if ($userMapper->userWithIdExists($userId)) {
         $user = $userMapper->getUserById($userId);
     } else {
         $user = new UserModel();
     }
     $groupMapper = new GroupMapper();
     $this->getView()->set('user', $user);
     $this->getView()->set('groupList', $groupMapper->getGroupList());
 }
Esempio n. 5
0
 public function indexAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('forum'), array('action' => 'index'));
     $forumMapper = new ForumMapper();
     $userGroupMapper = new UserGroupMapper();
     /*
      * Saves the item tree to database.
      */
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getPost('save')) {
             $sortItems = json_decode($this->getRequest()->getPost('hiddenMenu'));
             $items = $this->getRequest()->getPost('items');
             $oldItems = $forumMapper->getForumItems(1);
             /*
              * Deletes old entries from database.
              */
             if (!empty($oldItems)) {
                 foreach ($oldItems as $oldItem) {
                     if (!isset($items[$oldItem->getId()])) {
                         $forumMapper->deleteItem($oldItem);
                     }
                 }
             }
             if ($items) {
                 $sortArray = array();
                 foreach ($sortItems as $sortItem) {
                     if ($sortItem->item_id !== null) {
                         $sortArray[$sortItem->item_id] = (int) $sortItem->parent_id;
                     }
                 }
                 foreach ($items as $item) {
                     $forumItem = new \Modules\Forum\Models\ForumItem();
                     if (strpos($item['id'], 'tmp_') !== false) {
                         $tmpId = str_replace('tmp_', '', $item['id']);
                     } else {
                         $forumItem->setId($item['id']);
                     }
                     $forumItem->setForumId(1);
                     $forumItem->setType($item['type']);
                     $forumItem->setTitle($item['title']);
                     $forumItem->setDesc($item['desc']);
                     $forumItem->setReadAccess($item['readAccess']);
                     $forumItem->setReplayAccess($item['replayAccess']);
                     $forumItem->setCreateAccess($item['createAccess']);
                     $newId = $forumMapper->saveItem($forumItem);
                     if (isset($tmpId)) {
                         foreach ($sortArray as $id => $parentId) {
                             if ($id == $tmpId) {
                                 unset($sortArray[$id]);
                                 $sortArray[$newId] = $parentId;
                             }
                             if ($parentId == $tmpId) {
                                 $sortArray[$id] = $newId;
                             }
                         }
                     }
                 }
                 $sort = 0;
                 foreach ($sortArray as $id => $parent) {
                     $forumItem = new \Modules\Forum\Models\ForumItem();
                     $forumItem->setId($id);
                     $forumItem->setSort($sort);
                     $forumItem->setParentId($parent);
                     $forumMapper->saveItem($forumItem);
                     $sort += 10;
                 }
             }
         }
         $this->addMessage('saveSuccess');
         $this->redirect(array('action' => 'index'));
     }
     $forumItems = $forumMapper->getForumItemsByParent(1, 0);
     $this->getView()->set('forumItems', $forumItems);
     $this->getView()->set('forumMapper', $forumMapper);
     $userGroupList = $userGroupMapper->getGroupList();
     $this->getView()->set('userGroupList', $userGroupList);
 }