public function GetMembersListEnh($Limit = 5, $Offset = 0, $SortOrder, $UserField)
 {
     $RoleAction = $RoleActionID = "";
     $RemoveRoleArray = C('Plugins.MembersListEnh.RoleID');
     if (isset($RemoveRoleArray)) {
         $RoleAction = $RemoveRoleArray[0];
         $RoleActionID = $RemoveRoleArray[1];
     }
     $MembersListEnhModel = new Gdn_Model('User');
     $SQL = $MembersListEnhModel->SQL->Select('*')->From('User u')->LeftJoin('UserRole ur', 'u.UserID = ur.UserID');
     if (C('EnabledPlugins.KarmaBank') == TRUE) {
         $SQL->LeftJoin('KarmaBankBalance kb', 'u.UserID = kb.UserID');
     }
     if ($UserField != "Balance") {
         $SQL->OrderBy("u.{$UserField}", $SortOrder);
     }
     if (C('EnabledPlugins.KarmaBank') == TRUE && $UserField == "Balance") {
         $SQL->OrderBy("kb.Balance", $SortOrder);
     }
     $SQL->Where('Deleted', false);
     if ($RoleAction == "Exclude") {
         $SQL->Where('ur.RoleID<>', $RoleActionID);
     }
     if ($RoleAction == "Include") {
         $SQL->Where('ur.RoleID', $RoleActionID);
     }
     // Only show user once if in more than one role.
     $SQL->GroupBy('ur.UserID');
     $Sender->UserData = $SQL->Limit($Limit, $Offset)->Get();
     RoleModel::SetUserRoles($Sender->UserData->Result());
     return $Sender->UserData;
 }
   public function Index($Keywords = '', $Page = '') {
      $this->Permission(
         array(
            'Garden.Users.Add',
            'Garden.Users.Edit',
            'Garden.Users.Delete'
         ),
         '',
         FALSE
      );
      $this->AddJsFile('jquery.gardenmorepager.js');
      $this->AddJsFile('user.js');
      $this->Title(T('Users'));

      $this->AddSideMenu('dashboard/user');

      $this->Form->Method = 'get';

      // Input Validation.
      list($Offset, $Limit) = OffsetLimit($Page, PagerModule::$DefaultPageSize);
      if (!$Keywords) {
         $Keywords = $this->Form->GetFormValue('Keywords');
         if ($Keywords)
            $Offset = 0;
      }

      // Put the Keyword back in the form
      if ($Keywords)
         $this->Form->SetFormValue('Keywords', $Keywords);

      $UserModel = new UserModel();
      //$Like = trim($Keywords) == '' ? FALSE : array('u.Name' => $Keywords, 'u.Email' => $Keywords);
      list($Offset, $Limit) = OffsetLimit($Page, 30);

      $Filter = $this->_GetFilter();
      if ($Filter)
         $Filter['Keywords'] = $Keywords;
      else
         $Filter = $Keywords;

      $this->SetData('RecordCount', $UserModel->SearchCount($Filter));
      $this->UserData = $UserModel->Search($Filter, 'u.Name', 'asc', $Limit, $Offset);
      RoleModel::SetUserRoles($this->UserData->Result());
      
      // Deliver json data if necessary
      if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'users';
      }

      $this->Render();
   }
 public function PostController_Render_Before($Sender)
 {
     $Data = $Sender->Data('Comments');
     if (is_object($Data)) {
         RoleModel::SetUserRoles($Data->Result(), 'InsertUserID');
     }
 }
 /**
  * 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->addSideMenu('dashboard/user');
     // 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();
     //$Like = trim($Keywords) == '' ? FALSE : array('u.Name' => $Keywords, 'u.Email' => $Keywords);
     list($Offset, $Limit) = offsetLimit($Page, 30);
     $Filter = $this->_GetFilter();
     if ($Filter) {
         $Filter['Keywords'] = $Keywords;
     } else {
         $Filter = array('Keywords' => (string) $Keywords);
     }
     $Filter['Optimize'] = $this->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);
     if ($this->PastUserThreshold()) {
         $this->setData('_CurrentRecords', $this->UserData->count());
     } else {
         $this->setData('RecordCount', $UserModel->SearchCount($Filter));
     }
     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();
 }