/** * Filter the list of addons. * * @param string $FilterToType AddonModel::$TypesPlural and 'plugins,applications'. * @param string $Sort Order addons by popularity or recency. * @param string $Page Which page to display. */ public function browse($FilterToType = '', $Sort = '', $Page = '') { // Create a virtual type called 'apps' as a stand-in for both plugins & applications. if ($FilterToType == 'apps') { $FilterToType = 'plugins,applications'; } // Implement user prefs $Session = Gdn::session(); if ($Session->isValid()) { if ($FilterToType != '') { $Session->setPreference('Addons.FilterType', $FilterToType); } //if ($VanillaVersion != '') { $Session->setPreference('Addons.FilterVanilla', '2'); //} if ($Sort != '') { $Session->setPreference('Addons.Sort', $Sort); } $FilterToType = $Session->getPreference('Addons.FilterType', 'all'); $VanillaVersion = $Session->getPreference('Addons.FilterVanilla', '2'); $Sort = $Session->getPreference('Addons.Sort', 'recent'); } $allowedFilters = AddonModel::$TypesPlural + ['plugins,applications' => true]; if (!array_key_exists($FilterToType, $allowedFilters)) { $FilterToType = 'all'; } if ($Sort != 'popular') { $Sort = 'recent'; } if (!in_array($VanillaVersion, array('1', '2'))) { $VanillaVersion = '2'; } $this->Version = $VanillaVersion; $this->Sort = $Sort; $this->FilterChecked = 'checked'; $this->addJsFile('jquery.gardenmorepager.js'); $this->addJsFile('browse.js'); list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20)); $this->Filter = $FilterToType; if ($this->Filter == 'themes') { $Title = 'Browse Themes'; } elseif ($this->Filter == 'plugins,applications') { $Title = 'Browse Plugins & Applications'; } else { $Title = 'Browse Addons'; } $this->setData('Title', $Title); $Search = GetIncomingValue('Keywords', ''); $this->buildBrowseWheres($Search); $SortField = $Sort == 'recent' ? 'DateUpdated' : 'CountDownloads'; $ResultSet = $this->AddonModel->getWhere(false, $SortField, 'desc', $Limit, $Offset); $this->setData('Addons', $ResultSet); $this->buildBrowseWheres($Search); $NumResults = $this->AddonModel->getCount(false); $this->setData('TotalAddons', $NumResults); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $Pager = $PagerFactory->getPager('Pager', $this); $Pager->MoreCode = '›'; $Pager->LessCode = '‹'; $Pager->ClientID = 'Pager'; $Pager->configure($Offset, $Limit, $NumResults, 'addon/browse/' . $FilterToType . '/' . $Sort . '/%1$s/?Keywords=' . urlencode($Search)); $this->setData('_Pager', $Pager); if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->setJson('MoreRow', $Pager->toString('more')); } $this->addModule('AddonHelpModule'); $this->render(); }
/** * Creates addons tab ProfileController. * * @since 2.0.0 * @package Vanilla * * @param ProfileController $Sender */ public function profileController_addons_create($Sender) { $UserReference = val(0, $Sender->RequestArgs, ''); $Username = val(1, $Sender->RequestArgs, ''); // Tell the ProfileController what tab to load $Sender->getUserInfo($UserReference, $Username); $Sender->setTabView('Addons', 'Profile', 'Addon', 'Addons'); $Offset = 0; $Limit = 100; $AddonModel = new AddonModel(); $ResultSet = $AddonModel->getWhere(array('UserID' => $Sender->User->UserID), 'DateUpdated', 'desc', $Limit, $Offset); $Sender->setData('Addons', $ResultSet); $NumResults = $AddonModel->getCount(array('InsertUserID' => $Sender->User->UserID)); // Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views $Sender->HandlerType = HANDLER_TYPE_NORMAL; // Render the ProfileController $Sender->render(); }