コード例 #1
0
ファイル: roles.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Assign members to a role
  *
  * @return  void
  */
 public function delegateTask()
 {
     Request::setVar('hidemainmenu', 1);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $gid = Request::getVar('gid', '');
     $roleid = Request::getInt('roleid', 0);
     if (!$gid) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_GROUPS_MISSING_ID'), 'error');
     }
     $group = new Group();
     $group->read($gid);
     foreach ($ids as $id) {
         $model = \Components\Groups\Models\Member\Role::oneByUserAndRole((int) $id, $roleid);
         if (!$model->get('id')) {
             $model->set('roleid', $roleid);
             $model->set('uidNumber', (int) $id);
             $model->save();
         }
     }
     $this->cancelTask();
 }
コード例 #2
0
ファイル: membership.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Cancel Membership Task
  *
  * @return  void
  */
 public function cancelTask()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->loginTask(Lang::txt('COM_GROUPS_INVITE_MUST_BE_LOGGED_IN_TO_CANCEL'));
         return;
     }
     //check to make sure we have  cname
     if (!$this->cn) {
         $this->_errorHandler(400, Lang::txt('COM_GROUPS_ERROR_NO_ID'));
     }
     // Load the group page
     $this->view->group = Group::getInstance($this->cn);
     // Ensure we found the group info
     if (!$this->view->group || !$this->view->group->get('gidNumber')) {
         $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_NOT_FOUND'));
     }
     // Get the group params
     $gparams = new Registry($this->view->group->get('params'));
     // If membership is managed in seperate place disallow action
     if ($gparams->get('membership_control', 1) == 0) {
         $this->setNotification(Lang::txt('COM_GROUPS_MEMBERSHIP_MANAGED_ELSEWHERE'), 'error');
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->view->group->get('cn')));
         return;
     }
     //get request vars
     $return = strtolower(trim(Request::getVar('return', '', 'get')));
     // Remove the user from the group
     $this->view->group->remove('managers', User::get('id'));
     $this->view->group->remove('members', User::get('id'));
     $this->view->group->remove('applicants', User::get('id'));
     $this->view->group->remove('invitees', User::get('id'));
     if ($this->view->group->update() === false) {
         $this->setNotification(Lang::txt('GROUPS_ERROR_CANCEL_MEMBERSHIP_FAILED'), 'error');
     }
     // delete member roles
     require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'member' . DS . 'role.php';
     \Components\Groups\Models\Member\Role::destroyByUser(User::get('id'));
     // Log the membership cancellation
     Log::log(array('gidNumber' => $this->view->group->get('gidNumber'), 'action' => 'membership_cancelled', 'comments' => array(User::get('id'))));
     // Remove record of reason wanting to join group
     $reason = new Reason($this->database);
     $reason->deleteReason(User::get('id'), $this->view->group->get('gidNumber'));
     // Email subject
     $subject = Lang::txt('COM_GROUPS_EMAIL_MEMBERSHIP_CANCELLED_SUBJECT', $this->view->group->get('cn'));
     // Build the e-mail message
     $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'cancelled'));
     $eview->option = $this->_option;
     $eview->sitename = Config::get('sitename');
     $eview->user = User::getInstance();
     $eview->group = $this->view->group;
     $message = $eview->loadTemplate();
     $message = str_replace("\n", "\r\n", $message);
     // Get the system administrator e-mail
     $emailadmin = Config::get('mailfrom');
     // Build the "from" portion of the e-mail
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_name));
     $from['email'] = Config::get('mailfrom');
     // E-mail the administrator
     if (!Event::trigger('xmessage.onSendMessage', array('groups_cancelled_me', $subject, $message, $from, $this->view->group->get('managers'), $this->_option))) {
         $this->setError(Lang::txt('GROUPS_ERROR_EMAIL_MANAGERS_FAILED') . ' ' . $emailadmin);
     }
     // Log activity
     $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->view->group->get('cn'));
     $recipients = array(['group', $this->view->group->get('gidNumber')], ['user', User::get('id')]);
     foreach ($this->view->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'cancelled', 'scope' => 'group', 'scope_id' => $this->view->group->get('gidNumber'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_GROUP_USER_CANCELLED', '<a href="' . $url . '">' . $this->view->group->get('description') . '</a>'), 'details' => array('title' => $this->view->group->get('description'), 'url' => $url, 'cn' => $this->view->group->get('cn'), 'gidNumber' => $this->view->group->get('gidNumber'))], 'recipients' => $recipients]);
     // Action Complete. Redirect to appropriate page
     App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=groups'), Lang::txt('COM_GROUPS_INVITE_CANCEL_SUCCESS'), 'passed');
 }