public function GetData($Limit = 20, $DiscussionID = '') { $Session = Gdn::Session(); if ($Session->IsValid()) { $DraftModel = new Gdn_DraftModel(); $this->_DraftData = $DraftModel->Get($Session->UserID, 0, $Limit, $DiscussionID); } $this->Form = $this->_Sender->Form; }
public function Index($DiscussionID = '', $Offset = '', $Limit = '') { $this->AddCssFile('vanilla.css'); $Session = Gdn::Session(); $this->AddJsFile('/js/library/jquery.resizable.js'); $this->AddJsFile('/js/library/jquery.ui.packed.js'); $this->AddJsFile('/js/library/jquery.autogrow.js'); $this->AddJsFile('/js/library/jquery.gardenmorepager.js'); $this->AddJsFile('options.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('discussion.js'); $this->AddJsFile('autosave.js'); // Load the discussion record $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0; $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE); if (!is_object($this->Discussion)) { Redirect('FileNotFound'); } // Check Permissions $this->Permission('Vanilla.Discussions.View', $this->Discussion->CategoryID); $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE); if ($this->Discussion === FALSE) { Redirect('garden/home/filenotfound'); } else { // Setup $this->Title(Format::Text($this->Discussion->Name)); // Define the query offset & limit if (!is_numeric($Limit) || $Limit < 0) { $Limit = Gdn::Config('Vanilla.Comments.PerPage', 50); } $this->Offset = $Offset; if (!is_numeric($this->Offset) || $this->Offset < 0) { // Round down to the appropriate offset based on the user's read comments & comments per page $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0; if ($CountCommentWatch > $this->Discussion->CountComments) { $CountCommentWatch = $this->Discussion->CountComments; } // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60; $this->Offset = floor($CountCommentWatch / $Limit) * $Limit; } if ($this->Offset < 0) { $this->Offset = 0; } // Make sure to set the user's discussion watch records $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments); // Load the comments $this->SetData('CommentData', $this->CommentData = $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE); // Build a pager $PagerFactory = new PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = '%1$s more comments'; $this->Pager->LessCode = '%1$s older comments'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($this->Offset, $Limit, $this->Discussion->CountComments, 'vanilla/discussion/' . $DiscussionID . '/%1$s/%2$s/' . Format::Url($this->Discussion->Name)); } // Define the form for the comment input $this->Form = Gdn::Factory('Form', 'Comment'); $this->Form->Action = Url('/vanilla/post/comment/'); $this->DiscussionID = $this->Discussion->DiscussionID; $this->Form->AddHidden('DiscussionID', $this->DiscussionID); $this->Form->AddHidden('CommentID', ''); // Retrieve & apply the draft if there is one: $DraftModel = new Gdn_DraftModel(); $Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow(); $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : ''); if ($Draft) { $this->Form->SetFormValue('Body', $Draft->Body); } // 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 = 'comments'; } // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); $this->FireEvent('BeforeDiscussionRender'); $this->Render(); }