本文整理汇总了PHP中DiscussionModel::updateDiscussionCount方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::updateDiscussionCount方法的具体用法?PHP DiscussionModel::updateDiscussionCount怎么用?PHP DiscussionModel::updateDiscussionCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::updateDiscussionCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: discussionController_flag_create
/**
* Handle flagging process in a discussion.
*/
public function discussionController_flag_create($Sender)
{
// Signed in users only.
if (!($UserID = Gdn::session()->UserID)) {
return;
}
$UserName = Gdn::session()->User->Name;
$Arguments = $Sender->RequestArgs;
if (sizeof($Arguments) != 5) {
return;
}
list($Context, $ElementID, $ElementAuthorID, $ElementAuthor, $EncodedURL) = $Arguments;
$URL = htmlspecialchars(base64_decode(str_replace('-', '=', $EncodedURL)));
$Sender->setData('Plugin.Flagging.Data', array('Context' => $Context, 'ElementID' => $ElementID, 'ElementAuthorID' => $ElementAuthorID, 'ElementAuthor' => $ElementAuthor, 'URL' => $URL, 'UserID' => $UserID, 'UserName' => $UserName));
if ($Sender->Form->authenticatedPostBack()) {
$SQL = Gdn::sql();
$Comment = $Sender->Form->getValue('Plugin.Flagging.Reason');
$Sender->setData('Plugin.Flagging.Reason', $Comment);
$CreateDiscussion = c('Plugins.Flagging.UseDiscussions');
if ($CreateDiscussion) {
// Category
$CategoryID = c('Plugins.Flagging.CategoryID');
// New discussion name
if ($Context == 'comment') {
$Result = $SQL->select('d.Name')->select('c.Body')->from('Comment c')->join('Discussion d', 'd.DiscussionID = c.DiscussionID', 'left')->where('c.CommentID', $ElementID)->get()->firstRow();
} elseif ($Context == 'discussion') {
$DiscussionModel = new DiscussionModel();
$Result = $DiscussionModel->getID($ElementID);
}
$DiscussionName = val('Name', $Result);
$PrefixedDiscussionName = t('FlagPrefix', 'FLAG: ') . $DiscussionName;
// Prep data for the template
$Sender->setData('Plugin.Flagging.Report', array('DiscussionName' => $DiscussionName, 'FlaggedContent' => val('Body', $Result)));
// Assume no discussion exists
$this->DiscussionID = null;
// Get discussion ID if already flagged
$FlagResult = Gdn::sql()->select('DiscussionID')->from('Flag fl')->where('ForeignType', $Context)->where('ForeignID', $ElementID)->get()->firstRow();
if ($FlagResult) {
// New comment in existing discussion
$DiscussionID = $FlagResult->DiscussionID;
$ReportBody = $Sender->fetchView($this->getView('reportcomment.php'));
$SQL->insert('Comment', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'Body' => $ReportBody, 'Format' => 'Html', 'DateInserted' => date('Y-m-d H:i:s')));
$CommentModel = new CommentModel();
$CommentModel->updateCommentCount($DiscussionID);
} else {
// New discussion body
$ReportBody = $Sender->fetchView($this->getView('report.php'));
$DiscussionID = $SQL->insert('Discussion', array('InsertUserID' => $UserID, 'UpdateUserID' => $UserID, 'CategoryID' => $CategoryID, 'Name' => $PrefixedDiscussionName, 'Body' => $ReportBody, 'Format' => 'Html', 'CountComments' => 1, 'DateInserted' => date('Y-m-d H:i:s'), 'DateUpdated' => date('Y-m-d H:i:s'), 'DateLastComment' => date('Y-m-d H:i:s')));
// Update discussion count
$DiscussionModel = new DiscussionModel();
$DiscussionModel->updateDiscussionCount($CategoryID);
}
}
try {
// Insert the flag
$SQL->insert('Flag', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'InsertName' => $UserName, 'AuthorID' => $ElementAuthorID, 'AuthorName' => $ElementAuthor, 'ForeignURL' => $URL, 'ForeignID' => $ElementID, 'ForeignType' => $Context, 'Comment' => $Comment, 'DateInserted' => date('Y-m-d H:i:s')));
} catch (Exception $e) {
}
// Notify users with permission who've chosen to be notified
if (!$FlagResult) {
// Only send if this is first time it's being flagged.
$Sender->setData('Plugin.Flagging.DiscussionID', $DiscussionID);
$Subject = isset($PrefixedDiscussionName) ? $PrefixedDiscussionName : t('FlagDiscussion', 'A discussion was flagged');
$EmailBody = $Sender->fetchView($this->getView('reportemail.php'));
$NotifyUsers = c('Plugins.Flagging.NotifyUsers', array());
// Send emails
$UserModel = new UserModel();
foreach ($NotifyUsers as $UserID) {
$User = $UserModel->getID($UserID);
$Email = new Gdn_Email();
$Email->to($User->Email)->subject(sprintf(t('[%1$s] %2$s'), Gdn::config('Garden.Title'), $Subject))->message($EmailBody);
try {
$Email->send();
} catch (Exception $e) {
if (debug()) {
throw $e;
}
}
}
}
$Sender->informMessage(t('FlagSent', "Your complaint has been registered."));
}
$Sender->render($this->getView('flag.php'));
}
示例2: comment
//.........这里部分代码省略.........
$vanilla_category_id = c('Vanilla.Embed.DefaultCategoryID', 0);
if ($vanilla_category_id <= 0) {
// No default category defined, so grab the first non-root category and use that.
$vanilla_category_id = $this->DiscussionModel->SQL->select('CategoryID')->from('Category')->where('CategoryID >', 0)->get()->firstRow()->CategoryID;
// No categories in the db? default to 0
if (!$vanilla_category_id) {
$vanilla_category_id = 0;
}
}
} else {
$vanilla_category_id = $Category['CategoryID'];
}
$EmbedUserID = c('Garden.Embed.UserID');
if ($EmbedUserID) {
$EmbedUser = Gdn::userModel()->getID($EmbedUserID);
}
if (!$EmbedUserID || !$EmbedUser) {
$EmbedUserID = Gdn::userModel()->getSystemUserID();
}
$EmbeddedDiscussionData = array('InsertUserID' => $EmbedUserID, 'DateInserted' => Gdn_Format::toDateTime(), 'DateUpdated' => Gdn_Format::toDateTime(), 'CategoryID' => $vanilla_category_id, 'ForeignID' => $vanilla_identifier, 'Type' => $vanilla_type, 'Name' => $Title, 'Body' => $Body, 'Format' => 'Html', 'Attributes' => dbencode($Attributes));
$this->EventArguments['Discussion'] =& $EmbeddedDiscussionData;
$this->fireEvent('BeforeEmbedDiscussion');
$DiscussionID = $this->DiscussionModel->SQL->insert('Discussion', $EmbeddedDiscussionData);
$ValidationResults = $this->DiscussionModel->validationResults();
if (count($ValidationResults) == 0 && $DiscussionID > 0) {
$this->Form->addHidden('DiscussionID', $DiscussionID);
// Put this in the form so reposts won't cause new discussions.
$this->Form->setFormValue('DiscussionID', $DiscussionID);
// Put this in the form values so it is used when saving comments.
$this->setJson('DiscussionID', $DiscussionID);
$this->Discussion = $Discussion = $this->DiscussionModel->getID($DiscussionID, DATASET_TYPE_OBJECT, array('Slave' => false));
// Update the category discussion count
if ($vanilla_category_id > 0) {
$this->DiscussionModel->updateDiscussionCount($vanilla_category_id, $DiscussionID);
}
}
}
// If no discussion was found, error out
if (!$Discussion) {
$this->Form->addError(t('Failed to find discussion for commenting.'));
}
/**
* Special care is taken for embedded comments. Since we don't currently use an advanced editor for these
* comments, we may need to apply certain filters and fixes to the data to maintain its intended display
* with the input format (e.g. maintaining newlines).
*/
if ($isEmbeddedComments) {
$inputFormatter = $this->Form->getFormValue('Format', c('Garden.InputFormatter'));
switch ($inputFormatter) {
case 'Wysiwyg':
$this->Form->setFormValue('Body', nl2br($this->Form->getFormValue('Body')));
break;
}
}
$PermissionCategoryID = val('PermissionCategoryID', $Discussion);
// Setup head
$this->addJsFile('jquery.autosize.min.js');
$this->addJsFile('autosave.js');
$this->addJsFile('post.js');
// Setup comment model, $CommentID, $DraftID
$Session = Gdn::session();
$CommentID = isset($this->Comment) && property_exists($this->Comment, 'CommentID') ? $this->Comment->CommentID : '';
$DraftID = isset($this->Comment) && property_exists($this->Comment, 'DraftID') ? $this->Comment->DraftID : '';
$this->EventArguments['CommentID'] = $CommentID;
$this->EventArguments['DraftID'] = $DraftID;
// Determine whether we are editing
示例3: 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;
}