Exemplo n.º 1
0
 /**
  * display the membership of a group
  *
  */
 public function memberslistAction()
 {
     $gid = (int) $this->request->query->get('gid', null);
     $startnum = (int) $this->request->query->get('startnum', 0);
     if (!is_numeric($startnum)) {
         throw new \InvalidArgumentException('Missing or invalid arguments');
     }
     $itemsperpage = $this->getVar('itemsperpage');
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::memberslist', '::', ACCESS_OVERVIEW));
     $group = ModUtil::apiFunc('GroupsModule', 'user', 'get', array('gid' => $gid, 'numitems' => $itemsperpage, 'startnum' => $startnum));
     if (!$group) {
         return DataUtil::formatForDisplay($this->__('Error! Could not load data.'));
     }
     $uid = UserUtil::getVar('uid');
     $typelabel = array();
     $statelabel = array();
     $groupsCommon = new CommonHelper();
     $typelabel = $groupsCommon->gtypeLabels();
     $statelabel = $groupsCommon->stateLabels();
     $group['typelbl'] = $typelabel[$group['gtype']];
     $group['statelbl'] = $statelabel[$group['state']];
     $this->view->assign('mainpage', false);
     $this->view->assign('group', $group);
     if ($group['members']) {
         $onlines = ModUtil::apiFunc('GroupsModule', 'user', 'whosonline');
         $members = array();
         foreach ($group['members'] as $userid) {
             $userinfo = UserUtil::getVars($userid['uid']);
             $isonline = false;
             if (is_array($onlines)) {
                 foreach ($onlines as $online) {
                     if ($online['uid'] == $userid['uid']) {
                         $isonline = true;
                     }
                 }
             }
             if ($isonline) {
                 $userinfo['isonline'] = 'greenled.png';
                 $userinfo['isonlinelbl'] = $this->__('on-line');
             } else {
                 $userinfo['isonline'] = 'redled.png';
                 $userinfo['isonlinelbl'] = $this->__('off-line');
             }
             $members[] = $userinfo;
         }
         // test of sorting data
         if (!empty($members)) {
             $sortAarr = array();
             foreach ($members as $res) {
                 $sortAarr[] = strtolower($res['uname']);
             }
             array_multisort($sortAarr, SORT_ASC, $members);
         }
         $this->view->assign('members', $members);
     } else {
         $this->view->assign('members', false);
     }
     if (UserUtil::isLoggedIn()) {
         $this->view->assign('ismember', ModUtil::apiFunc('GroupsModule', 'user', 'isgroupmember', array('gid' => $gid, 'uid' => $uid)));
     } else {
         $this->view->assign('ismember', false);
     }
     $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('GroupsModule', 'user', 'countgroupmembers', array('gid' => $gid)), 'itemsperpage' => $itemsperpage));
     return $this->response($this->view->fetch('groups_user_memberslist.tpl'));
 }
Exemplo n.º 2
0
 /**
  * Create a blank group and return it.
  *
  * @return AjaxResponse
  */
 public function creategroupAction()
 {
     $this->checkAjaxToken();
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::', '::', ACCESS_ADD));
     $groupsCommon = new CommonHelper();
     $typelabel = $groupsCommon->gtypeLabels();
     $statelabel = $groupsCommon->stateLabels();
     // Default values
     $obj = array('name' => '', 'gtype' => CommonHelper::GTYPE_CORE, 'state' => CommonHelper::STATE_CLOSED, 'nbumax' => 0, 'description' => '');
     $group_id = ModUtil::apiFunc('GroupsModule', 'admin', 'create', $obj);
     if ($group_id == false) {
         throw new FatalException($this->__('Error! Could not create the new group.'));
     }
     // update group's name
     $group = $this->entityManager->find('GroupsModule\\Entity\\Group', $group_id);
     $group['name'] = $this->__f('Group %s', $group_id);
     $this->entityManager->flush();
     // convert to array
     $group = $group->toArray();
     $group['statelbl'] = $statelabel[$group['state']];
     $group['gtypelbl'] = $typelabel[$group['gtype']];
     $group['membersurl'] = ModUtil::url('Groups', 'admin', 'groupmembership', array('gid' => $group_id));
     return new AjaxResponse($group);
 }
Exemplo n.º 3
0
 /**
  * Modify a group.
  *
  * This is a standard function that is called whenever an administrator
  * wishes to modify a current group item.
  *
  * @param int 'gid' the id of the group to be modified.
  * @param int 'objectid' generic object id mapped onto gid if present.
  *
  * @return string HTML output string.
  */
 public function modifyAction(array $args = array())
 {
     // Get parameters from whatever input we need.
     $gid = (int) $this->request->query->get('gid', isset($args['gid']) ? $args['gid'] : null);
     // get group
     $item = ModUtil::apiFunc('GroupsModule', 'user', 'get', array('gid' => $gid));
     if (!$item) {
         return LogUtil::registerError($this->__('Sorry! No such group found.'), 404);
     }
     // Security check
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::', $item['gid'] . '::', ACCESS_EDIT));
     // assign the item
     $this->view->assign('item', $item);
     // Setting various defines
     $groupsCommon = new CommonHelper();
     $grouptype = $groupsCommon->gtypeLabels();
     $groupstate = $groupsCommon->stateLabels();
     $this->view->assign('grouptype', $grouptype)->assign('groupstate', $groupstate);
     // Return the output that has been generated by this function
     return $this->response($this->view->fetch('Admin/modify.tpl'));
 }