当前位置: 首页>>代码示例>>PHP>>正文


PHP DiscussionModel::Delete方法代码示例

本文整理汇总了PHP中DiscussionModel::Delete方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::Delete方法的具体用法?PHP DiscussionModel::Delete怎么用?PHP DiscussionModel::Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DiscussionModel的用法示例。


在下文中一共展示了DiscussionModel::Delete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Delete

 /**
  * Allows user to delete a discussion.
  *
  * This is a "hard" delete - it is removed from the database.
  * 
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function Delete($DiscussionID = '', $TransientKey = '')
 {
     $this->_DeliveryType = DELIVERY_TYPE_BOOL;
     $Session = Gdn::Session();
     $SuccessTarget = Url('/' . ltrim(GetIncomingValue('Target', '/'), '/'));
     if (is_numeric($DiscussionID) && $DiscussionID > 0 && $Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey)) {
         $Discussion = $this->DiscussionModel->GetID($DiscussionID);
         if ($Discussion && $Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
             if (!$this->DiscussionModel->Delete($DiscussionID)) {
                 $this->Form->AddError('Failed to delete discussion');
             }
         } else {
             $this->Form->AddError('ErrPermission');
         }
     } else {
         $this->Form->AddError('ErrPermission');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         Redirect($SuccessTarget);
     }
     if ($this->Form->ErrorCount() > 0) {
         $this->SetJson('ErrorMessage', $this->Form->Errors());
     }
     $this->RedirectUrl = $SuccessTarget;
     $this->Render();
 }
开发者ID:remobjects,项目名称:Garden,代码行数:38,代码来源:class.discussioncontroller.php

示例2: Delete

 /**
  * Allows user to delete a discussion.
  *
  * This is a "hard" delete - it is removed from the database.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID.
  */
 public function Delete($DiscussionID, $Target = '')
 {
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     $this->Permission('Vanilla.Discussions.Delete', TRUE, 'Category', $Discussion->PermissionCategoryID);
     if ($this->Form->AuthenticatedPostBack()) {
         if (!$this->DiscussionModel->Delete($DiscussionID)) {
             $this->Form->AddError('Failed to delete discussion');
         }
         if ($this->Form->ErrorCount() == 0) {
             if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
                 SafeRedirect($Target);
             }
             if ($Target) {
                 $this->RedirectUrl = Url($Target);
             }
             $this->JsonTarget(".Section-DiscussionList #Discussion_{$DiscussionID}", NULL, 'SlideUp');
         }
     }
     $this->SetData('Title', T('Delete Discussion'));
     $this->Render();
 }
开发者ID:srikarrohit,项目名称:Vanillaforums-SSO,代码行数:34,代码来源:class.discussioncontroller.php

示例3: ModerationController_MergeDiscussions_Create

 /**
  * 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');
 }
开发者ID:bishopb,项目名称:vanilla,代码行数:76,代码来源:class.splitmerge.plugin.php

示例4: ModerationController_MergeDiscussions_Create

 /**
  * 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');
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:87,代码来源:class.splitmerge.plugin.php

示例5: ConfirmDiscussionDeletes

 /**
  * 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.Discussions.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) {
         $PermissionCategory = CategoryModel::Categories(GetValue('CategoryID', $Discussion));
         $CountCheckedDiscussions = $DiscussionData->NumRows();
         if ($Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', GetValue('PermissionCategoryID', $PermissionCategory))) {
             $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) {
             $Deleted = $DiscussionModel->Delete($DiscussionID);
             if ($Deleted) {
                 $this->JsonTarget("#Discussion_{$DiscussionID}", '', 'SlideUp');
             }
         }
         // Clear selections
         Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', NULL);
         ModerationController::InformCheckedDiscussions($this, TRUE);
     }
     $this->Render();
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:46,代码来源:class.moderationcontroller.php

示例6: DiscussionController_VoteDiscussion_Create

 /**
  * Increment/decrement discussion scores
  */
 public function DiscussionController_VoteDiscussion_Create($Sender)
 {
     //		if (!C('Plugins.Voting.Enabled'))
     //			return;
     $DiscussionID = GetValue(0, $Sender->RequestArgs, 0);
     $TransientKey = GetValue(1, $Sender->RequestArgs);
     $VoteType = FALSE;
     if ($TransientKey == 'voteup' || $TransientKey == 'votedown') {
         $VoteType = $TransientKey;
         $TransientKey = GetValue(2, $Sender->RequestArgs);
     }
     $Session = Gdn::Session();
     $NewUserVote = 0;
     $Total = 0;
     if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $DiscussionID > 0) {
         $DiscussionModel = new DiscussionModel();
         $OldUserVote = $DiscussionModel->GetUserScore($DiscussionID, $Session->UserID);
         if ($VoteType == 'voteup') {
             $NewUserVote = 1;
         } else {
             if ($VoteType == 'votedown') {
                 $NewUserVote = -1;
             } else {
                 $NewUserVote = $OldUserVote == 1 ? -1 : 1;
             }
         }
         $FinalVote = intval($OldUserVote) + intval($NewUserVote);
         // Allow admins to vote unlimited.
         $AllowVote = $Session->CheckPermission('Garden.Moderation.Manage');
         // Only allow users to vote up or down by 1.
         if (!$AllowVote) {
             $AllowVote = $FinalVote > -2 && $FinalVote < 2;
         }
         if ($AllowVote) {
             $Total = $DiscussionModel->SetUserScore($DiscussionID, $Session->UserID, $FinalVote);
         } else {
             $Discussion = $DiscussionModel->GetID($DiscussionID);
             $Total = GetValue('Score', $Discussion, 0);
             $FinalVote = $OldUserVote;
         }
         // Move the comment into or out of moderation.
         if (class_exists('LogModel')) {
             $Moderate = FALSE;
             if ($Total <= C('Plugins.Voting.ModThreshold1', -10)) {
                 $LogOptions = array('GroupBy' => array('RecordID'));
                 // Get the comment row.
                 if (isset($Discussion)) {
                     $Data = (array) $Discussion;
                 } else {
                     $Data = (array) $DiscussionModel->GetID($DiscussionID);
                 }
                 if ($Data) {
                     // Get the users that voted the comment down.
                     $OtherUserIDs = $DiscussionModel->SQL->Select('UserID')->From('UserComment')->Where('CommentID', $DiscussionID)->Where('Score <', 0)->Get()->ResultArray();
                     $OtherUserIDs = array_column($OtherUserIDs, 'UserID');
                     $LogOptions['OtherUserIDs'] = $OtherUserIDs;
                     // Add the comment to moderation.
                     if ($Total > C('Plugins.Voting.ModThreshold2', -20)) {
                         LogModel::Insert('Moderate', 'Discussion', $Data, $LogOptions);
                     }
                 }
                 $Moderate = TRUE;
             }
             if ($Total <= C('Plugins.Voting.ModThreshold2', -20)) {
                 // Remove the comment.
                 $DiscussionModel->Delete($DiscussionID, array('Log' => 'Moderate'));
                 $Sender->InformMessage(sprintf(T('The %s has been removed for moderation.'), T('discussion')));
             } elseif ($Moderate) {
                 $Sender->InformMessage(sprintf(T('The %s has been flagged for moderation.'), T('discussion')));
             }
         }
     }
     $Sender->DeliveryType(DELIVERY_TYPE_BOOL);
     $Sender->SetJson('TotalScore', $Total);
     $Sender->SetJson('FinalVote', $FinalVote);
     $Sender->Render();
 }
开发者ID:vanilla,项目名称:addons,代码行数:80,代码来源:class.voting.plugin.php

示例7: Delete

 public function Delete($CommentID)
 {
     $this->EventArguments['CommentID'] = $CommentID;
     // Check to see if this is the first comment in the discussion
     $Data = $this->SQL->Select('d.DiscussionID, d.FirstCommentID, c.InsertUserID')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Where('c.CommentID', $CommentID)->Get()->FirstRow();
     if ($Data) {
         if ($Data->FirstCommentID == $CommentID) {
             $DiscussionModel = new DiscussionModel();
             $DiscussionModel->Delete($Data->DiscussionID);
         } else {
             $this->FireEvent('DeleteComment');
             // Delete the comment
             $this->SQL->Delete('Comment', array('CommentID' => $CommentID));
             // Delete the search.
             $Search = Gdn::Factory('SearchModel');
             if (!is_null($Search)) {
                 $Search->Delete(array('TableName' => 'Comment', 'PrimaryID' => $CommentID));
             }
         }
         // Update the user's comment count
         $this->UpdateUser($Data->InsertUserID);
     }
     return TRUE;
 }
开发者ID:kidmax,项目名称:Garden,代码行数:24,代码来源:class.commentmodel.php


注:本文中的DiscussionModel::Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。