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


PHP CommentModel::getID方法代码示例

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


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

示例1: deleteComment

 /**
  * Allows user to delete a comment.
  *
  * If the comment is the only one in the discussion, the discussion will
  * be deleted as well. Users without administrative delete abilities
  * should not be able to delete a comment unless it is a draft. This is
  * a "hard" delete - it is removed from the database.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $CommentID Unique comment ID.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function deleteComment($CommentID = '', $TransientKey = '')
 {
     $Session = Gdn::session();
     $DefaultTarget = '/discussions/';
     $ValidCommentID = is_numeric($CommentID) && $CommentID > 0;
     $ValidUser = $Session->UserID > 0 && $Session->validateTransientKey($TransientKey);
     if ($ValidCommentID && $ValidUser) {
         // Get comment and discussion data
         $Comment = $this->CommentModel->getID($CommentID);
         $DiscussionID = val('DiscussionID', $Comment);
         $Discussion = $this->DiscussionModel->getID($DiscussionID);
         if ($Comment && $Discussion) {
             $DefaultTarget = discussionUrl($Discussion);
             // Make sure comment is this user's or they have Delete permission
             if ($Comment->InsertUserID != $Session->UserID || !c('Vanilla.Comments.AllowSelfDelete')) {
                 $this->permission('Vanilla.Comments.Delete', true, 'Category', $Discussion->PermissionCategoryID);
             }
             // Make sure that content can (still) be edited
             $EditContentTimeout = c('Garden.EditContentTimeout', -1);
             $CanEdit = $EditContentTimeout == -1 || strtotime($Comment->DateInserted) + $EditContentTimeout > time();
             if (!$CanEdit) {
                 $this->permission('Vanilla.Comments.Delete', true, 'Category', $Discussion->PermissionCategoryID);
             }
             // Delete the comment
             if (!$this->CommentModel->deleteID($CommentID)) {
                 $this->Form->addError('Failed to delete comment');
             }
         } else {
             $this->Form->addError('Invalid comment');
         }
     } else {
         $this->Form->addError('ErrPermission');
     }
     // Redirect
     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', $DefaultTarget);
         SafeRedirect($Target);
     }
     if ($this->Form->errorCount() > 0) {
         $this->setJson('ErrorMessage', $this->Form->errors());
     } else {
         $this->jsonTarget("#Comment_{$CommentID}", '', 'SlideUp');
     }
     $this->render();
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:59,代码来源:class.discussioncontroller.php

示例2: getRecord

 /**
  * Get a record from the database.
  *
  * @param string $recordType The type of record to get. This is usually the un-prefixed table name of the record.
  * @param int $id The ID of the record.
  * @param bool $throw Whether or not to throw an exception if the record isn't found.
  * @return array|false Returns an array representation of the record or false if the record isn't found.
  * @throws Exception Throws an exception with a 404 code if the record isn't found and {@link $throw} is true.
  * @throws Gdn_UserException Throws an exception when {@link $recordType} is unknown.
  */
 function getRecord($recordType, $id, $throw = false)
 {
     $Row = false;
     switch (strtolower($recordType)) {
         case 'discussion':
             $Model = new DiscussionModel();
             $Row = $Model->getID($id);
             $Row->Url = DiscussionUrl($Row);
             $Row->ShareUrl = $Row->Url;
             if ($Row) {
                 return (array) $Row;
             }
             break;
         case 'comment':
             $Model = new CommentModel();
             $Row = $Model->getID($id, DATASET_TYPE_ARRAY);
             if ($Row) {
                 $Row['Url'] = Url("/discussion/comment/{$id}#Comment_{$id}", true);
                 $Model = new DiscussionModel();
                 $Discussion = $Model->getID($Row['DiscussionID']);
                 if ($Discussion) {
                     $Discussion->Url = DiscussionUrl($Discussion);
                     $Row['ShareUrl'] = $Discussion->Url;
                     $Row['Name'] = $Discussion->Name;
                     $Row['Discussion'] = (array) $Discussion;
                 }
                 return $Row;
             }
             break;
         case 'activity':
             $Model = new ActivityModel();
             $Row = $Model->getID($id, DATASET_TYPE_ARRAY);
             if ($Row) {
                 $Row['Name'] = formatString($Row['HeadlineFormat'], $Row);
                 $Row['Body'] = $Row['Story'];
                 return $Row;
             }
             break;
         default:
             throw new Gdn_UserException('Unknown record type requested.');
     }
     if ($throw) {
         throw NotFoundException();
     } else {
         return false;
     }
 }
开发者ID:sitexa,项目名称:vanilla,代码行数:57,代码来源:functions.general.php

示例3: gdn_statistics_tick_handler

 /**
  * Discussion view counter.
  *
  * @param $Sender
  * @param $Args
  */
 public function gdn_statistics_tick_handler($Sender, $Args)
 {
     $Path = Gdn::request()->post('Path');
     $Args = Gdn::request()->post('Args');
     parse_str($Args, $Args);
     $ResolvedPath = trim(Gdn::request()->post('ResolvedPath'), '/');
     $ResolvedArgs = Gdn::request()->post('ResolvedArgs');
     $DiscussionID = null;
     $DiscussionModel = new DiscussionModel();
     // Comment permalink
     if ($ResolvedPath == 'vanilla/discussion/comment') {
         $CommentID = val('CommentID', $ResolvedArgs);
         $CommentModel = new CommentModel();
         $Comment = $CommentModel->getID($CommentID);
         $DiscussionID = val('DiscussionID', $Comment);
     } elseif ($ResolvedPath == 'vanilla/discussion/index') {
         $DiscussionID = val('DiscussionID', $ResolvedArgs, null);
     } elseif ($ResolvedPath == 'vanilla/discussion/embed') {
         $ForeignID = val('vanilla_identifier', $Args);
         if ($ForeignID) {
             // This will be hit a lot so let's try caching it...
             $Key = "DiscussionID.ForeignID.page.{$ForeignID}";
             $DiscussionID = Gdn::cache()->get($Key);
             if (!$DiscussionID) {
                 $Discussion = $DiscussionModel->getForeignID($ForeignID, 'page');
                 $DiscussionID = val('DiscussionID', $Discussion);
                 Gdn::cache()->store($Key, $DiscussionID, array(Gdn_Cache::FEATURE_EXPIRY, 1800));
             }
         }
     }
     if ($DiscussionID) {
         $DiscussionModel->addView($DiscussionID);
     }
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:40,代码来源:class.hooks.php

示例4: 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


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