本文整理汇总了PHP中DiscussionModel::SetProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::SetProperty方法的具体用法?PHP DiscussionModel::SetProperty怎么用?PHP DiscussionModel::SetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::SetProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: announce
/**
* Allows user to announce or unannounce a discussion.
*
* If the discussion isn't announced, this announces it.
* If it is already announced, this unannounces it.
* Announced discussions stay at the top of the discussions
* list regardless of how long ago the last comment was.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique discussion ID.
* @param string $TransientKey Single-use hash to prove intent.
*/
public function announce($DiscussionID = '', $Target = '')
{
$Discussion = $this->DiscussionModel->getID($DiscussionID);
if (!$Discussion) {
throw notFoundException('Discussion');
}
$this->permission('Vanilla.Discussions.Announce', true, 'Category', $Discussion->PermissionCategoryID);
if ($this->Form->authenticatedPostBack()) {
// Save the property.
$CacheKeys = array($this->DiscussionModel->getAnnouncementCacheKey(), $this->DiscussionModel->getAnnouncementCacheKey(val('CategoryID', $Discussion)));
$this->DiscussionModel->SQL->cache($CacheKeys);
$this->DiscussionModel->SetProperty($DiscussionID, 'Announce', (int) $this->Form->getFormValue('Announce', 0));
if ($Target) {
$this->RedirectUrl = url($Target);
}
} else {
if (!$Discussion->Announce) {
$Discussion->Announce = 2;
}
$this->Form->setData($Discussion);
}
$Discussion = (array) $Discussion;
$Category = CategoryModel::categories($Discussion['CategoryID']);
$this->setData('Discussion', $Discussion);
$this->setData('Category', $Category);
$this->title(t('Announce'));
$this->render();
}
示例2: Close
/**
* Allows user to close or re-open a discussion.
*
* If the discussion isn't closed, this closes it. If it is already
* closed, this re-opens it. Closed discussions may not have new
* comments added to them.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique discussion ID.
* @param string $TransientKey Single-use hash to prove intent.
*/
public function Close($DiscussionID = '', $TransientKey = '')
{
$this->_DeliveryType = DELIVERY_TYPE_BOOL;
$Session = Gdn::Session();
$State = '1';
if (is_numeric($DiscussionID) && $DiscussionID > 0 && $Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey)) {
$Discussion = $this->DiscussionModel->GetID($DiscussionID);
if ($Discussion) {
if ($Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
$State = $this->DiscussionModel->SetProperty($DiscussionID, 'Closed');
} else {
$State = $Discussion->Closed;
$this->Form->AddError('ErrPermission');
}
}
}
// Redirect to the front page
if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
$Target = GetIncomingValue('Target', 'discussions');
Redirect($Target);
}
$State = $State == '1' ? TRUE : FALSE;
$this->SetJson('State', $State);
$this->SetJson('LinkText', T($State ? 'Reopen' : 'Close'));
$this->InformMessage(T('Your changes have been saved.'));
$this->Render();
}
示例3: Announce
/**
* Allows user to announce or unannounce a discussion.
*
* If the discussion isn't announced, this announces it.
* If it is already announced, this unannounces it.
* Announced discussions stay at the top of the discussions
* list regardless of how long ago the last comment was.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique discussion ID.
* @param string $TransientKey Single-use hash to prove intent.
*/
public function Announce($DiscussionID = '', $Target = '')
{
$Discussion = $this->DiscussionModel->GetID($DiscussionID);
if (!$Discussion) {
throw NotFoundException('Discussion');
}
$this->Permission('Vanilla.Discussions.Announce', TRUE, 'Category', $Discussion->PermissionCategoryID);
if ($this->Form->AuthenticatedPostBack()) {
// Save the property.
$CacheKeys = array('Announcements', 'Announcements_' . GetValue('CategoryID', $Discussion));
$this->DiscussionModel->SQL->Cache($CacheKeys);
$this->DiscussionModel->SetProperty($DiscussionID, 'Announce', (int) $this->Form->GetFormValue('Announce', 0));
if ($Target) {
$this->RedirectUrl = Url($Target);
}
} else {
if (!$Discussion->Announce) {
$Discussion->Announce = 2;
}
$this->Form->SetData($Discussion);
}
$Discussion = (array) $Discussion;
$Category = CategoryModel::Categories($Discussion['CategoryID']);
$this->SetData('Discussion', $Discussion);
$this->SetData('Category', $Category);
$this->Title(T('Announce'));
$this->Render();
}
示例4: PostController_Comment_Create
/**
* @param PostController $Sender
* @param array $Args
* @return mixed
*/
public function PostController_Comment_Create($Sender, $Args = array())
{
if ($Sender->Form->AuthenticatedPostBack()) {
$Sender->Form->SetModel($Sender->CommentModel);
// Grab the discussion for use later.
$DiscussionID = $Sender->Form->GetFormValue('DiscussionID');
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->GetID($DiscussionID);
// Check to see if the discussion is supposed to be in private...
$WhisperConversationID = GetValueR('Attributes.WhisperConversationID', $Discussion);
if ($WhisperConversationID === TRUE) {
// There isn't a conversation so we want to create one.
$Sender->Form->SetFormValue('Whisper', TRUE);
$WhisperUserIDs = GetValueR('Attributes.WhisperUserIDs', $Discussion);
$Sender->Form->SetFormValue('RecipientUserID', $WhisperUserIDs);
} elseif ($WhisperConversationID) {
// There is already a conversation.
$Sender->Form->SetFormValue('Whisper', TRUE);
$Sender->Form->SetFormValue('ConversationID', $WhisperConversationID);
}
$Whisper = $Sender->Form->GetFormValue('Whisper') && GetIncomingValue('Type') != 'Draft';
$WhisperTo = trim($Sender->Form->GetFormValue('To'));
$ConversationID = $Sender->Form->GetFormValue('ConversationID');
// If this isn't a whisper then post as normal.
if (!$Whisper) {
return call_user_func_array(array($Sender, 'Comment'), $Args);
}
$ConversationModel = new ConversationModel();
$ConversationMessageModel = new ConversationMessageModel();
if ($ConversationID > 0) {
$Sender->Form->SetModel($ConversationMessageModel);
} else {
// We have to remove the blank conversation ID or else the model won't validate.
$FormValues = $Sender->Form->FormValues();
unset($FormValues['ConversationID']);
$FormValues['Subject'] = GetValue('Name', $Discussion);
$Sender->Form->FormValues($FormValues);
$Sender->Form->SetModel($ConversationModel);
$ConversationModel->Validation->ApplyRule('DiscussionID', 'Required');
}
$ID = $Sender->Form->Save($ConversationMessageModel);
if ($Sender->Form->ErrorCount() > 0) {
$Sender->ErrorMessage($Sender->Form->Errors());
} else {
if ($WhisperConversationID === TRUE) {
$Discussion->Attributes['WhisperConversationID'] = $ID;
$DiscussionModel->SetProperty($DiscussionID, 'Attributes', serialize($Discussion->Attributes));
}
$LastCommentID = GetValue('LastCommentID', $Discussion);
$MessageID = GetValue('LastMessageID', $ConversationMessageModel, FALSE);
// Randomize the querystring to force the browser to refresh.
$Rand = mt_rand(10000, 99999);
if ($LastCommentID) {
// Link to the last comment.
$HashID = $MessageID ? 'w' . $MessageID : $LastCommentID;
$Sender->RedirectUrl = Url("discussion/comment/{$LastCommentID}?rand={$Rand}#Comment_{$HashID}", TRUE);
} else {
// Link to the discussion.
$Hash = $MessageID ? "Comment_w{$MessageID}" : 'Item_1';
$Name = rawurlencode(GetValue('Name', $Discussion, 'x'));
$Sender->RedirectUrl = Url("discussion/{$DiscussionID}/{$Name}?rand={$Rand}#{$Hash}", TRUE);
}
}
$Sender->Render();
} else {
return call_user_func_array(array($Sender, 'Comment'), $Args);
}
}
示例5: DiscussionController_afterDiscussionBody_handler
public function DiscussionController_afterDiscussionBody_handler($Sender)
{
$Discussion = $Sender->EventArguments['Discussion'];
$EventDate = $Sender->EventArguments['Discussion']->DiscussionEventDate;
if ($EventDate) {
$Guests = $Discussion->DiscussionEventGuests;
if ($Guests) {
$Guests = json_decode($Guests, true);
}
$DiscussionModel = new DiscussionModel();
$Session = Gdn::Session();
if ($Session->isValid()) {
$UserId = $Session->User->UserID;
} else {
$UserId = false;
}
if (!$this->Form) {
$this->Form = new Gdn_Form();
}
if ($this->Form->authenticatedPostBack()) {
$Data = $this->Form->FormValues();
if ($Data['Type'] == 'Subscribe') {
if (!$Guests) {
$Guests = array();
}
if (!array_key_exists($UserId, $Guests) && array_key_exists('Remark', $Data)) {
$Guests[$UserId] = $Data['Remark'];
$DiscussionModel->SetProperty($Discussion->DiscussionID, 'DiscussionEventGuests', json_encode($Guests));
}
} else {
if ($Data['Type'] == 'Unsubscribe') {
if (array_key_exists($UserId, $Guests)) {
unset($Guests[$UserId]);
$DiscussionModel->SetProperty($Discussion->DiscussionID, 'DiscussionEventGuests', json_encode($Guests));
}
}
}
}
self::displayEventGuests($Guests);
echo $this->Form->Open();
echo $this->Form->Errors();
if ($UserId) {
if (!$Guests || !array_key_exists($UserId, $Guests)) {
$this->Form->AddHidden('Type', 'Subscribe', true);
echo $Sender->Form->label(t('Remark'), 'DiscussionEventRemark'), ' ';
echo $this->Form->TextBox('Remark');
echo $this->Form->getHidden();
echo $this->Form->Close(t('Subscribe'));
} else {
$this->Form->AddHidden('Type', 'Unsubscribe', true);
echo $this->Form->getHidden();
echo $this->Form->Close(t('Unsubscribe'));
}
}
}
}