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


PHP CategoryModel::setField方法代码示例

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


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

示例1: categoryDisplayAs

 /**
  * Set the display as property of a category.
  *
  * @throws Gdn_UserException Throws an exception of the posted data is incorrect.
  */
 public function categoryDisplayAs()
 {
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     if ($this->Request->isAuthenticatedPostBack(true)) {
         $categoryID = $this->Request->post('CategoryID');
         $displayAs = $this->Request->post('DisplayAs');
         if (!$categoryID || !$displayAs) {
             throw new Gdn_UserException("CategoryID and DisplayAs are required", 400);
         }
         $this->CategoryModel->setField($categoryID, 'DisplayAs', $displayAs);
         $category = CategoryModel::categories($categoryID);
         $this->setData('CategoryID', $category['CategoryID']);
         $this->setData('DisplayAs', $category['DisplayAs']);
     } else {
         throw new Gdn_UserException(Gdn::request()->requestMethod() . ' not allowed.', 405);
     }
     $this->render();
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:23,代码来源:class.vanillasettingscontroller.php

示例2: save2

 /**
  * Insert or update meta data about the comment.
  *
  * Updates unread comment totals, bookmarks, and activity. Sends notifications.
  *
  * @since 2.0.0
  * @access public
  *
  * @param array $CommentID Unique ID for this comment.
  * @param int $Insert Used as a boolean for whether this is a new comment.
  * @param bool $CheckExisting Not used.
  * @param bool $IncUser Whether or not to just increment the user's comment count rather than recalculate it.
  */
 public function save2($CommentID, $Insert, $CheckExisting = true, $IncUser = false)
 {
     $Session = Gdn::session();
     $UserModel = Gdn::userModel();
     // Load comment data
     $Fields = $this->getID($CommentID, DATASET_TYPE_ARRAY);
     // Clear any session stashes related to this discussion
     $DiscussionModel = new DiscussionModel();
     $DiscussionID = val('DiscussionID', $Fields);
     $Discussion = $DiscussionModel->getID($DiscussionID);
     $Session->Stash('CommentForForeignID_' . GetValue('ForeignID', $Discussion));
     // Make a quick check so that only the user making the comment can make the notification.
     // This check may be used in the future so should not be depended on later in the method.
     if (Gdn::controller()->deliveryType() === DELIVERY_TYPE_ALL && $Fields['InsertUserID'] != $Session->UserID) {
         return;
     }
     // Update the discussion author's CountUnreadDiscussions (ie.
     // the number of discussions created by the user that s/he has
     // unread messages in) if this comment was not added by the
     // discussion author.
     $this->UpdateUser($Fields['InsertUserID'], $IncUser && $Insert);
     // Mark the user as participated.
     $this->SQL->replace('UserDiscussion', array('Participated' => 1), array('DiscussionID' => $DiscussionID, 'UserID' => val('InsertUserID', $Fields)));
     if ($Insert) {
         // UPDATE COUNT AND LAST COMMENT ON CATEGORY TABLE
         if ($Discussion->CategoryID > 0) {
             $Category = CategoryModel::categories($Discussion->CategoryID);
             if ($Category) {
                 $CountComments = val('CountComments', $Category, 0) + 1;
                 if ($CountComments < self::COMMENT_THRESHOLD_SMALL || $CountComments < self::COMMENT_THRESHOLD_LARGE && $CountComments % self::COUNT_RECALC_MOD == 0) {
                     $CountComments = $this->SQL->select('CountComments', 'sum', 'CountComments')->from('Discussion')->where('CategoryID', $Discussion->CategoryID)->get()->firstRow()->CountComments;
                 }
             }
             $CategoryModel = new CategoryModel();
             $CategoryModel->setField($Discussion->CategoryID, array('LastDiscussionID' => $DiscussionID, 'LastCommentID' => $CommentID, 'CountComments' => $CountComments, 'LastDateInserted' => $Fields['DateInserted']));
             // Update the cache.
             $CategoryCache = array('LastTitle' => $Discussion->Name, 'LastUserID' => $Fields['InsertUserID'], 'LastUrl' => DiscussionUrl($Discussion) . '#latest');
             CategoryModel::SetCache($Discussion->CategoryID, $CategoryCache);
         }
         // Prepare the notification queue.
         $ActivityModel = new ActivityModel();
         $HeadlineFormat = t('HeadlineFormat.Comment', '{ActivityUserID,user} commented on <a href="{Url,html}">{Data.Name,text}</a>');
         $Category = CategoryModel::categories($Discussion->CategoryID);
         $Activity = array('ActivityType' => 'Comment', 'ActivityUserID' => $Fields['InsertUserID'], 'HeadlineFormat' => $HeadlineFormat, 'RecordType' => 'Comment', 'RecordID' => $CommentID, 'Route' => "/discussion/comment/{$CommentID}#Comment_{$CommentID}", 'Data' => array('Name' => $Discussion->Name, 'Category' => val('Name', $Category)));
         // Allow simple fulltext notifications
         if (c('Vanilla.Activity.ShowCommentBody', false)) {
             $Activity['Story'] = val('Body', $Fields);
             $Activity['Format'] = val('Format', $Fields);
         }
         // Pass generic activity to events.
         $this->EventArguments['Activity'] = $Activity;
         // Notify users who have bookmarked the discussion.
         $BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
         foreach ($BookmarkData->result() as $Bookmark) {
             // Check user can still see the discussion.
             if (!$UserModel->GetCategoryViewPermission($Bookmark->UserID, $Discussion->CategoryID)) {
                 continue;
             }
             $Activity['NotifyUserID'] = $Bookmark->UserID;
             $Activity['Data']['Reason'] = 'bookmark';
             $ActivityModel->Queue($Activity, 'BookmarkComment', array('CheckRecord' => true));
         }
         // Notify users who have participated in the discussion.
         $ParticipatedData = $DiscussionModel->GetParticipatedUsers($DiscussionID);
         foreach ($ParticipatedData->result() as $UserRow) {
             if (!$UserModel->GetCategoryViewPermission($UserRow->UserID, $Discussion->CategoryID)) {
                 continue;
             }
             $Activity['NotifyUserID'] = $UserRow->UserID;
             $Activity['Data']['Reason'] = 'participated';
             $ActivityModel->Queue($Activity, 'ParticipateComment', array('CheckRecord' => true));
         }
         // Record user-comment activity.
         if ($Discussion != false) {
             $InsertUserID = val('InsertUserID', $Discussion);
             // Check user can still see the discussion.
             if ($UserModel->GetCategoryViewPermission($InsertUserID, $Discussion->CategoryID)) {
                 $Activity['NotifyUserID'] = $InsertUserID;
                 $Activity['Data']['Reason'] = 'mine';
                 $ActivityModel->Queue($Activity, 'DiscussionComment');
             }
         }
         // Record advanced notifications.
         if ($Discussion !== false) {
             $Activity['Data']['Reason'] = 'advanced';
             $this->RecordAdvancedNotications($ActivityModel, $Activity, $Discussion);
         }
//.........这里部分代码省略.........
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:101,代码来源:class.commentmodel.php

示例3: updateDiscussionCount

 /**
  * Updates the CountDiscussions value on the category based on the CategoryID
  * being saved.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $CategoryID Unique ID of category we are updating.
  */
 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 = array();
         $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 = array('CountDiscussions' => $CountDiscussions, 'CountComments' => $CountComments);
         if ($DiscussionID) {
             $CacheAmendment = array_merge($CacheAmendment, array('LastDiscussionID' => $DiscussionID, 'LastCommentID' => null, 'LastDateInserted' => val('DateInserted', $Discussion)));
         }
         $CategoryModel = new CategoryModel();
         $CategoryModel->setField($CategoryID, $CacheAmendment);
         $CategoryModel->SetRecentPost($CategoryID);
     }
 }
开发者ID:RodSloan,项目名称:vanilla,代码行数:40,代码来源:class.discussionmodel.php

示例4: _setCategoryPermissionIDs

 /**
  *
  *
  * @param $Category
  * @param $PermissionID
  * @param $IDs
  */
 protected function _setCategoryPermissionIDs($Category, $PermissionID, $IDs)
 {
     static $CategoryModel;
     if (!isset($CategoryModel)) {
         $CategoryModel = new CategoryModel();
     }
     $CategoryID = $Category['CategoryID'];
     if (isset($IDs[$CategoryID])) {
         $PermissionID = $CategoryID;
     }
     if ($Category['PermissionCategoryID'] != $PermissionID) {
         $CategoryModel->setField($CategoryID, 'PermissionCategoryID', $PermissionID);
     }
     $ChildIDs = val('ChildIDs', $Category, array());
     foreach ($ChildIDs as $ChildID) {
         $ChildCategory = CategoryModel::categories($ChildID);
         if ($ChildCategory) {
             $this->_setCategoryPermissionIDs($ChildCategory, $PermissionID, $IDs);
         }
     }
 }
开发者ID:oMadMartigaNo,项目名称:readjust-forum,代码行数:28,代码来源:class.importmodel.php

示例5: deleteCategoryPhoto

 /**
  * Deleting a category photo.
  *
  * @since 2.1
  * @access public
  *
  * @param int $CategoryID Unique ID of the category to have its photo deleted.
  */
 public function deleteCategoryPhoto($CategoryID = false, $TransientKey = '')
 {
     // Check permission
     $this->permission('Garden.Settings.Manage');
     $RedirectUrl = 'vanilla/settings/editcategory/' . $CategoryID;
     if (Gdn::session()->validateTransientKey($TransientKey)) {
         // Do removal, set message, redirect
         $CategoryModel = new CategoryModel();
         $CategoryModel->setField($CategoryID, 'Photo', null);
         $this->informMessage(t('Category photo has been deleted.'));
     }
     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         redirect($RedirectUrl);
     } else {
         $this->RedirectUrl = url($RedirectUrl);
         $this->render();
     }
 }
开发者ID:akratiani,项目名称:vanilla,代码行数:26,代码来源:class.settingscontroller.php


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