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


PHP DiscussionModel::Bookmark方法代码示例

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


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

示例1: Bookmark

 /**
  * Allows user to bookmark or unbookmark a discussion.
  *
  * If the discussion isn't bookmarked by the user, this bookmarks it.
  * If it is already bookmarked, this unbookmarks it.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID.
  */
 public function Bookmark($DiscussionID = NULL)
 {
     // Make sure we are posting back.
     if (!$this->Request->IsPostBack()) {
         throw PermissionException('Javascript');
     }
     $Session = Gdn::Session();
     if (!$Session->UserID) {
         throw PermissionException('SignedIn');
     }
     // Check the form to see if the data was posted.
     $Form = new Gdn_Form();
     $DiscussionID = $Form->GetFormValue('DiscussionID', $DiscussionID);
     $Bookmark = $Form->GetFormValue('Bookmark', NULL);
     $UserID = $Form->GetFormValue('UserID', $Session->UserID);
     // Check the permission on the user.
     if ($UserID != $Session->UserID) {
         $this->Permission('Garden.Moderation.Manage');
     }
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     $Bookmark = $this->DiscussionModel->Bookmark($DiscussionID, $UserID, $Bookmark);
     // Set the new value for api calls and json targets.
     $this->SetData(array('UserID' => $UserID, 'DiscussionID' => $DiscussionID, 'Bookmarked' => (bool) $Bookmark));
     SetValue('Bookmarked', $Discussion, (int) $Bookmark);
     // Update the user's bookmark count
     $CountBookmarks = $this->DiscussionModel->SetUserBookmarkCount($UserID);
     $this->JsonTarget('.User-CountBookmarks', (string) $CountBookmarks);
     //  Short circuit if this is an api call.
     if ($this->DeliveryType() === DELIVERY_TYPE_DATA) {
         $this->Render('Blank', 'Utility', 'Dashboard');
         return;
     }
     // Return the appropriate bookmark.
     require_once $this->FetchViewLocation('helper_functions', 'Discussions');
     $Html = BookmarkButton($Discussion);
     //      $this->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Bookmark,.Section-Discussion .PageTitle .Bookmark", $Html, 'ReplaceWith');
     $this->JsonTarget("!element", $Html, 'ReplaceWith');
     // Add the bookmark to the bookmarks module.
     if ($Bookmark) {
         // Grab the individual bookmark and send it to the client.
         $Bookmarks = new BookmarkedModule($this);
         if ($CountBookmarks == 1) {
             // When there is only one bookmark we have to get the whole module.
             $Target = '#Panel';
             $Type = 'Append';
             $Bookmarks->GetData();
             $Data = $Bookmarks->ToString();
         } else {
             $Target = '#Bookmark_List';
             $Type = 'Prepend';
             $Loc = $Bookmarks->FetchViewLocation('discussion');
             ob_start();
             include $Loc;
             $Data = ob_get_clean();
         }
         $this->JsonTarget($Target, $Data, $Type);
     } else {
         // Send command to remove bookmark html.
         if ($CountBookmarks == 0) {
             $this->JsonTarget('#Bookmarks', NULL, 'Remove');
         } else {
             $this->JsonTarget('#Bookmark_' . $DiscussionID, NULL, 'Remove');
         }
     }
     $this->Render('Blank', 'Utility', 'Dashboard');
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:80,代码来源:class.discussioncontroller.php


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