本文整理汇总了PHP中DiscussionModel::ValidationResults方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::ValidationResults方法的具体用法?PHP DiscussionModel::ValidationResults怎么用?PHP DiscussionModel::ValidationResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::ValidationResults方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ModerationController_SplitComments_Create
/**
* Add a method to the ModerationController to handle splitting comments out to a new discussion.
*/
public function ModerationController_SplitComments_Create($Sender)
{
$Session = Gdn::Session();
$Sender->Form = new Gdn_Form();
$Sender->Title(T('Split Comments'));
$Sender->Category = FALSE;
$DiscussionID = GetValue('0', $Sender->RequestArgs, '');
if (!is_numeric($DiscussionID)) {
return;
}
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->GetID($DiscussionID);
if (!$Discussion) {
return;
}
// Verify that the user has permission to perform the split
$Sender->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
$CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array());
if (!is_array($CheckedComments)) {
$CheckedComments = array();
}
$CommentIDs = array();
foreach ($CheckedComments as $DiscID => $Comments) {
foreach ($Comments as $Comment) {
if ($DiscID == $DiscussionID) {
$CommentIDs[] = str_replace('Comment_', '', $Comment);
}
}
}
// Load category data.
$Sender->ShowCategorySelector = (bool) C('Vanilla.Categories.Use');
$CountCheckedComments = count($CommentIDs);
$Sender->SetData('CountCheckedComments', $CountCheckedComments);
// Perform the split
if ($Sender->Form->AuthenticatedPostBack()) {
// Create a new discussion record
$Data = $Sender->Form->FormValues();
$Data['Body'] = sprintf(T('This discussion was created from comments split from: %s.'), Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name) . '/'));
$Data['Format'] = 'Html';
$NewDiscussionID = $DiscussionModel->Save($Data);
$Sender->Form->SetValidationResults($DiscussionModel->ValidationResults());
if ($Sender->Form->ErrorCount() == 0 && $NewDiscussionID > 0) {
// Re-assign the comments to the new discussion record
$DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $NewDiscussionID)->WhereIn('CommentID', $CommentIDs)->Put();
// Update counts on both discussions
$CommentModel = new CommentModel();
$CommentModel->UpdateCommentCount($DiscussionID);
// $CommentModel->UpdateUserCommentCounts($DiscussionID);
$CommentModel->UpdateCommentCount($NewDiscussionID);
// Clear selections
unset($CheckedComments[$DiscussionID]);
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedComments', $CheckedComments);
ModerationController::InformCheckedComments($Sender);
$Sender->RedirectUrl = Url('discussion/' . $NewDiscussionID . '/' . Gdn_Format::Url($Data['Name']));
}
} else {
$Sender->Form->SetValue('CategoryID', GetValue('CategoryID', $Discussion));
}
$Sender->Render($this->GetView('splitcomments.php'));
}
示例2: Comment
/**
* Create or update a comment.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique ID to add the comment to. If blank, this method will throw an error.
*/
public function Comment($DiscussionID = '')
{
// Get $DiscussionID from RequestArgs if valid
if ($DiscussionID == '' && count($this->RequestArgs)) {
if (is_numeric($this->RequestArgs[0])) {
$DiscussionID = $this->RequestArgs[0];
}
}
// If invalid $DiscussionID, get from form.
$this->Form->SetModel($this->CommentModel);
$DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->GetFormValue('DiscussionID', 0);
// Set discussion data
$this->DiscussionID = $DiscussionID;
$this->Discussion = $Discussion = $this->DiscussionModel->GetID($DiscussionID);
// Is this an embedded comment being posted to a discussion that doesn't exist yet?
$vanilla_type = $this->Form->GetFormValue('vanilla_type', '');
$vanilla_url = $this->Form->GetFormValue('vanilla_url', '');
$vanilla_category_id = $this->Form->GetFormValue('vanilla_category_id', '');
$Attributes = array('ForeignUrl' => $vanilla_url);
$vanilla_identifier = $this->Form->GetFormValue('vanilla_identifier', '');
// Only allow vanilla identifiers of 32 chars or less - md5 if larger
if (strlen($vanilla_identifier) > 32) {
$Attributes['vanilla_identifier'] = $vanilla_identifier;
$vanilla_identifier = md5($vanilla_identifier);
}
if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
$Discussion = $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
if ($Discussion) {
$this->DiscussionID = $DiscussionID = $Discussion->DiscussionID;
$this->Form->SetValue('DiscussionID', $DiscussionID);
}
}
// If so, create it!
if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
// Add these values back to the form if they exist!
$this->Form->AddHidden('vanilla_identifier', $vanilla_identifier);
$this->Form->AddHidden('vanilla_type', $vanilla_type);
$this->Form->AddHidden('vanilla_url', $vanilla_url);
$this->Form->AddHidden('vanilla_category_id', $vanilla_category_id);
$PageInfo = FetchPageInfo($vanilla_url);
if (!($Title = $this->Form->GetFormValue('Name'))) {
$Title = GetValue('Title', $PageInfo, '');
if ($Title == '') {
$Title = T('Undefined discussion subject.');
}
}
$Description = GetValue('Description', $PageInfo, '');
$Images = GetValue('Images', $PageInfo, array());
$LinkText = T('EmbededDiscussionLinkText', 'Read the full story here');
if (!$Description && count($Images) == 0) {
$Body = FormatString('<p><a href="{Url}">{LinkText}</a></p>', array('Url' => $vanilla_url, 'LinkText' => $LinkText));
} else {
$Body = FormatString('
<div class="EmbeddedContent">{Image}<strong>{Title}</strong>
<p>{Excerpt}</p>
<p><a href="{Url}">{LinkText}</a></p>
<div class="ClearFix"></div>
</div>', array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? Img(GetValue(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $vanilla_url, 'LinkText' => $LinkText));
}
if ($Body == '') {
$Body = $vanilla_url;
}
if ($Body == '') {
$Body = T('Undefined discussion body.');
}
// Validate the CategoryID for inserting.
$Category = CategoryModel::Categories($vanilla_category_id);
if (!$Category) {
$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' => serialize($Attributes));
$this->EventArguments['Discussion'] = $EmbeddedDiscussionData;
$this->FireEvent('BeforeEmbedDiscussion');
$DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', $EmbeddedDiscussionData);
$ValidationResults = $this->DiscussionModel->ValidationResults();
//.........这里部分代码省略.........
示例3: ModerationController_SplitComments_Create
/**
* Add a method to the ModerationController to handle splitting comments out to a new discussion.
*/
public function ModerationController_SplitComments_Create($Sender) {
$Session = Gdn::Session();
$Sender->Form = new Gdn_Form();
$Sender->Title(T('Split Comments'));
$Sender->Category = FALSE;
$DiscussionID = GetValue('0', $Sender->RequestArgs, '');
if (!is_numeric($DiscussionID))
return;
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->GetID($DiscussionID);
if (!$Discussion)
return;
// Verify that the user has permission to perform the split
$Sender->Permission('Vanilla.Discussion.Edit', TRUE, 'Category', $Discussion->CategoryID);
$CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array());
if (!is_array($CheckedComments))
$CheckedComments = array();
$CommentIDs = array();
foreach ($CheckedComments as $DiscID => $Comments) {
foreach ($Comments as $Comment) {
if (substr($Comment, 0, 8) == 'Comment_' && $DiscID == $DiscussionID)
$CommentIDs[] = str_replace('Comment_', '', $Comment);
}
}
// Load category data
$Sender->ShowCategorySelector = (bool)C('Vanilla.Categories.Use');
if ($Sender->ShowCategorySelector) {
$CategoryModel = new CategoryModel();
$CategoryData = $CategoryModel->GetFull('', 'Vanilla.Discussions.Add');
$aCategoryData = array();
foreach ($CategoryData->Result() as $Category) {
if ($Category->CategoryID <= 0)
continue;
if ($Discussion->CategoryID == $Category->CategoryID)
$Sender->Category = $Category;
$CategoryName = $Category->Name;
if ($Category->Depth > 1) {
$CategoryName = '↳ '.$CategoryName;
$CategoryName = str_pad($CategoryName, strlen($CategoryName) + $Category->Depth - 2, ' ', STR_PAD_LEFT);
$CategoryName = str_replace(' ', ' ', $CategoryName);
}
$aCategoryData[$Category->CategoryID] = $CategoryName;
$Sender->EventArguments['aCategoryData'] = &$aCategoryData;
$Sender->EventArguments['Category'] = &$Category;
$Sender->FireEvent('AfterCategoryItem');
}
$Sender->CategoryData = $aCategoryData;
}
$CountCheckedComments = count($CommentIDs);
$Sender->SetData('CountCheckedComments', $CountCheckedComments);
// Perform the split
if ($Sender->Form->AuthenticatedPostBack()) {
// Create a new discussion record
$Data = $Sender->Form->FormValues();
$Data['Body'] = sprintf(T('This discussion was created from comments split from: %s.'), Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/'.$Discussion->DiscussionID.'/'.Gdn_Format::Url($Discussion->Name).'/'));
$NewDiscussionID = $DiscussionModel->Save($Data);
$Sender->Form->SetValidationResults($DiscussionModel->ValidationResults());
if ($Sender->Form->ErrorCount() == 0 && $NewDiscussionID > 0) {
// Re-assign the comments to the new discussion record
$DiscussionModel->SQL
->Update('Comment')
->Set('DiscussionID', $NewDiscussionID)
->WhereIn('CommentID', $CommentIDs)
->Put();
// Update counts on both discussions
$CommentModel = new CommentModel();
$CommentModel->UpdateCommentCount($DiscussionID);
$CommentModel->UpdateUserCommentCounts($DiscussionID);
$CommentModel->UpdateCommentCount($NewDiscussionID);
// Clear selections
unset($CheckedComments[$DiscussionID]);
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedComments', $CheckedComments);
ModerationController::InformCheckedComments($Sender);
$Sender->RedirectUrl = Url('discussion/'.$NewDiscussionID.'/'.Gdn_Format::Url($Data['Name']));
}
}
$Sender->Render($this->GetView('splitcomments.php'));
}
示例4: ConfirmDiscussionMoves
/**
* Form to ask for the destination of the move, confirmation and permission check.
*/
public function ConfirmDiscussionMoves($DiscussionID = NULL)
{
$Session = Gdn::Session();
$this->Form = new Gdn_Form();
$DiscussionModel = new DiscussionModel();
$this->Title(T('Confirm'));
if ($DiscussionID) {
$CheckedDiscussions = (array) $DiscussionID;
$ClearSelection = FALSE;
} else {
$CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
if (!is_array($CheckedDiscussions)) {
$CheckedDiscussions = array();
}
$ClearSelection = TRUE;
}
$DiscussionIDs = $CheckedDiscussions;
$CountCheckedDiscussions = count($DiscussionIDs);
$this->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
// Check for edit permissions on each discussion
$AllowedDiscussions = array();
$DiscussionData = $DiscussionModel->SQL->Select('DiscussionID, Name, DateLastComment, CategoryID')->From('Discussion')->WhereIn('DiscussionID', $DiscussionIDs)->Get();
$DiscussionData = Gdn_DataSet::Index($DiscussionData->ResultArray(), array('DiscussionID'));
foreach ($DiscussionData as $DiscussionID => $Discussion) {
$Category = CategoryModel::Categories($Discussion['CategoryID']);
if ($Category && $Category['PermsDiscussionsEdit']) {
$AllowedDiscussions[] = $DiscussionID;
}
}
$this->SetData('CountAllowed', count($AllowedDiscussions));
$CountNotAllowed = $CountCheckedDiscussions - count($AllowedDiscussions);
$this->SetData('CountNotAllowed', $CountNotAllowed);
if ($this->Form->AuthenticatedPostBack()) {
// Retrieve the category id
$CategoryID = $this->Form->GetFormValue('CategoryID');
$Category = CategoryModel::Categories($CategoryID);
$RedirectLink = $this->Form->GetFormValue('RedirectLink');
// User must have add permission on the target category
if (!$Category['PermsDiscussionsAdd']) {
throw ForbiddenException('@' . T('You do not have permission to add discussions to this category.'));
}
// Iterate and move.
foreach ($AllowedDiscussions as $DiscussionID) {
// Create the shadow redirect.
if ($RedirectLink) {
$Discussion = GetValue($DiscussionID, $DiscussionData);
$DiscussionModel->DefineSchema();
$MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name'));
$RedirectDiscussion = array('Name' => SliceString(sprintf(T('Moved: %s'), $Discussion['Name']), $MaxNameLength), 'DateInserted' => $Discussion['DateLastComment'], 'Type' => 'redirect', 'CategoryID' => $Discussion['CategoryID'], 'Body' => FormatString(T('This discussion has been <a href="{url,html}">moved</a>.'), array('url' => DiscussionUrl($Discussion))), 'Format' => 'Html', 'Closed' => TRUE);
$RedirectID = $DiscussionModel->Save($RedirectDiscussion);
if (!$RedirectID) {
$this->Form->SetValidationResults($DiscussionModel->ValidationResults());
break;
}
}
$DiscussionModel->SetField($DiscussionID, 'CategoryID', $CategoryID);
}
// Clear selections.
if ($ClearSelection) {
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
ModerationController::InformCheckedDiscussions($this);
}
if ($this->Form->ErrorCount() == 0) {
$this->JsonTarget('', '', 'Refresh');
}
}
$this->Render();
}