/** * Highlight route and include JS, CSS, and modules used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function Initialize() { parent::Initialize(); $this->ShowOptions = TRUE; $this->Menu->HighlightRoute('/discussions'); $this->AddCssFile('vanilla.css'); $this->AddJsFile('discussions.js'); // Inform moderator of checked comments in this discussion $CheckedDiscussions = Gdn::Session()->GetAttribute('CheckedDiscussions', array()); if (count($CheckedDiscussions) > 0) { ModerationController::InformCheckedDiscussions($this); } $this->CountCommentsPerPage = C('Vanilla.Comments.PerPage', 30); $this->FireEvent('AfterInitialize'); }
/** * Add a method to the ModerationController to handle merging discussions. * @param Gdn_Controller $Sender */ public function ModerationController_MergeDiscussions_Create($Sender) { $Session = Gdn::Session(); $Sender->Form = new Gdn_Form(); $Sender->Title(T('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $Sender->SetData('DiscussionIDs', $DiscussionIDs); $CountCheckedDiscussions = count($DiscussionIDs); $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray(); $Sender->SetData('Discussions', $Discussions); // Perform the merge if ($Sender->Form->AuthenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = FALSE; $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID'); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } if ($MergeDiscussion) { $ErrorCount = 0; // Verify that the user has permission to perform the merge. $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']); if ($Category && !$Category['PermsDiscussionsEdit']) { throw PermissionException('Vanilla.Discussions.Edit'); } // Assign the comments to the new discussion record $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put(); $CommentModel = new CommentModel(); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { continue; } // Create a comment out of the discussion. $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse')); $Comment['DiscussionID'] = $MergeDiscussionID; $CommentModel->Validation->Results(TRUE); $CommentID = $CommentModel->Save($Comment); if ($CommentID) { // Move any attachments (FileUpload plugin awareness) if (class_exists('MediaModel')) { $MediaModel = new MediaModel(); $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment'); } // Delete discussion that was merged $DiscussionModel->Delete($Discussion['DiscussionID']); } else { $Sender->InformMessage($CommentModel->Validation->ResultsText()); $ErrorCount++; } } // Update counts on all affected discussions. $CommentModel->UpdateCommentCount($MergeDiscussionID); $CommentModel->RemovePageCache($MergeDiscussionID); // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($Sender); if ($ErrorCount == 0) { $Sender->RedirectUrl = Url("/discussion/{$MergeDiscussionID}/" . Gdn_Format::Url($MergeDiscussion['Name'])); } } } $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge'); }
/** * Highlight route and include JS, CSS, and modules used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function initialize() { parent::initialize(); $this->ShowOptions = true; $this->Menu->highlightRoute('/discussions'); $this->addJsFile('discussions.js'); // Inform moderator of checked comments in this discussion $CheckedDiscussions = Gdn::session()->getAttribute('CheckedDiscussions', array()); if (count($CheckedDiscussions) > 0) { ModerationController::InformCheckedDiscussions($this); } $this->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30); $this->fireEvent('AfterInitialize'); }
/** * Add a method to the ModerationController to handle merging discussions. * @param Gdn_Controller $Sender */ public function ModerationController_MergeDiscussions_Create($Sender) { $Session = Gdn::Session(); $Sender->Form = new Gdn_Form(); $Sender->Title(T('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $Sender->SetData('DiscussionIDs', $DiscussionIDs); $CountCheckedDiscussions = count($DiscussionIDs); $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray(); $Sender->SetData('Discussions', $Discussions); // Perform the merge if ($Sender->Form->AuthenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = FALSE; $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID'); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } $RedirectLink = $Sender->Form->GetFormValue('RedirectLink'); if ($MergeDiscussion) { $ErrorCount = 0; // Verify that the user has permission to perform the merge. $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']); if ($Category && !$Category['PermsDiscussionsEdit']) { throw PermissionException('Vanilla.Discussions.Edit'); } $DiscussionModel->DefineSchema(); $MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name')); // Assign the comments to the new discussion record $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put(); $CommentModel = new CommentModel(); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { continue; } // Create a comment out of the discussion. $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse')); $Comment['DiscussionID'] = $MergeDiscussionID; $CommentModel->Validation->Results(TRUE); $CommentID = $CommentModel->Save($Comment); if ($CommentID) { // Move any attachments (FileUpload plugin awareness) if (class_exists('MediaModel')) { $MediaModel = new MediaModel(); $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment'); } if ($RedirectLink) { // The discussion needs to be changed to a moved link. $RedirectDiscussion = array('Name' => SliceString(sprintf(T('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => FormatString(T('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html'); $DiscussionModel->SetField($Discussion['DiscussionID'], $RedirectDiscussion); $CommentModel->UpdateCommentCount($Discussion['DiscussionID']); $CommentModel->RemovePageCache($Discussion['DiscussionID']); } else { // Delete discussion that was merged. $DiscussionModel->Delete($Discussion['DiscussionID']); } } else { $Sender->InformMessage($CommentModel->Validation->ResultsText()); $ErrorCount++; } } // Update counts on all affected discussions. $CommentModel->UpdateCommentCount($MergeDiscussionID); $CommentModel->RemovePageCache($MergeDiscussionID); // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($Sender); if ($ErrorCount == 0) { $Sender->JsonTarget('', '', 'Refresh'); } } } $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge'); }
/** * Add a method to the ModerationController to handle merging discussions. */ public function ModerationController_MergeDiscussions_Create($Sender) { $Session = Gdn::Session(); $Sender->Form = new Gdn_Form(); $Sender->Title(T('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) $CheckedDiscussions = array(); $DiscussionIDs = $CheckedDiscussions; $Sender->SetData('DiscussionIDs', $DiscussionIDs); $CountCheckedDiscussions = count($DiscussionIDs); $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); $DiscussionData = $DiscussionModel->GetIn($DiscussionIDs); $Sender->SetData('DiscussionData', $DiscussionData); // Perform the merge if ($Sender->Form->AuthenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = FALSE; $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID'); foreach ($DiscussionData->Result() as $Discussion) { if ($Discussion->DiscussionID == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } if ($MergeDiscussion) { // Verify that the user has permission to perform the merge $Sender->Permission('Vanilla.Discussion.Edit', TRUE, 'Category', $MergeDiscussion->CategoryID); // Assign the comments to the new discussion record $DiscussionModel->SQL ->Update('Comment') ->Set('DiscussionID', $MergeDiscussionID) ->WhereIn('DiscussionID', $DiscussionIDs) ->Put(); $CommentModel = new CommentModel(); foreach ($DiscussionIDs as $DiscussionID) { // Add a new comment to each empty discussion if ($DiscussionID != $MergeDiscussionID) { // Add a comment to each one explaining the merge $DiscussionAnchor = Anchor( Gdn_Format::Text($MergeDiscussion->Name), 'discussion/'.$MergeDiscussionID.'/'.Gdn_Format::Url($MergeDiscussion->Name) ); $CommentModel->Save(array( 'DiscussionID' => $DiscussionID, 'Body' => sprintf(T('This discussion was merged into %s'), $DiscussionAnchor) )); // Close non-merge discussions $CommentModel->SQL->Update('Discussion')->Set('Closed', '1')->Where('DiscussionID', $DiscussionID)->Put(); } // Update counts on all affected discussions $CommentModel->UpdateCommentCount($DiscussionID); $CommentModel->UpdateUserCommentCounts($DiscussionID); } // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($Sender); $Sender->RedirectUrl = Url('discussion/'.$MergeDiscussionID.'/'.Gdn_Format::Url($MergeDiscussion->Name)); } } $Sender->Render($this->GetView('mergediscussions.php')); }
/** * Highlight route and include JS, CSS, and modules used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function initialize() { parent::initialize(); $this->ShowOptions = true; $this->Menu->highlightRoute('/discussions'); $this->addJsFile('discussions.js'); // Inform moderator of checked comments in this discussion $CheckedDiscussions = Gdn::session()->getAttribute('CheckedDiscussions', array()); if (count($CheckedDiscussions) > 0) { ModerationController::InformCheckedDiscussions($this); } $this->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30); /** * The default Cache-Control header does not include no-store, which can cause issues (e.g. inaccurate unread * status or new comment counts) when users visit the discussion list via the browser's back button. The same * check is performed here as in Gdn_Controller before the Cache-Control header is added, but this value * includes the no-store specifier. */ if (Gdn::session()->isValid()) { $this->setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate'); } $this->fireEvent('AfterInitialize'); }
/** * Form to ask for the destination of the move, confirmation and permission check. */ public function ConfirmDiscussionMoves($DiscussionID = NULL) { $Session = Gdn::Session(); $this->Form = new Gdn_Form(); $DiscussionModel = new DiscussionModel(); $this->Title(T('Confirm')); if ($DiscussionID) { $CheckedDiscussions = (array) $DiscussionID; $ClearSelection = FALSE; } else { $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $ClearSelection = TRUE; } $DiscussionIDs = $CheckedDiscussions; $CountCheckedDiscussions = count($DiscussionIDs); $this->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); // Check for edit permissions on each discussion $AllowedDiscussions = array(); $DiscussionData = $DiscussionModel->SQL->Select('DiscussionID, Name, DateLastComment, CategoryID')->From('Discussion')->WhereIn('DiscussionID', $DiscussionIDs)->Get(); $DiscussionData = Gdn_DataSet::Index($DiscussionData->ResultArray(), array('DiscussionID')); foreach ($DiscussionData as $DiscussionID => $Discussion) { $Category = CategoryModel::Categories($Discussion['CategoryID']); if ($Category && $Category['PermsDiscussionsEdit']) { $AllowedDiscussions[] = $DiscussionID; } } $this->SetData('CountAllowed', count($AllowedDiscussions)); $CountNotAllowed = $CountCheckedDiscussions - count($AllowedDiscussions); $this->SetData('CountNotAllowed', $CountNotAllowed); if ($this->Form->AuthenticatedPostBack()) { // Retrieve the category id $CategoryID = $this->Form->GetFormValue('CategoryID'); $Category = CategoryModel::Categories($CategoryID); $RedirectLink = $this->Form->GetFormValue('RedirectLink'); // User must have add permission on the target category if (!$Category['PermsDiscussionsAdd']) { throw ForbiddenException('@' . T('You do not have permission to add discussions to this category.')); } // Iterate and move. foreach ($AllowedDiscussions as $DiscussionID) { // Create the shadow redirect. if ($RedirectLink) { $Discussion = GetValue($DiscussionID, $DiscussionData); $DiscussionModel->DefineSchema(); $MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name')); $RedirectDiscussion = array('Name' => SliceString(sprintf(T('Moved: %s'), $Discussion['Name']), $MaxNameLength), 'DateInserted' => $Discussion['DateLastComment'], 'Type' => 'redirect', 'CategoryID' => $Discussion['CategoryID'], 'Body' => FormatString(T('This discussion has been <a href="{url,html}">moved</a>.'), array('url' => DiscussionUrl($Discussion))), 'Format' => 'Html', 'Closed' => TRUE); $RedirectID = $DiscussionModel->Save($RedirectDiscussion); if (!$RedirectID) { $this->Form->SetValidationResults($DiscussionModel->ValidationResults()); break; } } $DiscussionModel->SetField($DiscussionID, 'CategoryID', $CategoryID); } // Clear selections. if ($ClearSelection) { Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($this); } if ($this->Form->ErrorCount() == 0) { $this->JsonTarget('', '', 'Refresh'); } } $this->Render(); }
/** * Form to ask for the destination of the move, confirmation and permission check. */ public function confirmDiscussionMoves($DiscussionID = null) { $Session = Gdn::session(); $this->Form = new Gdn_Form(); $DiscussionModel = new DiscussionModel(); $CategoryModel = new CategoryModel(); $this->title(t('Confirm')); if ($DiscussionID) { $CheckedDiscussions = (array) $DiscussionID; $ClearSelection = false; } else { $CheckedDiscussions = Gdn::userModel()->getAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $ClearSelection = true; } $DiscussionIDs = $CheckedDiscussions; $CountCheckedDiscussions = count($DiscussionIDs); $this->setData('CountCheckedDiscussions', $CountCheckedDiscussions); // Check for edit permissions on each discussion $AllowedDiscussions = array(); $DiscussionData = $DiscussionModel->SQL->select('DiscussionID, Name, DateLastComment, CategoryID, CountComments')->from('Discussion')->whereIn('DiscussionID', $DiscussionIDs)->get(); $DiscussionData = Gdn_DataSet::Index($DiscussionData->resultArray(), array('DiscussionID')); foreach ($DiscussionData as $DiscussionID => $Discussion) { $Category = CategoryModel::categories($Discussion['CategoryID']); if ($Category && $Category['PermsDiscussionsEdit']) { $AllowedDiscussions[] = $DiscussionID; } } $this->setData('CountAllowed', count($AllowedDiscussions)); $CountNotAllowed = $CountCheckedDiscussions - count($AllowedDiscussions); $this->setData('CountNotAllowed', $CountNotAllowed); if ($this->Form->authenticatedPostBack()) { // Retrieve the category id $CategoryID = $this->Form->getFormValue('CategoryID'); $Category = CategoryModel::categories($CategoryID); $RedirectLink = $this->Form->getFormValue('RedirectLink'); // User must have add permission on the target category if (!$Category['PermsDiscussionsAdd']) { throw forbiddenException('@' . t('You do not have permission to add discussions to this category.')); } $AffectedCategories = array(); // Iterate and move. foreach ($AllowedDiscussions as $DiscussionID) { $Discussion = val($DiscussionID, $DiscussionData); // Create the shadow redirect. if ($RedirectLink) { $DiscussionModel->defineSchema(); $MaxNameLength = val('Length', $DiscussionModel->Schema->GetField('Name')); $RedirectDiscussion = array('Name' => SliceString(sprintf(t('Moved: %s'), $Discussion['Name']), $MaxNameLength), 'DateInserted' => $Discussion['DateLastComment'], 'Type' => 'redirect', 'CategoryID' => $Discussion['CategoryID'], 'Body' => formatString(t('This discussion has been <a href="{url,html}">moved</a>.'), array('url' => DiscussionUrl($Discussion))), 'Format' => 'Html', 'Closed' => true); // Pass a forced input formatter around this exception. if (c('Garden.ForceInputFormatter')) { $InputFormat = c('Garden.InputFormatter'); saveToConfig('Garden.InputFormatter', 'Html', false); } $RedirectID = $DiscussionModel->save($RedirectDiscussion); // Reset the input formatter if (c('Garden.ForceInputFormatter')) { saveToConfig('Garden.InputFormatter', $InputFormat, false); } if (!$RedirectID) { $this->Form->setValidationResults($DiscussionModel->validationResults()); break; } } $DiscussionModel->setField($DiscussionID, 'CategoryID', $CategoryID); if (!isset($AffectedCategories[$Discussion['CategoryID']])) { $AffectedCategories[$Discussion['CategoryID']] = array(-1, -$Discussion['CountComments']); } else { $AffectedCategories[$Discussion['CategoryID']][0] -= 1; $AffectedCategories[$Discussion['CategoryID']][1] -= $Discussion['CountComments']; } if (!isset($AffectedCategories[$CategoryID])) { $AffectedCategories[$CategoryID] = array(1, $Discussion['CountComments']); } else { $AffectedCategories[$CategoryID][0] += 1; $AffectedCategories[$CategoryID][1] += $Discussion['CountComments']; } } // Update recent posts and counts on all affected categories. foreach ($AffectedCategories as $CategoryID => $Counts) { $CategoryModel->SetRecentPost($CategoryID); $CategoryModel->SQL->update('Category')->set('CountDiscussions', 'CountDiscussions' . ($Counts[0] < 0 ? ' - ' : ' + ') . abs($Counts[0]), false)->set('CountComments', 'CountComments' . ($Counts[1] < 0 ? ' - ' : ' + ') . abs($Counts[1]), false)->where('CategoryID', $CategoryID)->put(); } // Clear selections. if ($ClearSelection) { Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedDiscussions', false); ModerationController::InformCheckedDiscussions($this); } if ($this->Form->errorCount() == 0) { $this->jsonTarget('', '', 'Refresh'); } } $this->render(); }
/** * Form to ask for the destination of the move, confirmation and permission check. */ public function ConfirmDiscussionMoves() { $Session = Gdn::Session(); $this->Form = new Gdn_Form(); $DiscussionModel = new DiscussionModel(); $this->Title(T('Confirm')); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $CountCheckedDiscussions = count($DiscussionIDs); $this->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); // Check for edit permissions on each discussion $AllowedDiscussions = array(); $DiscussionData = $DiscussionModel->SQL->Select('DiscussionID, CategoryID')->From('Discussion')->WhereIn('DiscussionID', $DiscussionIDs)->Get(); foreach ($DiscussionData->Result() as $Discussion) { $Category = CategoryModel::Categories($Discussion->CategoryID); if ($Category && $Category['PermsDiscussionsEdit']) { $AllowedDiscussions[] = $Discussion->DiscussionID; } } $this->SetData('CountAllowed', count($AllowedDiscussions)); $CountNotAllowed = $CountCheckedDiscussions - count($AllowedDiscussions); $this->SetData('CountNotAllowed', $CountNotAllowed); if ($this->Form->AuthenticatedPostBack()) { // Retrieve the category id $CategoryID = $this->Form->GetFormValue('CategoryID'); $Category = CategoryModel::Categories($CategoryID); // User must have add permission on the target category if (!$Category['PermsDiscussionsAdd']) { throw ForbiddenException('@' . T('You do not have permission to add discussions to this category.')); } // Iterate and move. foreach ($AllowedDiscussions as $DiscussionID) { $DiscussionModel->SetField($DiscussionID, 'CategoryID', $CategoryID); } // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($this); $this->JsonTarget('', '', 'Refresh'); } $this->Render(); }
/** * Form to confirm that the administrator wants to delete the selected * discussions (and has permission to do so). */ public function ConfirmDiscussionDeletes() { $Session = Gdn::Session(); $this->Form = new Gdn_Form(); $DiscussionModel = new DiscussionModel(); // Verify that the user has permission to perform the deletes $this->Permission('Vanilla.Comment.Delete', TRUE, 'Category', 'any'); $this->Title(T('Confirm')); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) $CheckedDiscussions = array(); $DiscussionIDs = $CheckedDiscussions; $CountCheckedDiscussions = count($DiscussionIDs); $this->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); // Check permissions on each discussion to make sure the user has permission to delete them $AllowedDiscussions = array(); $DiscussionData = $DiscussionModel->SQL->Select('DiscussionID, CategoryID')->From('Discussion')->WhereIn('DiscussionID', $DiscussionIDs)->Get(); foreach ($DiscussionData->Result() as $Discussion) { if ($Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $Discussion->CategoryID)) $AllowedDiscussions[] = $Discussion->DiscussionID; } $this->SetData('CountAllowed', count($AllowedDiscussions)); $CountNotAllowed = $CountCheckedDiscussions - count($AllowedDiscussions); $this->SetData('CountNotAllowed', $CountNotAllowed); if ($this->Form->AuthenticatedPostBack()) { // Delete the selected discussions (that the user has permission to delete). foreach ($AllowedDiscussions as $DiscussionID) { $DiscussionModel->Delete($DiscussionID); } // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($this); $this->RedirectUrl = 'discussions'; } $this->Render(); }
/** * Highlight route and include JS, CSS, and modules used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function Initialize() { parent::Initialize(); $this->ShowOptions = TRUE; $this->Menu->HighlightRoute('/discussions'); $this->AddCssFile('vanilla.css'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('discussions.js'); $this->AddJsFile('options.js'); $this->AddJsFile('jquery.gardenmorepager.js'); // Inform moderator of checked comments in this discussion $CheckedDiscussions = Gdn::Session()->GetAttribute('CheckedDiscussions', array()); if (count($CheckedDiscussions) > 0) ModerationController::InformCheckedDiscussions($this); $this->FireEvent('AfterInitialize'); }