本文整理汇总了PHP中DiscussionModel::GetAnnouncements方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::GetAnnouncements方法的具体用法?PHP DiscussionModel::GetAnnouncements怎么用?PHP DiscussionModel::GetAnnouncements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::GetAnnouncements方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Index
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');
}
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 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();
}
示例2: Index
public function Index($Offset = '0')
{
if ($this->Head) {
$this->AddJsFile('discussions.js');
$this->AddJsFile('bookmark.js');
$this->AddJsFile('js/library/jquery.menu.js');
$this->AddJsFile('options.js');
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
$this->Head->Title(T('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 DiscussionModel();
$CountDiscussions = $DiscussionModel->GetCount();
$this->SetData('CountDiscussions', $CountDiscussions);
$this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
$this->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_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();
}
示例3: Index
/**
* Default all discussions view: chronological by most recent comment.
*
* @since 2.0.0
* @access public
*
* @param int $Page Multiplied by PerPage option to determine offset.
*/
public function Index($Page = FALSE)
{
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
Gdn_Theme::Section('DiscussionList');
// Determine offset from $Page
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$Page = PageNumber($Offset, $Limit);
// Allow page manipulation
$this->EventArguments['Page'] =& $Page;
$this->EventArguments['Offset'] =& $Offset;
$this->EventArguments['Limit'] =& $Limit;
$this->FireEvent('AfterPageCalculation');
// Set canonical URL
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
// We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
$MaxPages = C('Vanilla.Discussions.MaxPages');
if ($MaxPages && $Page > $MaxPages) {
throw NotFoundException();
}
// Setup head.
if (!$this->Data('Title')) {
$Title = C('Garden.HomepageTitle');
$DefaultControllerRoute = val('Destination', Gdn::Router()->GetRoute('DefaultController'));
if ($Title && $DefaultControllerRoute == 'discussions') {
$this->Title($Title, '');
} else {
$this->Title(T('Recent Discussions'));
}
}
if (!$this->Description()) {
$this->Description(C('Garden.Description', NULL));
}
if ($this->Head) {
$this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
$this->SetData('Breadcrumbs', array(array('Name' => T('Recent Discussions'), 'Url' => '/discussions')));
// Set criteria & get discussions data
$this->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$DiscussionModel->Watching = TRUE;
// Get Discussion Count
$CountDiscussions = $DiscussionModel->GetCount();
if ($MaxPages) {
$CountDiscussions = min($MaxPages * $Limit, $CountDiscussions);
}
$this->SetData('CountDiscussions', $CountDiscussions);
// Get Announcements
$this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
// Get Discussions
$this->DiscussionData = $DiscussionModel->GetWhere(FALSE, $Offset, $Limit);
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s');
if (!$this->Data('_PagerUrl')) {
$this->SetData('_PagerUrl', 'discussions/{Page}');
}
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildPager');
// 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';
}
$this->Render();
}
示例4: Index
/**
* Default all discussions view: chronological by most recent comment.
*
* @since 2.0.0
* @access public
*
* @param int $Page Multiplied by PerPage option to determine offset.
*/
public function Index($Page = FALSE)
{
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
Gdn_Theme::Section('DiscussionList');
// Determine offset from $Page
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$Page = PageNumber($Offset, $Limit);
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
// Setup head.
if (!$this->Data('Title')) {
$Title = C('Garden.HomepageTitle');
if ($Title) {
$this->Title($Title, '');
} else {
$this->Title(T('Recent Discussions'));
}
}
if (!$this->Description()) {
$this->Description(C('Garden.Description', NULL));
}
if ($this->Head) {
$this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
$this->SetData('Breadcrumbs', array(array('Name' => T('Recent Discussions'), 'Url' => '/discussions')));
// Set criteria & get discussions data
$this->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$DiscussionModel->Watching = TRUE;
// Get Discussion Count
$CountDiscussions = $DiscussionModel->GetCount();
$this->SetData('CountDiscussions', $CountDiscussions);
// Get Announcements
$this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
// Get Discussions
$this->DiscussionData = $DiscussionModel->GetWhere(FALSE, $Offset, $Limit);
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s');
if (!$this->Data('_PagerUrl')) {
$this->SetData('_PagerUrl', 'discussions/{Page}');
}
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildPager');
// 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);
}
$this->Render();
}
示例5: Index
/**
* Default all discussions view: chronological by most recent comment.
*
* @since 2.0.0
* @access public
*
* @param int $Page Multiplied by PerPage option to determine offset.
*/
public function Index($Page = '0')
{
// Determine offset from $Page
list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Page, $Limit, TRUE, FALSE)), TRUE));
// Validate $Page
if (!is_numeric($Page) || $Page < 0) {
$Page = 0;
}
// Setup head.
if (!$this->Data('Title')) {
$this->Title(T('All Discussions'));
}
if ($this->Head) {
$this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
}
// Add modules
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
// Set criteria & get discussions data
$this->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$DiscussionModel->Watching = TRUE;
// Get Discussion Count
$CountDiscussions = $DiscussionModel->GetCount();
$this->SetData('CountDiscussions', $CountDiscussions);
// Get Announcements
$this->AnnounceData = $Page == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
// Get Discussions
$this->DiscussionData = $DiscussionModel->Get($Page, $Limit);
// var_dump($this->DiscussionData);
// die();
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Page . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Page, $Limit, $CountDiscussions, 'discussions/%1$s');
if (!$this->Data('_PagerUrl')) {
$this->SetData('_PagerUrl', 'discussions/{Page}');
}
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildPager');
// 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 default view (discussions/index.php)
$this->Render();
}
示例6: index
/**
* Default all discussions view: chronological by most recent comment.
*
* @since 2.0.0
* @access public
*
* @param int $Page Multiplied by PerPage option to determine offset.
*/
public function index($Page = false)
{
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = c('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
Gdn_Theme::section('DiscussionList');
// Check for the feed keyword.
if ($Page === 'feed' && $this->SyndicationMethod != SYNDICATION_NONE) {
$Page = 'p1';
}
// Determine offset from $Page
list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30), true);
$Page = PageNumber($Offset, $Limit);
// Allow page manipulation
$this->EventArguments['Page'] =& $Page;
$this->EventArguments['Offset'] =& $Offset;
$this->EventArguments['Limit'] =& $Limit;
$this->fireEvent('AfterPageCalculation');
// Set canonical URL
$this->canonicalUrl(url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, true, false)), true));
// We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
$MaxPages = c('Vanilla.Discussions.MaxPages');
if ($MaxPages && $Page > $MaxPages) {
throw notFoundException();
}
// Setup head.
if (!$this->data('Title')) {
$Title = c('Garden.HomepageTitle');
$DefaultControllerRoute = val('Destination', Gdn::router()->GetRoute('DefaultController'));
if ($Title && $DefaultControllerRoute == 'discussions') {
$this->title($Title, '');
} else {
$this->title(t('Recent Discussions'));
}
}
if (!$this->Description()) {
$this->Description(c('Garden.Description', null));
}
if ($this->Head) {
$this->Head->AddRss(url('/discussions/feed.rss', true), $this->Head->title());
}
// Add modules
$this->addModule('DiscussionFilterModule');
$this->addModule('NewDiscussionModule');
$this->addModule('CategoriesModule');
$this->addModule('BookmarkedModule');
$this->setData('Breadcrumbs', array(array('Name' => t('Recent Discussions'), 'Url' => '/discussions')));
// Set criteria & get discussions data
$this->setData('Category', false, true);
$DiscussionModel = new DiscussionModel();
// Check for individual categories.
$categoryIDs = $this->getCategoryIDs();
$where = array();
if ($categoryIDs) {
$where['d.CategoryID'] = CategoryModel::filterCategoryPermissions($categoryIDs);
} else {
$DiscussionModel->Watching = true;
}
// Get Discussion Count
$CountDiscussions = $DiscussionModel->getCount($where);
if ($MaxPages) {
$CountDiscussions = min($MaxPages * $Limit, $CountDiscussions);
}
$this->setData('CountDiscussions', $CountDiscussions);
// Get Announcements
$this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($where) : false;
$this->setData('Announcements', $this->AnnounceData !== false ? $this->AnnounceData : array(), true);
// Get Discussions
$this->DiscussionData = $DiscussionModel->getWhere($where, $Offset, $Limit);
$this->setData('Discussions', $this->DiscussionData, true);
$this->setJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->fireEvent('BeforeBuildPager');
if (!$this->data('_PagerUrl')) {
$this->setData('_PagerUrl', 'discussions/{Page}');
}
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->configure($Offset, $Limit, $this->data('CountDiscussions'), $this->data('_PagerUrl'));
PagerModule::Current($this->Pager);
$this->setData('_Page', $Page);
//.........这里部分代码省略.........
示例7: Index
/**
* Show all discussions in a particular category.
*
* @since 2.0.0
* @access public
*
* @param string $CategoryIdentifier Unique category slug or ID.
* @param int $Offset Number of discussions to skip.
*/
public function Index($CategoryIdentifier = '', $Page = '0')
{
if ($CategoryIdentifier == '') {
// Figure out which category layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Categories.Layout');
switch ($Layout) {
case 'mixed':
$this->View = 'discussions';
$this->Discussions();
break;
case 'table':
$this->Table();
break;
default:
$this->View = 'all';
$this->All();
break;
}
return;
} else {
Gdn_Theme::Section('DiscussionList');
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
$Category = CategoryModel::Categories($CategoryIdentifier);
if (empty($Category)) {
if ($CategoryIdentifier) {
throw NotFoundException();
}
}
$Category = (object) $Category;
Gdn_Theme::Section($Category->CssClass);
// Load the breadcrumbs.
$this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
$this->SetData('Category', $Category, TRUE);
// Load the subtree.
if (C('Vanilla.ExpandCategories')) {
$Categories = CategoryModel::GetSubtree($CategoryIdentifier);
} else {
$Categories = array($Category);
}
$this->SetData('Categories', $Categories);
// Setup head
$this->AddCssFile('vanilla.css');
$this->Menu->HighlightRoute('/discussions');
if ($this->Head) {
$this->AddJsFile('discussions.js');
$this->AddJsFile('bookmark.js');
$this->AddJsFile('options.js');
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
}
$this->Title(GetValue('Name', $Category, ''));
$this->Description(GetValue('Description', $Category), TRUE);
// Set CategoryID
$CategoryID = GetValue('CategoryID', $Category);
$this->SetData('CategoryID', $CategoryID, TRUE);
// Add modules
$this->AddModule('NewDiscussionModule');
$this->AddModule('DiscussionFilterModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
// Get a DiscussionModel
$DiscussionModel = new DiscussionModel();
$CategoryIDs = ConsolidateArrayValuesByKey($this->Data('Categories'), 'CategoryID');
$Wheres = array('d.CategoryID' => $CategoryIDs);
$this->SetData('_ShowCategoryLink', count($CategoryIDs) > 1);
// Check permission
$this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category));
// Set discussion meta data.
$this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30);
$this->FireEvent('BeforeGetDiscussions');
list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']);
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
$CountDiscussions = $DiscussionModel->GetCount($Wheres);
$this->SetData('CountDiscussions', $CountDiscussions);
$this->SetData('_Limit', $Limit);
// We don't wan't child categories in announcements.
$Wheres['d.CategoryID'] = $CategoryID;
$AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
$this->SetData('AnnounceData', $AnnounceData, TRUE);
//.........这里部分代码省略.........
示例8: index
//.........这里部分代码省略.........
}
Gdn_Theme::section('DiscussionList');
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = c('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
// Load the subtree.
$Categories = CategoryModel::GetSubtree($CategoryIdentifier, false);
$this->setData('Categories', $Categories);
// Setup head
$this->Menu->highlightRoute('/discussions');
if ($this->Head) {
$this->addJsFile('discussions.js');
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->title());
}
// Set CategoryID
$CategoryID = val('CategoryID', $Category);
$this->setData('CategoryID', $CategoryID, true);
// Add modules
$this->addModule('NewDiscussionModule');
$this->addModule('DiscussionFilterModule');
$this->addModule('CategoriesModule');
$this->addModule('BookmarkedModule');
// Get a DiscussionModel
$DiscussionModel = new DiscussionModel();
$CategoryIDs = array($CategoryID);
if (c('Vanilla.ExpandCategories')) {
$CategoryIDs = array_merge($CategoryIDs, array_column($this->data('Categories'), 'CategoryID'));
}
$Wheres = array('d.CategoryID' => $CategoryIDs);
$this->setData('_ShowCategoryLink', count($CategoryIDs) > 1);
// Check permission
$this->permission('Vanilla.Discussions.View', true, 'Category', val('PermissionCategoryID', $Category));
// Set discussion meta data.
$this->EventArguments['PerPage'] = c('Vanilla.Discussions.PerPage', 30);
$this->fireEvent('BeforeGetDiscussions');
list($Offset, $Limit) = offsetLimit($Page, $this->EventArguments['PerPage']);
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
$Page = PageNumber($Offset, $Limit);
// Allow page manipulation
$this->EventArguments['Page'] =& $Page;
$this->EventArguments['Offset'] =& $Offset;
$this->EventArguments['Limit'] =& $Limit;
$this->fireEvent('AfterPageCalculation');
// We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
$MaxPages = c('Vanilla.Categories.MaxPages');
if ($MaxPages && $Page > $MaxPages) {
throw notFoundException();
}
$CountDiscussions = $DiscussionModel->getCount($Wheres);
if ($MaxPages && $MaxPages * $Limit < $CountDiscussions) {
$CountDiscussions = $MaxPages * $Limit;
}
$this->setData('CountDiscussions', $CountDiscussions);
$this->setData('_Limit', $Limit);
// We don't wan't child categories in announcements.
$Wheres['d.CategoryID'] = $CategoryID;
$AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
$this->setData('AnnounceData', $AnnounceData, true);
$Wheres['d.CategoryID'] = $CategoryIDs;
$this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhere($Wheres, $Offset, $Limit));
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->fireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->configure($Offset, $Limit, $CountDiscussions, array('CategoryUrl'));
$this->Pager->Record = $Category;
PagerModule::Current($this->Pager);
$this->setData('_Page', $Page);
$this->setData('_Limit', $Limit);
$this->fireEvent('AfterBuildPager');
// Set the canonical Url.
$this->canonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit)));
// Change the controller name so that it knows to grab the discussion views
$this->ControllerName = 'DiscussionsController';
// Pick up the discussions class
$this->CssClass = 'Discussions Category-' . GetValue('UrlCode', $Category);
// 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 default view.
$this->fireEvent('BeforeCategoriesRender');
$this->render();
}
}
示例9: Index
/**
* Show all discussions in a particular category.
*
* @since 2.0.0
* @access public
*
* @param string $CategoryIdentifier Unique category slug or ID.
* @param int $Offset Number of discussions to skip.
*/
public function Index($CategoryIdentifier = '', $Offset = '0')
{
list($Offset, $Limit) = OffsetLimit($Offset, C('Vanilla.Discussions.PerPage', 30));
if (!is_numeric($CategoryIdentifier)) {
$Category = $this->CategoryModel->GetFullByUrlCode(urlencode($CategoryIdentifier));
} else {
$Category = $this->CategoryModel->GetFull($CategoryIdentifier);
}
if ($Category === FALSE) {
return $this->All();
}
$this->SetData('Category', $Category, TRUE);
// Setup head
$this->AddCssFile('vanilla.css');
$this->Menu->HighlightRoute('/discussions');
if ($this->Head) {
$this->Head->Title($Category->Name);
$this->AddJsFile('discussions.js');
$this->AddJsFile('bookmark.js');
$this->AddJsFile('jquery.menu.js');
$this->AddJsFile('options.js');
$this->AddJsFile('jquery.gardenmorepager.js');
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Set CategoryID
$this->SetData('CategoryID', $this->Category->CategoryID, TRUE);
// Add modules
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$BookmarkedModule = new BookmarkedModule($this);
$BookmarkedModule->GetData();
$this->AddModule($BookmarkedModule);
// Get a DiscussionModel
$DiscussionModel = new DiscussionModel();
$Wheres = array('d.CategoryID' => $this->CategoryID);
// Check permission
$this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->CategoryID);
// Set discussion meta data
$CountDiscussions = $DiscussionModel->GetCount($Wheres);
$this->SetData('CountDiscussions', $CountDiscussions);
$AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
$this->SetData('AnnounceData', $AnnounceData, TRUE);
$this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $Limit, $Wheres), TRUE);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->Pager = $PagerFactory->GetPager('Pager', $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s');
// Set the canonical Url.
$this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE)), TRUE));
// 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 default view
$this->Render();
}
示例10: Index
/**
* Show all discussions in a particular category.
*
* @since 2.0.0
* @access public
*
* @param string $CategoryIdentifier Unique category slug or ID.
* @param int $Offset Number of discussions to skip.
*/
public function Index($CategoryIdentifier = '', $Page = '0')
{
$Category = CategoryModel::Categories($CategoryIdentifier);
if (empty($Category)) {
if ($CategoryIdentifier) {
throw NotFoundException();
}
}
$Category = (object) $Category;
// Load the breadcrumbs.
$this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
$this->SetData('Category', $Category, TRUE);
// Setup head
$this->AddCssFile('vanilla.css');
$this->Menu->HighlightRoute('/discussions');
if ($this->Head) {
$this->Head->Title(GetValue('Name', $Category, ''));
$this->AddJsFile('discussions.js');
$this->AddJsFile('bookmark.js');
$this->AddJsFile('options.js');
$this->AddJsFile('jquery.gardenmorepager.js');
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
}
// Set CategoryID
$this->SetData('CategoryID', GetValue('CategoryID', $Category), TRUE);
// Add modules
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
// Get a DiscussionModel
$DiscussionModel = new DiscussionModel();
$Wheres = array('d.CategoryID' => $this->CategoryID);
// Check permission
$this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category));
// Set discussion meta data.
$this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30);
$this->FireEvent('BeforeGetDiscussions');
list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']);
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
$CountDiscussions = $DiscussionModel->GetCount($Wheres);
$this->SetData('CountDiscussions', $CountDiscussions);
$this->SetData('_Limit', $Limit);
$AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
$this->SetData('AnnounceData', $AnnounceData, TRUE);
$this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->Get($Offset, $Limit, $Wheres));
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->Pager = $PagerFactory->GetPager('Pager', $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s');
$this->SetData('_PagerUrl', 'categories/' . rawurlencode($CategoryIdentifier) . '/{Page}');
$this->SetData('_Page', $Page);
// Set the canonical Url.
$this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
// 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 default view
$this->Render();
}
示例11: Index
/**
* Show all discussions in a particular category.
*/
public function Index($CategoryIdentifier = '', $Offset = '0')
{
$this->AddCssFile('vanilla.css');
$this->Menu->HighlightRoute('/discussions');
if ($this->Head) {
$this->Head->AddScript('/applications/vanilla/js/discussions.js');
$this->Head->AddScript('/applications/vanilla/js/options.js');
$this->Head->AddScript('/js/library/jquery.gardenmorepager.js');
}
if (!is_numeric($Offset) || $Offset < 0) {
$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->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 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();
}