コード例 #1
0
ファイル: xusers.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Method is called after user data is deleted from the database
  *
  * @param   array    $user     holds the user data
  * @param   boolean  $success  true if user was succesfully stored in the database
  * @param   string   $msg      message
  * @return  boolean  True on success
  */
 public function onAfterDeleteUser($user, $success, $msg)
 {
     $xprofile = \Hubzero\User\Profile::getInstance($user['id']);
     // remove user from groups
     \Hubzero\User\Helper::removeUserFromGroups($user['id']);
     if (is_object($xprofile)) {
         $xprofile->delete();
     }
     \Hubzero\Auth\Link::delete_by_user_id($user['id']);
     // Check if quota exists for the user
     require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'quota.php';
     $quota = Components\Members\Models\Quota::all()->whereEquals('user_id', $user['id'])->row();
     if ($quota->get('id')) {
         $quota->destroy();
     }
     if ($success) {
         Event::trigger('members.onMemberAfterDelete', array($user, $success, $msg));
     }
     return true;
 }
コード例 #2
0
ファイル: middleware.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Utility method to act on a user after it has been saved.
  *
  * @param   array    $user     Holds the new user data.
  * @param   boolean  $isnew    True if a new user is stored.
  * @param   boolean  $success  True if user was succesfully stored in the database.
  * @param   string   $msg      Message.
  * @return  void
  */
 public function onUserAfterSave($user, $isnew, $success, $msg)
 {
     $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int');
     if ($userId && $success) {
         try {
             $gids = JUserHelper::getUserGroups($userId);
             $db = App::get('db');
             //
             // Quota class
             //
             require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'quota.php';
             // Check for an existing quota record
             $row = Components\Members\Models\Quota::all()->whereEquals('user_id', $userId)->row();
             $row->set('user_id', $userId);
             // If (no quota record OR a record and a quota class [e.g., not custom]) ...
             if (!$row->get('id') || $row->get('id') && $row->get('class_id')) {
                 $val = array('hard_files' => 0, 'soft_files' => 0, 'hard_blocks' => 0, 'soft_blocks' => 0);
                 $db->setQuery("SELECT c.* FROM `#__users_quotas_classes` AS c LEFT JOIN `#__users_quotas_classes_groups` AS g ON g.`class_id`=c.`id` WHERE g.`group_id` IN (" . implode(',', $gids) . ")");
                 $cids = $db->loadObjectList();
                 if (count($cids) <= 0) {
                     $db->setQuery("SELECT c.* FROM `#__users_quotas_classes` AS c WHERE c.`alias`=" . $db->quote('default'));
                     $cids = $db->loadObjectList();
                 }
                 // Loop through each usergroup and find the highest quota values
                 foreach ($cids as $cls) {
                     $cls->hard_blocks = intval($cls->hard_blocks);
                     $cls->soft_blocks = intval($cls->soft_blocks);
                     if ($cls->hard_blocks > $val['hard_blocks'] && $cls->soft_blocks > $val['soft_blocks']) {
                         $row->set('class_id', $cls->id);
                     }
                     //$val['hard_files']  = ($val['hard_files']  > $cls->hard_files  ?: $cls->hard_files);
                     //$val['soft_files']  = ($val['soft_files']  > $cls->soft_files  ?: $cls->soft_files);
                     $val['hard_blocks'] = $val['hard_blocks'] > $cls->hard_blocks ? $val['hard_blocks'] : $cls->hard_blocks;
                     $val['soft_blocks'] = $val['soft_blocks'] > $cls->soft_blocks ? $val['soft_blocks'] : $cls->soft_blocks;
                 }
                 $row->set('hard_files', $val['hard_files']);
                 $row->set('soft_files', $val['soft_files']);
                 $row->set('hard_blocks', $val['hard_blocks']);
                 $row->set('soft_blocks', $val['soft_blocks']);
                 if (!$row->save()) {
                     throw new Exception($row->getError());
                 }
             }
             //
             // Session limits
             //
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'sessionclass.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'preferences.php';
             $row = new \Components\Tools\Tables\Preferences($db);
             // Check for an existing quota record
             $db->setQuery("SELECT * FROM `#__users_tool_preferences` WHERE `user_id`=" . $userId);
             if ($quota = $db->loadObject()) {
                 $row->bind($quota);
             } else {
                 $row->user_id = $userId;
             }
             // If (no quota record OR a record and a quota class [e.g., not custom]) ...
             if (!$row->id || $row->id && $row->class_id) {
                 $val = array('jobs' => 0);
                 $db->setQuery("SELECT c.* FROM `#__tool_session_classes` AS c LEFT JOIN `#__tool_session_class_groups` AS g ON g.`class_id`=c.`id` WHERE g.`group_id` IN (" . implode(',', $gids) . ")");
                 $cids = $db->loadObjectList();
                 if (count($cids) <= 0) {
                     $db->setQuery("SELECT c.* FROM `#__tool_session_classes` AS c WHERE c.`alias`=" . $db->quote('default'));
                     $cids = $db->loadObjectList();
                 }
                 // Loop through each usergroup and find the highest 'jobs allowed' value
                 foreach ($cids as $cls) {
                 }
                 $cls->jobs = intval($cls->jobs);
                 if ($cls->jobs > $val['jobs']) {
                     $row->class_id = $cls->id;
                 }
                 $val['jobs'] = $val['jobs'] > $cls->jobs ? $val['jobs'] : $cls->jobs;
                 $row->jobs = $val['jobs'];
                 if (!$row->check()) {
                     throw new Exception($row->getError());
                 }
                 if (!$row->store()) {
                     throw new Exception($row->getError());
                 }
             }
         } catch (Exception $e) {
             $this->_subject->setError($e->getMessage());
             return false;
         }
     }
     return true;
 }