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


PHP CommentModel::save方法代码示例

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


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

示例1: actionAddComment

 function actionAddComment()
 {
     $user_id = $_REQUEST['uid'];
     $style_id = $_REQUEST['sid'];
     $comment = $_REQUEST['comment'];
     $commentModel = new CommentModel();
     $commentModel->user_id = $user_id;
     $commentModel->comment = $comment;
     $commentModel->create_time = time();
     $commentModel->style_id = $style_id;
     if ($commentModel->save()) {
         echo json_encode(array('result' => 1, 'res' => array('_id' => $commentModel->_id, 'user_id' => $user_id, 'comment' => $comment, 'time' => $commentModel->create_time)));
     } else {
         echo json_encode(array('result' => 0));
     }
 }
开发者ID:dalinhuang,项目名称:styleshop,代码行数:16,代码来源:ApiController.php

示例2: commit

 /**
  *
  *
  * @return bool
  * @throws Exception
  * @throws Gdn_UserException
  */
 public function commit()
 {
     if (is_null($this->Type)) {
         throw new Exception(T("Adding a Regarding event requires a type."));
     }
     if (is_null($this->ForeignType)) {
         throw new Exception(T("Adding a Regarding event requires a foreign association type."));
     }
     if (is_null($this->ForeignID)) {
         throw new Exception(T("Adding a Regarding event requires a foreign association id."));
     }
     if (is_null($this->Comment)) {
         throw new Exception(T("Adding a Regarding event requires a comment."));
     }
     if (is_null($this->UserID)) {
         $this->UserID = Gdn::session()->UserID;
     }
     $RegardingModel = new RegardingModel();
     $CollapseMode = c('Garden.Regarding.AutoCollapse', true);
     $Collapse = false;
     if ($CollapseMode) {
         // Check for an existing report of this type
         $ExistingRegardingEntity = $RegardingModel->getRelated($this->Type, $this->ForeignType, $this->ForeignID);
         if ($ExistingRegardingEntity) {
             $Collapse = true;
             $RegardingID = val('RegardingID', $ExistingRegardingEntity);
         }
     }
     if (!$Collapse) {
         // Create a new Regarding entry
         $RegardingPreSend = array('Type' => $this->Type, 'ForeignType' => $this->ForeignType, 'ForeignID' => $this->ForeignID, 'InsertUserID' => $this->UserID, 'DateInserted' => date('Y-m-d H:i:s'), 'ParentType' => $this->ParentType, 'ParentID' => $this->ParentID, 'ForeignURL' => $this->ForeignURL, 'Comment' => $this->Comment, 'OriginalContent' => $this->OriginalContent, 'Reports' => 1);
         $RegardingID = $RegardingModel->save($RegardingPreSend);
         if (!$RegardingID) {
             return false;
         }
     }
     // Handle collaborations
     // Don't error on foreach
     if (!is_array($this->CollaborativeActions)) {
         $this->CollaborativeActions = array();
     }
     foreach ($this->CollaborativeActions as $Action) {
         $ActionType = val('Type', $Action);
         switch ($ActionType) {
             case 'discussion':
                 $DiscussionModel = new DiscussionModel();
                 if ($Collapse) {
                     $Discussion = Gdn::SQL()->select('*')->from('Discussion')->where(array('RegardingID' => $RegardingID))->get()->firstRow(DATASET_TYPE_ARRAY);
                 }
                 if (!$Collapse || !$Discussion) {
                     $CategoryID = val('Parameters', $Action);
                     // Make a new discussion
                     $DiscussionID = $DiscussionModel->save(array('Name' => $this->CollaborativeTitle, 'CategoryID' => $CategoryID, 'Body' => $this->OriginalContent, 'InsertUserID' => val('InsertUserID', $this->SourceElement), 'Announce' => 0, 'Close' => 0, 'RegardingID' => $RegardingID));
                     if (!$DiscussionID) {
                         throw new Gdn_UserException($DiscussionModel->Validation->resultsText());
                     }
                     $DiscussionModel->updateDiscussionCount($CategoryID);
                 } else {
                     // Add a comment to the existing discussion.
                     $CommentModel = new CommentModel();
                     $CommentID = $CommentModel->save(array('DiscussionID' => val('DiscussionID', $Discussion), 'Body' => $this->Comment, 'InsertUserID' => $this->UserID));
                     $CommentModel->save2($CommentID, true);
                 }
                 break;
             case 'conversation':
                 $ConversationModel = new ConversationModel();
                 $ConversationMessageModel = new ConversationMessageModel();
                 $Users = val('Parameters', $Action);
                 $UserList = explode(',', $Users);
                 if (!sizeof($UserList)) {
                     throw new Exception(sprintf(T("The userlist provided for collaboration on '%s:%s' is invalid.", $this->Type, $this->ForeignType)));
                 }
                 $ConversationID = $ConversationModel->save(array('To' => 'Admins', 'Body' => $this->CollaborativeTitle, 'RecipientUserID' => $UserList, 'RegardingID' => $RegardingID), $ConversationMessageModel);
                 break;
         }
     }
     return true;
 }
开发者ID:sitexa,项目名称:vanilla,代码行数:85,代码来源:class.regardingentity.php

