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


PHP CategoryModel::setRecentPost方法代码示例

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


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

示例1: deleteUserData

 /**
  * Delete all of the Vanilla related information for a specific user.
  *
  * @since 2.1
  *
  * @param int $userID The ID of the user to delete.
  * @param array $options An array of options:
  *  - DeleteMethod: One of delete, wipe, or NULL
  */
 public function deleteUserData($userID, $options = array(), &$data = null)
 {
     $sql = Gdn::sql();
     // Remove discussion watch records and drafts.
     $sql->delete('UserDiscussion', array('UserID' => $userID));
     Gdn::userModel()->getDelete('Draft', array('InsertUserID' => $userID), $data);
     // Comment deletion depends on method selected
     $deleteMethod = val('DeleteMethod', $options, 'delete');
     if ($deleteMethod == 'delete') {
         // Get a list of category IDs that has this user as the most recent poster.
         $discussionCats = $sql->select('cat.CategoryID')->from('Category cat')->join('Discussion d', 'd.DiscussionID = cat.LastDiscussionID')->where('d.InsertUserID', $userID)->get()->resultArray();
         $commentCats = $sql->select('cat.CategoryID')->from('Category cat')->join('Comment c', 'c.CommentID = cat.LastCommentID')->where('c.InsertUserID', $userID)->get()->resultArray();
         $categoryIDs = array_unique(array_merge(array_column($discussionCats, 'CategoryID'), array_column($commentCats, 'CategoryID')));
         // Grab all of the discussions that the user has engaged in.
         $discussionIDs = $sql->select('DiscussionID')->from('Comment')->where('InsertUserID', $userID)->groupBy('DiscussionID')->get()->resultArray();
         $discussionIDs = array_column($discussionIDs, 'DiscussionID');
         Gdn::userModel()->getDelete('Comment', array('InsertUserID' => $userID), $data);
         // Update the comment counts.
         $commentCounts = $sql->select('DiscussionID')->select('CommentID', 'count', 'CountComments')->select('CommentID', 'max', 'LastCommentID')->whereIn('DiscussionID', $discussionIDs)->groupBy('DiscussionID')->get('Comment')->resultArray();
         foreach ($commentCounts as $row) {
             $sql->put('Discussion', array('CountComments' => $row['CountComments'] + 1, 'LastCommentID' => $row['LastCommentID']), array('DiscussionID' => $row['DiscussionID']));
         }
         // Update the last user IDs.
         $sql->update('Discussion d')->join('Comment c', 'd.LastCommentID = c.CommentID', 'left')->set('d.LastCommentUserID', 'c.InsertUserID', false, false)->set('d.DateLastComment', 'coalesce(c.DateInserted, d.DateInserted)', false, false)->whereIn('d.DiscussionID', $discussionIDs)->put();
         // Update the last posts.
         $discussions = $sql->whereIn('DiscussionID', $discussionIDs)->where('LastCommentUserID', $userID)->get('Discussion');
         // Delete the user's discussions.
         Gdn::userModel()->getDelete('Discussion', array('InsertUserID' => $userID), $data);
         // Update the appropriate recent posts in the categories.
         $categoryModel = new CategoryModel();
         foreach ($categoryIDs as $categoryID) {
             $categoryModel->setRecentPost($categoryID);
         }
     } elseif ($deleteMethod == 'wipe') {
         // Erase the user's discussions.
         $sql->update('Discussion')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $userID)->put();
         $sql->update('Comment')->set('Body', t('The user and all related content has been deleted.'))->set('Format', 'Deleted')->where('InsertUserID', $userID)->put();
     } else {
         // Leave comments
     }
     // Remove the user's profile information related to this application
     $sql->update('User')->set(array('CountDiscussions' => 0, 'CountUnreadDiscussions' => 0, 'CountComments' => 0, 'CountDrafts' => 0, 'CountBookmarks' => 0))->where('UserID', $userID)->put();
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:52,代码来源:class.hooks.php

示例2: updateDiscussionCount

 /**
  * Update the CountDiscussions value on the category based on the CategoryID being saved.
  *
  * @param int $CategoryID Unique ID of category we are updating.
  * @param array|false $Discussion The discussion to update the count for or **false** for all of them.
  */
 public function updateDiscussionCount($CategoryID, $Discussion = false)
 {
     $DiscussionID = val('DiscussionID', $Discussion, false);
     if (strcasecmp($CategoryID, 'All') == 0) {
         $Exclude = (bool) Gdn::config('Vanilla.Archive.Exclude');
         $ArchiveDate = Gdn::config('Vanilla.Archive.Date');
         $Params = [];
         $Where = '';
         if ($Exclude && $ArchiveDate) {
             $Where = 'where d.DateLastComment > :ArchiveDate';
             $Params[':ArchiveDate'] = $ArchiveDate;
         }
         // Update all categories.
         $Sql = "update :_Category c\n            left join (\n              select\n                d.CategoryID,\n                coalesce(count(d.DiscussionID), 0) as CountDiscussions,\n                coalesce(sum(d.CountComments), 0) as CountComments\n              from :_Discussion d\n              {$Where}\n              group by d.CategoryID\n            ) d\n              on c.CategoryID = d.CategoryID\n            set\n               c.CountDiscussions = coalesce(d.CountDiscussions, 0),\n               c.CountComments = coalesce(d.CountComments, 0)";
         $Sql = str_replace(':_', $this->Database->DatabasePrefix, $Sql);
         $this->Database->query($Sql, $Params, 'DiscussionModel_UpdateDiscussionCount');
     } elseif (is_numeric($CategoryID)) {
         $this->SQL->select('d.DiscussionID', 'count', 'CountDiscussions')->select('d.CountComments', 'sum', 'CountComments')->from('Discussion d')->where('d.CategoryID', $CategoryID);
         $this->addArchiveWhere();
         $Data = $this->SQL->get()->firstRow();
         $CountDiscussions = (int) GetValue('CountDiscussions', $Data, 0);
         $CountComments = (int) GetValue('CountComments', $Data, 0);
         $CacheAmendment = ['CountDiscussions' => $CountDiscussions, 'CountComments' => $CountComments];
         if ($DiscussionID) {
             $CacheAmendment = array_merge($CacheAmendment, ['LastDiscussionID' => $DiscussionID, 'LastCommentID' => null, 'LastDateInserted' => val('DateInserted', $Discussion)]);
         }
         $CategoryModel = new CategoryModel();
         $CategoryModel->setField($CategoryID, $CacheAmendment);
         $CategoryModel->setRecentPost($CategoryID);
     }
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:37,代码来源:class.discussionmodel.php


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