1: <?php if(!defined('APPLICATION')) exit();
2:
3:
4: 5: 6: 7: 8: 9:
10: class BestController extends Gdn_Controller {
11:
12: 13: 14: 15:
16: protected $_Content = array();
17:
18: 19: 20: 21:
22: public $Uses = array('ActedModel');
23:
24: 25: 26: 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: 46: 47: 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: 60: 61: 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: 74: 75: 76: 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: 100: 101: 102: 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: 114: 115: 116: 117: 118:
119: protected function ($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: