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


PHP DiscussionModel::deleteID方法代码示例

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


在下文中一共展示了DiscussionModel::deleteID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.
  */
 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->deleteID($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:vanilla,项目名称:vanilla,代码行数:34,代码来源:class.discussioncontroller.php

示例2: 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;
     $CountCheckedDiscussions = count($DiscussionIDs);
     $Discussions = $DiscussionModel->SQL->whereIn('DiscussionID', $DiscussionIDs)->get('Discussion')->resultArray();
     // Make sure none of the selected discussions are ghost redirects.
     $discussionTypes = array_column($Discussions, 'Type');
     if (in_array('redirect', $discussionTypes)) {
         throw new Gdn_UserException('You cannot merge redirects.', 400);
     }
     // Check that the user has permission to edit all discussions
     foreach ($Discussions as $discussion) {
         if (!DiscussionModel::canEdit($discussion)) {
             throw permissionException('@' . t('You do not have permission to edit all of the posts you are trying to merge.'));
         }
     }
     $Sender->setData('DiscussionIDs', $DiscussionIDs);
     $Sender->setData('CountCheckedDiscussions', $CountCheckedDiscussions);
     $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 = val('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->deleteID($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:sitexa,项目名称:vanilla,代码行数:99,代码来源:class.splitmerge.plugin.php

示例3: flagForReview

 /**
  * Insert a SPAM Queue entry for the specified record and delete the record, if possible.
  *
  * @param string $recordType The type of record we're flagging: Discussion or Comment.
  * @param int $id ID of the record we're flagging.
  * @param object|array $data Properties used for updating/overriding the record's current values.
  *
  * @throws Exception If an invalid record type is specified, throw an exception.
  */
 protected static function flagForReview($recordType, $id, $data)
 {
     // We're planning to purge the spammy record.
     $deleteRow = true;
     /**
      * We're only handling two types of content: discussions and comments.  Both need some special setup.
      * Error out if we're not dealing with a discussion or comment.
      */
     switch ($recordType) {
         case 'Comment':
             $model = new CommentModel();
             $row = $model->getID($id, DATASET_TYPE_ARRAY);
             break;
         case 'Discussion':
             $model = new DiscussionModel();
             $row = $model->getID($id, DATASET_TYPE_ARRAY);
             /**
              * If our discussion has more than three comments, it might be worth saving.  Hold off on deleting and
              * just flag it.  If we have between 0 and 3 comments, save them along with the discussion.
              */
             if ($row['CountComments'] > 3) {
                 $deleteRow = false;
             } elseif ($row['CountComments'] > 0) {
                 $comments = Gdn::database()->sql()->getWhere('Comment', array('DiscussionID' => $id))->resultArray();
                 if (!array_key_exists('_Data', $row)) {
                     $row['_Data'] = array();
                 }
                 $row['_Data']['Comment'] = $comments;
             }
             break;
         default:
             throw notFoundException($recordType);
     }
     $overrideFields = array('Name', 'Body');
     foreach ($overrideFields as $fieldName) {
         if (($fieldValue = val($fieldName, $data, false)) !== false) {
             $row[$fieldName] = $fieldValue;
         }
     }
     $logOptions = array('GroupBy' => array('RecordID'));
     if ($deleteRow) {
         // Remove the record to the log.
         $model->deleteID($id);
     }
     LogModel::insert('Spam', $recordType, $row, $logOptions);
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:55,代码来源:class.spammodel.php

示例4: 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(val('CategoryID', $Discussion));
         $CountCheckedDiscussions = $DiscussionData->numRows();
         if ($Session->checkPermission('Vanilla.Discussions.Delete', true, 'Category', val('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->deleteID($DiscussionID);
             if ($Deleted) {
                 $this->jsonTarget("#Discussion_{$DiscussionID}", '', 'SlideUp');
             }
         }
         // Clear selections
         Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedDiscussions', null);
         ModerationController::InformCheckedDiscussions($this, true);
     }
     $this->render();
 }
开发者ID:sitexa,项目名称:vanilla,代码行数:46,代码来源:class.moderationcontroller.php


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