Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Voting Plugin, Adding Popular week, month, etc.
silentkillzr
New
I am adding the functions, Popular Weekly, Popular Monthly, and so on to my voting plugin.
Ive got it down how to expand and create new discussion controllers, but i am not positive how to limit it to posts for the week, month, etc.
Heres my new function for the Popular this week.
Also i am having trouble with my pagers not working correctly, only displays first page, seems offset isn't working right.
public function DiscussionsController_PopularThisWeek_Create($Sender) {
// if (!C('Plugins.Voting.Enabled'))
// return;
$Sender->Title(T('Popular This Week')); // This sets title of page $Sender->Head->Title($Sender->Head->Title()); $Offset = GetValue('0', $Sender->RequestArgs, '0'); // Get rid of announcements from this view if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->AddJsFile('bookmark.js'); $Sender->AddJsFile('options.js'); $Sender->Head->AddRss($Sender->SelfUrl.'/feed.rss', $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) $Offset = 0; // Add Modules $Sender->AddModule('NewDiscussionModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); // I think this would be where i need to limit the dates somehow. $Limit = C('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new DiscussionModel(); $CountDiscussions = $DiscussionModel->GetCount(); $Sender->SetData('CountDiscussions', $CountDiscussions); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel->SQL->OrderBy('d.Score', 'desc'); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); // Or possibly right here $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure( $Offset, $Limit, $CountDiscussions, 'discussions/popular/%1$s' ); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->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()); $Sender->AddDefinition('SetClientHour', $ClientHour); } // Render the controller $Sender->View = 'index'; $Sender->Render();
}
Tagged:
0
Comments
So far ive got it to limit posts to a specific date and so on, Trying to make a function to create a date format the same as stored in the database, but 1 week earlier than the current timestamp.
Heres what i got so far:
This only works because, this date is setup as 12hr cycle, instead of 24hour. So it wont work really well.
I just need to now make a function to take that date and subtract 1 week from it, 1 day, and so on.
here's an example that you could modify.:
http://vanillaforums.org/discussion/comment/168515/#Comment_168515
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Looks like i figured out how todo it in a way.
Set it to one week, and it works lol.
Actually thats a much cleaner method, I have updated my code as follows:
This is what i finally ended up with, it makes two more tabs, so a total of 3 tabs, Popular All Time, Popular Today, And Popular This Week. Enjoy. Trying to fix the paging bug atm still.
// if (!C('Plugins.Voting.Enabled'))
// return;
// public function CategoriesController_BeforeDiscussionContent_Handler($Sender) {
// $this->DiscussionsController_BeforeDiscussionContent_Handler($Sender);
// }
/**
* Load popular discussions.
*/
public function DiscussionsController_Popular_Create($Sender) {
// if (!C('Plugins.Voting.Enabled'))
// return;
}
public function DiscussionsController_PopularThisWeek_Create($Sender) {
// if (!C('Plugins.Voting.Enabled'))
// return;
}
public function DiscussionsController_PopularToday_Create($Sender) {
// if (!C('Plugins.Voting.Enabled'))
// return;
}