Overview

Packages

  • None
  • Yaga

Classes

  • ActedModel
  • ActionController
  • ActionModel
  • AwardCombo
  • BadgeAwardModel
  • BadgeController
  • BadgeModel
  • BadgesController
  • BadgesModule
  • BestController
  • BestFilterModule
  • CakeDayPost
  • CommentCount
  • CommentMarathon
  • DiscussionBodyLength
  • DiscussionCategory
  • DiscussionCount
  • DiscussionPageCount
  • HasMentioned
  • HolidayVisit
  • LeaderBoardModule
  • LengthOfService
  • ManualAward
  • NecroPost
  • NewbieComment
  • PhotoExists
  • PostCount
  • PostReactions
  • QnAAnserCount
  • RankController
  • RankModel
  • ReactController
  • ReactionCount
  • ReactionModel
  • ReflexComment
  • RulesController
  • SocialConnection
  • Yaga
  • YagaController
  • YagaHooks

Interfaces

  • YagaRule
  • Overview
  • Package
  • Class
  • Tree
  • Todo
  • Download
  1: <?php if(!defined('APPLICATION')) exit();
  2: /* Copyright 2014 Zachary Doll */
  3: 
  4: /**
  5:  * This is all the frontend pages dealing with badges
  6:  *
  7:  * @since 1.0
  8:  * @package Yaga
  9:  */
 10: class BestController extends Gdn_Controller {
 11: 
 12:   /**
 13:    * The list of content the filters want to show
 14:    * @var array
 15:    */
 16:   protected $_Content = array();
 17:   
 18:   /**
 19:    * @var array These objects will be created on instantiation and available via
 20:    * $this->ObjectName
 21:    */
 22:   public $Uses = array('ActedModel');
 23: 
 24:   /**
 25:    * Initializes a frontend controller with the Best Filter, New Discussion, and
 26:    * Discussion Filter modules.
 27:    */
 28:   public function Initialize() {
 29:     parent::Initialize();
 30:     $this->Application = 'Yaga';
 31:     $this->Head = new HeadModule($this);
 32:     $this->AddJsFile('jquery.js');
 33:     $this->AddJsFile('jquery-ui.js');
 34:     $this->AddJsFile('jquery.livequery.js');
 35:     $this->AddJsFile('jquery.popup.js');
 36:     $this->AddJsFile('global.js');
 37:     $this->AddCssFile('style.css');
 38:     $this->AddCssFile('reactions.css');
 39:     $this->AddModule('BestFilterModule');
 40:     $this->AddModule('NewDiscussionModule');
 41:     $this->AddModule('DiscussionFilterModule');
 42:   }
 43: 
 44:   /**
 45:    * Default to showing the best of all time
 46:    * 
 47:    * @param int $Page What page of content should be shown
 48:    */
 49:   public function Index($Page = 0) {
 50:     list($Offset, $Limit) = $this->_TranslatePage($Page);    
 51:     $this->Title(T('Yaga.BestContent.Recent'));
 52:     $this->_Content = $this->ActedModel->GetRecent('week', $Limit, $Offset);
 53:     $this->_BuildPager($Offset, $Limit, '/best/%1$s/');
 54:     $this->SetData('ActiveFilter', 'Recent');
 55:     $this->Render('index');
 56:   }
 57:   
 58:   /**
 59:    * Get the highest scoring content from all time
 60:    *
 61:    * @param int $Page What page of content should be shown
 62:    */
 63:   public function AllTime($Page = 0) {
 64:     list($Offset, $Limit) = $this->_TranslatePage($Page); 
 65:     $this->Title(T('Yaga.BestContent.AllTime'));
 66:     $this->_Content = $this->ActedModel->GetBest(NULL, $Limit, $Offset);
 67:     $this->_BuildPager($Offset, $Limit, '/best/alltime/%1$s/');
 68:     $this->SetData('ActiveFilter', 'AllTime');
 69:     $this->Render('index');
 70:   }
 71:   
 72:   /**
 73:    * Get the latest promoted content
 74:    * 
 75:    * @param int $ID Filter on a specific action ID
 76:    * @param int $Page What page of content should be shown
 77:    */
 78:   public function Action($ID = NULL, $Page = 0) {
 79:     if(is_null($ID) || !is_numeric($ID)) {
 80:       $this->Index($Page);
 81:       return;
 82:     }
 83:     $ActionModel = Yaga::ActionModel();
 84:     $Action = $ActionModel->GetByID($ID);
 85:     if(!$Action) {
 86:       $this->Index($Page);
 87:       return;
 88:     }
 89:     
 90:     list($Offset, $Limit) = $this->_TranslatePage($Page);
 91:     $this->Title(sprintf(T('Yaga.BestContent.Action'), $Action->Name));
 92:     $this->_Content = $this->ActedModel->GetAction($ID, $Limit, $Offset);
 93:     $this->_BuildPager($Offset, $Limit, '/best/action/' . $ID . '/%1$s/');
 94:     $this->SetData('ActiveFilter', $ID);
 95:     $this->Render('index');
 96:   }
 97:   
 98:   /**
 99:    * Converts a page number to an offset and limit useful for model queries.
100:    * 
101:    * @param int $Page What page of content should be shown
102:    * @return array An array containing the offset and limit
103:    */
104:   protected function _TranslatePage($Page) {
105:     list($Offset, $Limit) = OffsetLimit($Page, C('Yaga.BestContent.PerPage'));
106:     if(!is_numeric($Offset) || $Offset < 0) {
107:       $Offset = 0;
108:     }
109:     return array($Offset, $Limit);
110:   }
111:   
112:   /**
113:    * Builds a simple more/less pager to be rendered on the page
114:    * 
115:    * @param int $Offset
116:    * @param int $Limit
117:    * @param string $Link
118:    */
119:   protected function _BuildPager($Offset, $Limit, $Link) {
120:     $PagerFactory = new Gdn_PagerFactory();
121:     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
122:     $this->Pager->MoreCode = 'More';
123:     $this->Pager->LessCode = 'Newer Content';
124:     $this->Pager->ClientID = 'Pager';
125:     $this->Pager->Configure(
126:        $Offset,
127:        $Limit,
128:        FALSE,
129:        $Link
130:     );
131:   }
132: }
133: 
Yaga API documentation generated by ApiGen 2.8.0