示例3: moderationController_mergeDiscussions_create

 /**
  * Add a method to the ModerationController to handle merging discussions.
  *
  * @param Gdn_Controller $Sender
  */
 public function moderationController_mergeDiscussions_create($Sender)
 {
     $Session = Gdn::session();
     $Sender->Form = new Gdn_Form();
     $Sender->title(t('Merge Discussions'));
     $DiscussionModel = new DiscussionModel();
     $CheckedDiscussions = Gdn::userModel()->getAttribute($Session->User->UserID, 'CheckedDiscussions', array());
     if (!is_array($CheckedDiscussions)) {
         $CheckedDiscussions = array();
     }
     $DiscussionIDs = $CheckedDiscussions;
     $Sender->setData('DiscussionIDs', $DiscussionIDs);
     $CountCheckedDiscussions = count($DiscussionIDs);
     $Sender->setData('CountCheckedDiscussions', $CountCheckedDiscussions);
     $Discussions = $DiscussionModel->SQL->whereIn('DiscussionID', $DiscussionIDs)->get('Discussion')->resultArray();
     $Sender->setData('Discussions', $Discussions);
     // Make sure none of the selected discussions are ghost redirects.
     $discussionTypes = array_column($Discussions, 'Type');
     if (in_array('redirect', $discussionTypes)) {
         throw Gdn_UserException('You cannot merge redirects.', 400);
     }
     // Perform the merge
     if ($Sender->Form->authenticatedPostBack()) {
         // Create a new discussion record
         $MergeDiscussion = false;
         $MergeDiscussionID = $Sender->Form->getFormValue('MergeDiscussionID');
         foreach ($Discussions as $Discussion) {
             if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
                 $MergeDiscussion = $Discussion;
                 break;
             }
         }
         $RedirectLink = $Sender->Form->getFormValue('RedirectLink');
         if ($MergeDiscussion) {
             $ErrorCount = 0;
             // Verify that the user has permission to perform the merge.
             $Category = CategoryModel::categories($MergeDiscussion['CategoryID']);
             if ($Category && !$Category['PermsDiscussionsEdit']) {
                 throw permissionException('Vanilla.Discussions.Edit');
             }
             $DiscussionModel->defineSchema();
             $MaxNameLength = val('Length', $DiscussionModel->Schema->getField('Name'));
             // Assign the comments to the new discussion record
             $DiscussionModel->SQL->update('Comment')->set('DiscussionID', $MergeDiscussionID)->whereIn('DiscussionID', $DiscussionIDs)->put();
             $CommentModel = new CommentModel();
             foreach ($Discussions as $Discussion) {
                 if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
                     continue;
                 }
                 // Create a comment out of the discussion.
                 $Comment = arrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
                 $Comment['DiscussionID'] = $MergeDiscussionID;
                 $CommentModel->Validation->results(true);
                 $CommentID = $CommentModel->save($Comment);
                 if ($CommentID) {
                     // Move any attachments (FileUpload plugin awareness)
                     if (class_exists('MediaModel')) {
                         $MediaModel = new MediaModel();
                         $MediaModel->reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
                     }
                     if ($RedirectLink) {
                         // The discussion needs to be changed to a moved link.
                         $RedirectDiscussion = array('Name' => SliceString(sprintf(t('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => formatString(t('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html');
                         $DiscussionModel->setField($Discussion['DiscussionID'], $RedirectDiscussion);
                         $CommentModel->updateCommentCount($Discussion['DiscussionID']);
                         $CommentModel->removePageCache($Discussion['DiscussionID']);
                     } else {
                         // Delete discussion that was merged.
                         $DiscussionModel->delete($Discussion['DiscussionID']);
                     }
                 } else {
                     $Sender->informMessage($CommentModel->Validation->resultsText());
                     $ErrorCount++;
                 }
             }
             // Update counts on all affected discussions.
             $CommentModel->updateCommentCount($MergeDiscussionID);
             $CommentModel->removePageCache($MergeDiscussionID);
             // Clear selections
             Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedDiscussions', false);
             ModerationController::informCheckedDiscussions($Sender);
             if ($ErrorCount == 0) {
                 $Sender->jsonTarget('', '', 'Refresh');
             }
         }
     }
     $Sender->render('MergeDiscussions', '', 'plugins/SplitMerge');
 }
开发者ID:alim4egg,项目名称:vanilla,代码行数:93,代码来源:class.splitmerge.plugin.php

示例4: validateInput

    } else {
        $movieId = validateInput($_POST['movieId']);
        $comment = validateInput($_POST['comment']);
        if (array_key_exists('commentId', $_POST)) {
            $commentId = $_POST['commentId'];
        }
    }
} else {
    throw new Exception("Error Processing Request", 1);
}
// Check if database is available
CheckOrCreateDB();
if (!$delete) {
    // populating the data
    $co = new CommentModel(array('movie_id' => $movieId, 'comment' => $comment, 'id' => $commentId));
    $co->save();
    $response = array('id' => $co->id, 'message' => 'success!!');
} else {
    if ($delete) {
        // Actions for delete
        $co = CommentModel::find($commentId);
        if ($co->delete()) {
            $response = array('message' => 'success');
        } else {
            $response = array('message' => 'some problems');
        }
    }
}
$encoded = json_encode($response);
header('Content-type: application/json');
exit($encoded);
开发者ID:alfchee,项目名称:TestDomPDF,代码行数:31,代码来源:processNotes.php


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