getByUser() public method

Events: BeforeGetByUser
Since: 2.1
public getByUser ( integer $UserID, integer $Limit, integer $Offset, integer $LastDiscussionID = false, integer $WatchUserID = false ) : Gdn_DataSet
$UserID integer Which user to get discussions for.
$Limit integer Max number to get.
$Offset integer Number to skip.
$LastDiscussionID integer A hint for quicker paging.
$WatchUserID integer User to use for read/unread data.
return Gdn_DataSet SQL results.
Exemplo n.º 1
0
 /**
  * Creates virtual 'Discussions' method in ProfileController.
  *
  * @since 2.0.0
  * @package Vanilla
  *
  * @param ProfileController $Sender ProfileController.
  */
 public function profileController_discussions_create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '')
 {
     $Sender->editMode(false);
     // Tell the ProfileController what tab to load
     $Sender->getUserInfo($UserReference, $Username, $UserID);
     $Sender->_setBreadcrumbs(t('Discussions'), userUrl($Sender->User, '', 'discussions'));
     $Sender->setTabView('Discussions', 'Profile', 'Discussions', 'Vanilla');
     $Sender->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30);
     list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
     $DiscussionModel = new DiscussionModel();
     $Discussions = $DiscussionModel->getByUser($Sender->User->UserID, $Limit, $Offset, false, Gdn::session()->UserID);
     $CountDiscussions = $Offset + $DiscussionModel->LastDiscussionCount + 1;
     $Sender->DiscussionData = $Sender->setData('Discussions', $Discussions);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->Pager = $PagerFactory->getPager('MorePager', $Sender);
     $Sender->Pager->MoreCode = 'More Discussions';
     $Sender->Pager->LessCode = 'Newer Discussions';
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->configure($Offset, $Limit, $CountDiscussions, userUrl($Sender->User, '', 'discussions') . '?page={Page}');
     // Deliver JSON data if necessary
     if ($Sender->deliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
         $Sender->setJson('LessRow', $Sender->Pager->toString('less'));
         $Sender->setJson('MoreRow', $Sender->Pager->toString('more'));
         $Sender->View = 'discussions';
     }
     // Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
     $Sender->HandlerType = HANDLER_TYPE_NORMAL;
     // Do not show discussion options
     $Sender->ShowOptions = false;
     if ($Sender->Head) {
         // These pages offer only duplicate content to search engines and are a bit slow.
         $Sender->Head->addTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
     }
     // Render the ProfileController
     $Sender->render();
 }