setUserRoles() 공개 정적인 메소드

public static setUserRoles ( &$Users, string $UserIDColumn = 'UserID', string $RolesColumn = 'Roles' )
$Users
$UserIDColumn string
$RolesColumn string
예제 #1
0
 /**
  * User management list.
  *
  * @since 2.0.0
  * @access public
  * @param mixed $Keywords Term or array of terms to filter list of users.
  * @param int $Page Page number.
  * @param string $Order Sort order for list.
  */
 public function index($Keywords = '', $Page = '', $Order = '')
 {
     $this->permission(array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'), '', false);
     // Page setup
     $this->addJsFile('jquery.gardenmorepager.js');
     $this->addJsFile('user.js');
     $this->title(t('Users'));
     $this->setHighlightRoute('dashboard/user');
     Gdn_Theme::section('Moderation');
     // Form setup
     $this->Form->Method = 'get';
     // Input Validation.
     list($Offset, $Limit) = offsetLimit($Page, PagerModule::$DefaultPageSize);
     if (!$Keywords) {
         $Keywords = $this->Form->getFormValue('Keywords');
         if ($Keywords) {
             $Offset = 0;
         }
     }
     if (!is_string($Keywords)) {
         $Keywords = '';
     }
     // Put the Keyword back in the form
     if ($Keywords) {
         $this->Form->setFormValue('Keywords', $Keywords);
     }
     $UserModel = new UserModel();
     list($Offset, $Limit) = offsetLimit($Page, 30);
     // Determine our data filters.
     $Filter = $this->_getFilter();
     if ($Filter) {
         $Filter['Keywords'] = $Keywords;
     } else {
         $Filter = array('Keywords' => (string) $Keywords);
     }
     $Filter['Optimize'] = Gdn::userModel()->pastUserThreshold();
     // Sorting
     if (in_array($Order, array('DateInserted', 'DateFirstVisit', 'DateLastActive'))) {
         $Order = 'u.' . $Order;
         $OrderDir = 'desc';
     } else {
         $Order = 'u.Name';
         $OrderDir = 'asc';
     }
     // Get user list
     $this->UserData = $UserModel->search($Filter, $Order, $OrderDir, $Limit, $Offset);
     $this->setData('Users', $this->UserData);
     // Figure out our number of results and users.
     $showUserCount = $this->UserData->count();
     if (!Gdn::userModel()->pastUserThreshold()) {
         // Pfft, query that sucker however you want.
         $this->setData('RecordCount', $UserModel->searchCount($Filter));
     } else {
         // We have a user search, so at least set enough data for the Next pager.
         if ($showUserCount) {
             $this->setData('_CurrentRecords', $showUserCount);
         } else {
             // No search was done. Just give the total users overall. First, zero-out our pager.
             $this->setData('_CurrentRecords', 0);
             if (!Gdn::userModel()->pastUserMegaThreshold()) {
                 // Restoring this semi-optimized counter is our compromise to let non-mega sites know their exact total users.
                 $this->setData('UserCount', $UserModel->getCount());
             } else {
                 // Dang, yo. Get a table status guess instead of really counting.
                 $this->setData('UserEstimate', Gdn::userModel()->countEstimate());
             }
         }
     }
     // Add roles to the user data.
     RoleModel::setUserRoles($this->UserData->result());
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
         $this->View = 'users';
     }
     $this->render();
 }
예제 #2
0
 /**
  *
  * @param PostController $sender Sending controller instance.
  * @param array $args Event arguments.
  */
 public function postController_render_before($sender, $args)
 {
     $data = $sender->data('Comments');
     if (is_object($data)) {
         RoleModel::setUserRoles($data->result(), 'InsertUserID');
     }
 }