ConversationModel::bookmark PHP Метод

bookmark() публичный Метод

Bookmark (or unbookmark) a conversation for a specific user id.
С версии: 2.0.0
public bookmark ( integer $ConversationID, integer $UserID ) : boolean
$ConversationID integer Unique ID of conversation effected.
$UserID integer Unique ID of current user.
Результат boolean Whether it is currently bookmarked.
    public function bookmark($ConversationID, $UserID)
    {
        $Bookmark = false;
        $Discussion = $this->getID($ConversationID, $UserID);
        if (is_object($Discussion)) {
            $Bookmark = $Discussion->Bookmark == '0' ? '1' : '0';
            $this->SQL->update('UserConversation')->set('Bookmark', $Bookmark)->where('ConversationID', $ConversationID)->where('UserID', $UserID)->put();
            $Bookmark == '1' ? true : false;
        }
        return $Bookmark;
    }

Usage Example

Пример #1
0
 /**
  * Allows users to bookmark conversations.
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function bookmark($ConversationID = '', $TransientKey = '')
 {
     $Session = Gdn::session();
     $Bookmark = null;
     // Validate & do bookmarking.
     if (is_numeric($ConversationID) && $ConversationID > 0 && $Session->UserID > 0 && $Session->validateTransientKey($TransientKey)) {
         $Bookmark = $this->ConversationModel->bookmark($ConversationID, $Session->UserID);
     }
     // Report success or error
     if ($Bookmark === false) {
         $this->Form->addError('ErrorBool');
     } else {
         $this->setJson('Bookmark', $Bookmark);
     }
     // Redirect back where the user came from if necessary
     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         redirect($_SERVER['HTTP_REFERER']);
     } else {
         $this->render();
     }
 }