本文整理汇总了PHP中DiscussionModel::canEdit方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::canEdit方法的具体用法?PHP DiscussionModel::canEdit怎么用?PHP DiscussionModel::canEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::canEdit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: optionsList
function optionsList($Discussion)
{
$Sender = Gdn::controller();
$Session = Gdn::session();
if ($Session->isValid() && $Sender->ShowOptions) {
$Sender->Options = '';
// Dismiss an announcement
if (c('Vanilla.Discussions.Dismiss', 1) && $Discussion->Announce == '1' && $Discussion->Dismissed != '1') {
$Sender->Options .= '<li>' . anchor(t('Dismiss'), "vanilla/discussion/dismissannouncement?discussionid={$Discussion->DiscussionID}", 'DismissAnnouncement Hijack') . '</li>';
}
// Edit discussion
if (DiscussionModel::canEdit($Discussion)) {
$Sender->Options .= '<li>' . anchor(t('Edit'), 'vanilla/post/editdiscussion/' . $Discussion->DiscussionID, 'EditDiscussion') . '</li>';
}
// Announce discussion
if ($Session->checkPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
$Sender->Options .= '<li>' . anchor(t('Announce...'), '/discussion/announce?discussionid=' . $Discussion->DiscussionID . '&Target=' . urlencode($Sender->SelfUrl), 'Popup AnnounceDiscussion') . '</li>';
}
// Sink discussion
if ($Session->checkPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
$NewSink = (int) (!$Discussion->Sink);
$Sender->Options .= '<li>' . anchor(t($Discussion->Sink == '1' ? 'Unsink' : 'Sink'), "vanilla/discussion/sink?discussionid={$Discussion->DiscussionID}&sink={$NewSink}", 'SinkDiscussion Hijack') . '</li>';
}
// Close discussion
if ($Session->checkPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
$NewClosed = (int) (!$Discussion->Closed);
$Sender->Options .= '<li>' . anchor(t($Discussion->Closed == '1' ? 'Reopen' : 'Close'), "/discussion/close?discussionid={$Discussion->DiscussionID}&close={$NewClosed}", 'CloseDiscussion Hijack') . '</li>';
}
// Delete discussion
if ($Session->checkPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
$Sender->Options .= '<li>' . anchor(t('Delete'), '/discussion/delete?discussionid=' . $Discussion->DiscussionID, 'DeleteDiscussion Popup') . '</li>';
}
// Allow plugins to add options.
$Sender->EventArguments['Discussion'] = $Discussion;
$Sender->fireEvent('DiscussionOptions');
if ($Sender->Options != '') {
$Result = '<span class="ToggleFlyout OptionsMenu">' . '<span class="OptionsTitle" title="' . t('Options') . '">' . t('Options') . '</span>' . '<span class="SpFlyoutHandle"></span>' . '<ul class="Flyout MenuItems">' . $Sender->Options . '</ul>' . '</span>';
return $Result;
}
}
return '';
}
示例2: discussion
/**
* Create or update a discussion.
*
* @since 2.0.0
* @access public
*
* @param int $CategoryID Unique ID of the category to add the discussion to.
*/
public function discussion($CategoryUrlCode = '')
{
// Override CategoryID if categories are disabled
$UseCategories = $this->ShowCategorySelector = (bool) c('Vanilla.Categories.Use');
if (!$UseCategories) {
$CategoryUrlCode = '';
}
// Setup head
$this->addJsFile('jquery.autosize.min.js');
$this->addJsFile('autosave.js');
$this->addJsFile('post.js');
$Session = Gdn::session();
Gdn_Theme::section('PostDiscussion');
// Set discussion, draft, and category data
$DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : '';
$DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0;
$Category = false;
$CategoryModel = new CategoryModel();
if (isset($this->Discussion)) {
$this->CategoryID = $this->Discussion->CategoryID;
$Category = CategoryModel::categories($this->CategoryID);
} elseif ($CategoryUrlCode != '') {
$Category = CategoryModel::categories($CategoryUrlCode);
if ($Category) {
$this->CategoryID = val('CategoryID', $Category);
}
}
if ($Category) {
$this->Category = (object) $Category;
$this->setData('Category', $Category);
$this->Form->addHidden('CategoryID', $this->Category->CategoryID);
if (val('DisplayAs', $this->Category) == 'Discussions' && !$DraftID) {
$this->ShowCategorySelector = false;
} else {
// Get all our subcategories to add to the category if we are in a Header or Categories category.
$this->Context = CategoryModel::getSubtree($this->CategoryID);
}
} else {
$this->CategoryID = 0;
$this->Category = null;
}
$CategoryData = $this->ShowCategorySelector ? CategoryModel::categories() : false;
// Check permission
if (isset($this->Discussion)) {
// Make sure that content can (still) be edited.
$CanEdit = DiscussionModel::canEdit($this->Discussion);
if (!$CanEdit) {
throw permissionException('Vanilla.Discussions.Edit');
}
// Make sure only moderators can edit closed things
if ($this->Discussion->Closed) {
$this->permission('Vanilla.Discussions.Edit', true, 'Category', $this->Category->PermissionCategoryID);
}
$this->Form->setFormValue('DiscussionID', $this->Discussion->DiscussionID);
$this->title(t('Edit Discussion'));
if ($this->Discussion->Type) {
$this->setData('Type', $this->Discussion->Type);
} else {
$this->setData('Type', 'Discussion');
}
} else {
// Permission to add.
if ($this->Category) {
$this->permission('Vanilla.Discussions.Add', true, 'Category', $this->Category->PermissionCategoryID);
} else {
$this->permission('Vanilla.Discussions.Add');
}
$this->title(t('New Discussion'));
}
touchValue('Type', $this->Data, 'Discussion');
// See if we should hide the category dropdown.
if ($this->ShowCategorySelector) {
$AllowedCategories = CategoryModel::getByPermission('Discussions.Add', $this->Form->getValue('CategoryID', $this->CategoryID), ['Archived' => 0, 'AllowDiscussions' => 1], ['AllowedDiscussionTypes' => $this->Data['Type']]);
if (count($AllowedCategories) == 1) {
$AllowedCategory = array_pop($AllowedCategories);
$this->ShowCategorySelector = false;
$this->Form->addHidden('CategoryID', $AllowedCategory['CategoryID']);
if ($this->Form->isPostBack() && !$this->Form->getFormValue('CategoryID')) {
$this->Form->setFormValue('CategoryID', $AllowedCategory['CategoryID']);
}
}
}
// Set the model on the form
$this->Form->setModel($this->DiscussionModel);
if (!$this->Form->isPostBack()) {
// Prep form with current data for editing
if (isset($this->Discussion)) {
$this->Form->setData($this->Discussion);
} elseif (isset($this->Draft)) {
$this->Form->setData($this->Draft);
} else {
if ($this->Category !== null) {
//.........这里部分代码省略.........
示例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;
$CountCheckedDiscussions = count($DiscussionIDs);
$Discussions = $DiscussionModel->SQL->whereIn('DiscussionID', $DiscussionIDs)->get('Discussion')->resultArray();
// Make sure none of the selected discussions are ghost redirects.
$discussionTypes = array_column($Discussions, 'Type');
if (in_array('redirect', $discussionTypes)) {
throw new Gdn_UserException('You cannot merge redirects.', 400);
}
// Check that the user has permission to edit all discussions
foreach ($Discussions as $discussion) {
if (!DiscussionModel::canEdit($discussion)) {
throw permissionException('@' . t('You do not have permission to edit all of the discussions you are trying to merge.'));
}
}
$Sender->setData('DiscussionIDs', $DiscussionIDs);
$Sender->setData('CountCheckedDiscussions', $CountCheckedDiscussions);
$Sender->setData('Discussions', $Discussions);
// 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');
}
示例4: getDiscussionOptions
function getDiscussionOptions($Discussion = null)
{
$Options = array();
$Sender = Gdn::controller();
$Session = Gdn::session();
if ($Discussion == null) {
$Discussion = $Sender->data('Discussion');
}
$CategoryID = val('CategoryID', $Discussion);
if (!$CategoryID && property_exists($Sender, 'Discussion')) {
$CategoryID = val('CategoryID', $Sender->Discussion);
}
$PermissionCategoryID = val('PermissionCategoryID', $Discussion, val('PermissionCategoryID', $Discussion));
// Build the $Options array based on current user's permission.
// Can the user edit the discussion?
$CanEdit = DiscussionModel::canEdit($Discussion, $TimeLeft);
if ($CanEdit) {
if ($TimeLeft) {
$TimeLeft = ' (' . Gdn_Format::Seconds($TimeLeft) . ')';
}
$Options['EditDiscussion'] = array('Label' => t('Edit') . $TimeLeft, 'Url' => '/post/editdiscussion/' . $Discussion->DiscussionID);
}
// Can the user announce?
if ($Session->checkPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $PermissionCategoryID)) {
$Options['AnnounceDiscussion'] = array('Label' => t('Announce'), 'Url' => '/discussion/announce?discussionid=' . $Discussion->DiscussionID . '&Target=' . urlencode($Sender->SelfUrl . '#Head'), 'Class' => 'AnnounceDiscussion Popup');
}
// Can the user sink?
if ($Session->checkPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $PermissionCategoryID)) {
$NewSink = (int) (!$Discussion->Sink);
$Options['SinkDiscussion'] = array('Label' => t($Discussion->Sink ? 'Unsink' : 'Sink'), 'Url' => "/discussion/sink?discussionid={$Discussion->DiscussionID}&sink={$NewSink}", 'Class' => 'SinkDiscussion Hijack');
}
// Can the user close?
if ($Session->checkPermission('Vanilla.Discussions.Close', TRUE, 'Category', $PermissionCategoryID)) {
$NewClosed = (int) (!$Discussion->Closed);
$Options['CloseDiscussion'] = array('Label' => t($Discussion->Closed ? 'Reopen' : 'Close'), 'Url' => "/discussion/close?discussionid={$Discussion->DiscussionID}&close={$NewClosed}", 'Class' => 'CloseDiscussion Hijack');
}
if ($CanEdit && valr('Attributes.ForeignUrl', $Discussion)) {
$Options['RefetchPage'] = array('Label' => t('Refetch Page'), 'Url' => '/discussion/refetchpageinfo.json?discussionid=' . $Discussion->DiscussionID, 'Class' => 'RefetchPage Hijack');
}
// Can the user move?
if ($CanEdit && $Session->checkPermission('Garden.Moderation.Manage')) {
$Options['MoveDiscussion'] = array('Label' => t('Move'), 'Url' => '/moderation/confirmdiscussionmoves?discussionid=' . $Discussion->DiscussionID, 'Class' => 'MoveDiscussion Popup');
}
// Can the user delete?
if ($Session->checkPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $PermissionCategoryID)) {
$Category = CategoryModel::categories($CategoryID);
$Options['DeleteDiscussion'] = array('Label' => t('Delete Discussion'), 'Url' => '/discussion/delete?discussionid=' . $Discussion->DiscussionID . '&target=' . urlencode(CategoryUrl($Category)), 'Class' => 'DeleteDiscussion Popup');
}
// DEPRECATED (as of 2.1)
$Sender->EventArguments['Type'] = 'Discussion';
// Allow plugins to add options.
$Sender->EventArguments['DiscussionOptions'] =& $Options;
$Sender->EventArguments['Discussion'] = $Discussion;
$Sender->fireEvent('DiscussionOptions');
return $Options;
}
示例5: getDiscussionOptionsDropdown
/**
* Constructs an options dropdown menu for a discussion.
*
* @param object|array|null $discussion The discussion to get the dropdown options for.
* @return DropdownModule A dropdown consisting of discussion options.
* @throws Exception
*/
function getDiscussionOptionsDropdown($discussion = null)
{
$dropdown = new DropdownModule();
$sender = Gdn::controller();
$session = Gdn::session();
if ($discussion == null) {
$discussion = $sender->data('Discussion');
}
$categoryID = val('CategoryID', $discussion);
if (!$categoryID && property_exists($sender, 'Discussion')) {
trace('Getting category ID from controller Discussion property.');
$categoryID = val('CategoryID', $sender->Discussion);
}
$discussionID = $discussion->DiscussionID;
$categoryUrl = urlencode(categoryUrl(CategoryModel::categories($categoryID)));
$permissionCategoryID = val('PermissionCategoryID', $discussion, val('PermissionCategoryID', $discussion));
// Permissions
$canEdit = DiscussionModel::canEdit($discussion, $timeLeft);
$canAnnounce = $session->checkPermission('Vanilla.Discussions.Announce', true, 'Category', $permissionCategoryID);
$canSink = $session->checkPermission('Vanilla.Discussions.Sink', true, 'Category', $permissionCategoryID);
$canClose = $session->checkPermission('Vanilla.Discussions.Close', true, 'Category', $permissionCategoryID);
$canDelete = $session->checkPermission('Vanilla.Discussions.Delete', true, 'Category', $permissionCategoryID);
$canMove = $canEdit && $session->checkPermission('Garden.Moderation.Manage');
$canRefetch = $canEdit && valr('Attributes.ForeignUrl', $discussion);
$canDismiss = c('Vanilla.Discussions.Dismiss', 1) && $discussion->Announce == '1' && $discussion->Dismissed != '1' && $session->isValid();
if ($canEdit && $timeLeft) {
$timeLeft = ' (' . Gdn_Format::seconds($timeLeft) . ')';
}
$dropdown->addLinkIf($canDismiss, t('Dismiss'), "vanilla/discussion/dismissannouncement?discussionid={$discussionID}", 'dismiss', 'DismissAnnouncement Hijack')->addLinkIf($canEdit, t('Edit') . $timeLeft, '/post/editdiscussion/' . $discussionID, 'edit')->addLinkIf($canAnnounce, t('Announce'), '/discussion/announce?discussionid=' . $discussionID, 'announce', 'AnnounceDiscussion Popup')->addLinkIf($canSink, t($discussion->Sink ? 'Unsink' : 'Sink'), '/discussion/sink?discussionid=' . $discussionID . '&sink=' . (int) (!$discussion->Sink), 'sink', 'SinkDiscussion Hijack')->addLinkIf($canClose, t($discussion->Closed ? 'Reopen' : 'Close'), '/discussion/close?discussionid=' . $discussionID . '&close=' . (int) (!$discussion->Closed), 'close', 'CloseDiscussion Hijack')->addLinkIf($canRefetch, t('Refetch Page'), '/discussion/refetchpageinfo.json?discussionid=' . $discussionID, 'refetch', 'RefetchPage Hijack')->addLinkIf($canMove, t('Move'), '/moderation/confirmdiscussionmoves?discussionid=' . $discussionID, 'move', 'MoveDiscussion Popup')->addLinkIf($canDelete, t('Delete Discussion'), '/discussion/delete?discussionid=' . $discussionID . '&target=' . $categoryUrl, 'delete', 'DeleteDiscussion Popup');
// DEPRECATED
$options = [];
$sender->EventArguments['DiscussionOptions'] =& $options;
$sender->EventArguments['Discussion'] = $discussion;
$sender->fireEvent('DiscussionOptions');
// Backwards compatability
$dropdown = discussionOptionsToDropdown($options, $dropdown);
// Allow plugins to edit the dropdown.
$sender->EventArguments['DiscussionOptionsDropdown'] =& $dropdown;
$sender->EventArguments['Discussion'] = $discussion;
$sender->fireEvent('DiscussionOptionsDropdown');
return $dropdown;
}