public function Index($Offset = '0') { if ($this->Head) { $this->AddJsFile('discussions.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('options.js'); $this->Head->AddRss('/rss/' . $this->SelfUrl, $this->Head->Title()); $this->Head->Title(Translate('All Discussions')); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); $this->SetData('Category', FALSE, TRUE); $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new Gdn_DiscussionModel(); $CountDiscussions = $DiscussionModel->GetCount(); $this->SetData('CountDiscussions', $CountDiscussions); $TmpLimit = $Limit; $AnnounceData = FALSE; if ($Offset == 0) { $AnnounceData = $DiscussionModel->GetAnnouncements(); $TmpLimit = $Limit - $AnnounceData->NumRows(); if ($TmpLimit <= 0) { $TmpLimit = 1; } } $this->SetJson('Loading', $Offset . ' to ' . $TmpLimit); $this->SetData('AnnounceData', $AnnounceData, TRUE); $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $TmpLimit), TRUE); // Build a pager. $PagerFactory = new PagerFactory(); $this->Pager = $PagerFactory->GetPager('Pager', $this); $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s'); // 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 = 'discussions'; } // Set a definition of the user's current timezone from the db. jQuery // will pick this up, compare to the browser, and update the user's // timezone if necessary. $CurrentUser = Gdn::Session()->User; if (is_object($CurrentUser)) { $ClientHour = $CurrentUser->HourOffset + date('G', time()); $this->AddDefinition('SetClientHour', $ClientHour); } // Render the controller $this->Render(); }
public function Index($Offset = '0') { if ($this->Head) { $this->Head->AddScript('/applications/vanilla/js/discussions.js'); $this->Head->AddScript('/applications/vanilla/js/bookmark.js'); $this->Head->AddScript('/applications/vanilla/js/options.js'); $this->Head->AddRss('/rss/' . $this->SelfUrl, $this->Head->Title()); $this->Head->Title(Translate('All Discussions')); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); $DraftsModule = new DraftsModule($this); $DraftsModule->GetData(); $this->AddModule($DraftsModule); $this->SetData('Category', FALSE, TRUE); $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new Gdn_DiscussionModel(); $CountDiscussions = $DiscussionModel->GetCount(); $this->SetData('CountDiscussions', $CountDiscussions); $TmpLimit = $Limit; $AnnounceData = FALSE; if ($Offset == 0) { $AnnounceData = $DiscussionModel->GetAnnouncements(); $TmpLimit = $Limit - $AnnounceData->NumRows(); if ($TmpLimit <= 0) { $TmpLimit = 1; } } $this->SetJson('Loading', $Offset . ' to ' . $TmpLimit); $this->SetData('AnnounceData', $AnnounceData, TRUE); $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $TmpLimit), TRUE); // Build a pager. $PagerFactory = new PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More Discussions'; $this->Pager->LessCode = 'Newer Discussions'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s'); // 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 = 'discussions'; } // Render the controller $this->Render(); }
/** * Show all discussions in a particular category. */ public function Index($CategoryIdentifier = '', $Offset = '0') { if (!is_numeric($CategoryIdentifier)) { $Category = $this->CategoryModel->GetFullByName(urldecode($CategoryIdentifier)); } else { $Category = $this->CategoryModel->GetFull($CategoryIdentifier); } $this->SetData('Category', $Category, TRUE); if ($Category === FALSE) { return $this->All(); } $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); if ($this->Head) { $this->Head->Title($Category->Name); $this->Head->AddScript('/applications/vanilla/js/discussions.js'); $this->Head->AddScript('/applications/vanilla/js/options.js'); $this->Head->AddScript('/js/library/jquery.gardenmorepager.js'); $this->Head->AddRss('/rss/' . $this->SelfUrl, $this->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $this->SetData('CategoryID', $this->Category->CategoryID, TRUE); // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); $DraftsModule = new DraftsModule($this); $DraftsModule->GetData(); $this->AddModule($DraftsModule); $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new Gdn_DiscussionModel(); $Wheres = array('d.CategoryID' => $this->CategoryID); $this->Permission('Vanilla.Discussions.View', $this->CategoryID); $CountDiscussions = $DiscussionModel->GetCount($Wheres); $this->SetData('CountDiscussions', $CountDiscussions); $TmpLimit = $Limit; $AnnounceData = FALSE; if ($Offset == 0) { $AnnounceData = $DiscussionModel->GetAnnouncements($Wheres); $TmpLimit = $Limit - $AnnounceData->NumRows(); } $this->SetData('AnnounceData', $AnnounceData, TRUE); $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $TmpLimit, $Wheres), TRUE); // Build a pager $PagerFactory = new PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More Discussions'; $this->Pager->LessCode = 'Newer Discussions'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s'); // Change the controller name so that it knows to grab the discussion views $this->ControllerName = 'DiscussionsController'; // Pick up the discussions class $this->CssClass = 'Discussions'; // 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 = 'discussions'; } // Render the controller $this->Render(); }