本文整理汇总了PHP中DiscussionModel::getSortFilterQueryString方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::getSortFilterQueryString方法的具体用法?PHP DiscussionModel::getSortFilterQueryString怎么用?PHP DiscussionModel::getSortFilterQueryString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::getSortFilterQueryString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
//.........这里部分代码省略.........
Gdn_Theme::section('DiscussionList');
// Remove score sort
DiscussionModel::removeSort('top');
// 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();
$DiscussionModel->setSort(Gdn::request()->get());
$DiscussionModel->setFilters(Gdn::request()->get());
$this->setData('Sort', $DiscussionModel->getSort());
$this->setData('Filters', $DiscussionModel->getFilters());
// 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);
// RSS should include announcements.
if ($this->SyndicationMethod !== SYNDICATION_NONE) {
$Where['Announce'] = 'all';
}
// Get Discussions
$this->DiscussionData = $DiscussionModel->getWhereRecent($where, $Limit, $Offset);
$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}');
}
$queryString = DiscussionModel::getSortFilterQueryString($DiscussionModel->getSort(), $DiscussionModel->getFilters());
$this->setData('_PagerUrl', $this->data('_PagerUrl') . $queryString);
$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);
$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();
}
示例2: getFilterDropdowns
/**
* Returns an array of dropdown menus with the data from the filters array or an array containing an empty string
* to make it safe for echoing out.
*
* @return array An array of dropdown menus or an array containing an empty string.
*/
protected function getFilterDropdowns()
{
if (!$this->filters) {
return [''];
}
$dropdowns = [];
foreach ($this->filters as $filterSet) {
// Check to see if there's a category restriction.
if ($categories = val('categories', $filterSet)) {
if (!in_array($this->categoryID, $categories)) {
continue;
}
}
$setKey = val('key', $filterSet);
$dropdown = new DropdownModule('discussions-filter-' . $setKey, val('name', $filterSet), 'discussion-filter');
// Override the trigger text?
$selectedValue = val($setKey, $this->selectedFilters);
if ($selectedValue && $selectedValue != 'none') {
$selected = val('name', $filterSet['filters'][$selectedValue]);
$dropdown->setTrigger($selected);
}
$dropdown->setView($this->dropdownView);
$dropdown->setForceDivider(true);
// Adds dividers between groups in the dropdown.
// Add the filters to the dropdown
foreach (val('filters', $filterSet) as $filter) {
$key = val('group', $filter, '') . '.' . val('key', $filter);
$queryString = DiscussionModel::getSortFilterQueryString($this->selectedSort, $this->selectedFilters, '', [$setKey => val('key', $filter)]);
$pathAndQuery = $this->getPagelessPath() . $queryString;
if (empty($pathAndQuery)) {
$pathAndQuery = '/';
}
$url = url($pathAndQuery);
$dropdown->addLink(val('name', $filter), $url, $key, '', array(), false, array('rel' => 'nofollow'));
}
$dropdowns[] = $dropdown;
}
return $dropdowns;
}
示例3: index
//.........这里部分代码省略.........
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();
$DiscussionModel->setSort(Gdn::request()->get());
$DiscussionModel->setFilters(Gdn::request()->get());
$this->setData('Sort', $DiscussionModel->getSort());
$this->setData('Filters', $DiscussionModel->getFilters());
$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->getWhereRecent($Wheres, $Limit, $Offset));
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$url = CategoryUrl($CategoryIdentifier);
$this->EventArguments['PagerType'] = 'Pager';
$this->fireEvent('BeforeBuildPager');
if (!$this->data('_PagerUrl')) {
$this->setData('_PagerUrl', $url . '/{Page}');
}
$queryString = DiscussionModel::getSortFilterQueryString($DiscussionModel->getSort(), $DiscussionModel->getFilters());
$this->setData('_PagerUrl', $this->data('_PagerUrl') . $queryString);
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->configure($Offset, $Limit, $CountDiscussions, $this->data('_PagerUrl'));
$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();
}
}