本文整理汇总了PHP中CategoryModel::categories方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::categories方法的具体用法?PHP CategoryModel::categories怎么用?PHP CategoryModel::categories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::categories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$vars = array_merge(array('cid' => -1, 'original' => -1, 'order' => 'hot'), $_GET);
$total = BlogModel::blogs($vars, true);
$Page = new Newpage($total, 10);
$this->assign('page', $Page->getPage());
$this->assign($vars);
$categories = CategoryModel::categories();
$this->assign('categories', $categories);
$blogs = BlogModel::blogs($vars, false, $Page->limit);
foreach ($blogs as &$row) {
$row['content'] = strip_tags($row['content']);
$row['user'] = model('User')->formatForApi($row, $row['uid']);
}
$this->assign('blogs', $blogs);
$hot = BlogModel::hotBlogs(5);
foreach ($hot as &$row) {
$row['user'] = model('User')->formatForApi($row, $row['uid']);
}
$this->assign('hot_blogs', $hot);
//$hot_users = UserModel::hotUsers(5);
$hot_users = BlogModel::hotUsers(5);
if (is_array($hot_users) and $hot_users) {
foreach ($hot_users as &$user) {
$user = model('User')->formatForApi($user, $user['uid']);
}
}
//$this->ajaxReturn($hot_users);
$this->assign('hot_users', $hot_users);
$this->display();
}
示例2: getCategory
/**
* Get data for the configured category.
*
* @return array|null Array if the configured category is valid. Otherwise, null.
*/
public function getCategory()
{
if (!isset($this->category)) {
$this->category = CategoryModel::categories($this->categoryID);
}
return $this->category;
}
示例3: toString
/**
* Render the module.
*
* @return string
*/
public function toString()
{
// Set CategoryID if we have one.
if ($this->CategoryID === null) {
$this->CategoryID = Gdn::controller()->data('Category.CategoryID', false);
}
// Allow plugins and themes to modify parameters.
Gdn::controller()->EventArguments['NewDiscussionModule'] =& $this;
Gdn::controller()->fireEvent('BeforeNewDiscussionButton');
// Make sure the user has the most basic of permissions first.
$PermissionCategory = CategoryModel::permissionCategory($this->CategoryID);
if ($this->CategoryID) {
$Category = CategoryModel::categories($this->CategoryID);
$HasPermission = Gdn::session()->checkPermission('Vanilla.Discussions.Add', true, 'Category', val('CategoryID', $PermissionCategory));
} else {
$HasPermission = Gdn::session()->checkPermission('Vanilla.Discussions.Add', true, 'Category', 'any');
}
// Determine if this is a guest & we're using "New Discussion" button as call to action.
$PrivilegedGuest = $this->ShowGuests && !Gdn::session()->isValid();
// No module for you!
if (!$HasPermission && !$PrivilegedGuest) {
return '';
}
// Grab the allowed discussion types.
$DiscussionTypes = CategoryModel::allowedDiscussionTypes($PermissionCategory);
foreach ($DiscussionTypes as $Key => $Type) {
if (isset($Type['AddPermission']) && !Gdn::session()->checkPermission($Type['AddPermission'])) {
unset($DiscussionTypes[$Key]);
continue;
}
$Url = val('AddUrl', $Type);
if (!$Url) {
continue;
}
if (isset($Category)) {
$Url .= '/' . rawurlencode(val('UrlCode', $Category));
}
// Present a signin redirect for a $PrivilegedGuest.
if (!$HasPermission) {
$Url = $this->GuestUrl . '?Target=' . $Url;
}
$this->addButton(t(val('AddText', $Type)), $Url);
}
// Add QueryString to URL if one is defined.
if ($this->QueryString && $HasPermission) {
foreach ($this->Buttons as &$Row) {
$Row['Url'] .= (strpos($Row['Url'], '?') !== false ? '&' : '?') . $this->QueryString;
}
}
return parent::toString();
}
示例4: getData
/**
* Get the data for this module.
*/
protected function getData()
{
// Allow plugins to set different data.
$this->fireEvent('GetData');
if ($this->Data) {
return;
}
$Categories = CategoryModel::categories();
$Categories2 = $Categories;
// Filter out the categories we aren't watching.
foreach ($Categories2 as $i => $Category) {
if (!$Category['PermsDiscussionsView'] || !$Category['Following']) {
unset($Categories[$i]);
}
}
$Data = new Gdn_DataSet($Categories);
$Data->DatasetType(DATASET_TYPE_ARRAY);
$Data->DatasetType(DATASET_TYPE_OBJECT);
$this->Data = $Data;
}
示例5: discussionsController_unanswered_create
/**
*
*
* @param DiscussionsController $sender Sending controller instance.
* @param array $args Event arguments.
*/
public function discussionsController_unanswered_create($sender, $args)
{
$sender->View = 'Index';
$sender->setData('_PagerUrl', 'discussions/unanswered/{Page}');
// Be sure to display every unanswered question (ie from groups)
$categories = CategoryModel::categories();
$this->EventArguments['Categories'] =& $categories;
$this->fireEvent('UnansweredBeforeSetCategories');
$sender->setCategoryIDs(array_keys($categories));
$sender->index(val(0, $args, 'p1'));
$this->InUnanswered = true;
}
示例6: getMessagesForLocation
/**
* Get what messages are active for a template location.
*
* @param $Location
* @param array $Exceptions
* @param null $CategoryID
* @return array|null
*/
public function getMessagesForLocation($Location, $Exceptions = array('[Base]'), $CategoryID = null)
{
$Session = Gdn::session();
$Prefs = $Session->getPreference('DismissedMessages', array());
if (count($Prefs) == 0) {
$Prefs[] = 0;
}
$category = null;
if (!empty($CategoryID)) {
$category = CategoryModel::categories($CategoryID);
}
$Exceptions = array_map('strtolower', $Exceptions);
list($Application, $Controller, $Method) = explode('/', strtolower($Location));
if (Gdn::cache()->activeEnabled()) {
// Get the messages from the cache.
$Messages = self::messages();
$Result = array();
foreach ($Messages as $MessageID => $Message) {
if (in_array($MessageID, $Prefs) || !$Message['Enabled']) {
continue;
}
$MApplication = strtolower($Message['Application']);
$MController = strtolower($Message['Controller']);
$MMethod = strtolower($Message['Method']);
$Visible = false;
if (in_array($MController, $Exceptions)) {
$Visible = true;
} elseif ($MApplication == $Application && $MController == $Controller && $MMethod == $Method) {
$Visible = true;
}
$Visible = $Visible && self::inCategory($CategoryID, val('CategoryID', $Message), val('IncludeSubcategories', $Message));
if ($category !== null) {
$Visible &= CategoryModel::checkPermission($category, 'Vanilla.Discussions.View');
}
if ($Visible) {
$Result[] = $Message;
}
}
return $Result;
}
$Result = $this->SQL->select()->from('Message')->where('Enabled', '1')->beginWhereGroup()->whereIn('Controller', $Exceptions)->orOp()->beginWhereGroup()->orWhere('Application', $Application)->where('Controller', $Controller)->where('Method', $Method)->endWhereGroup()->endWhereGroup()->whereNotIn('MessageID', $Prefs)->orderBy('Sort', 'asc')->get()->resultArray();
$Result = array_filter($Result, function ($Message) use($Session, $category) {
$visible = MessageModel::inCategory(val('CategoryID', $category, null), val('CategoryID', $Message), val('IncludeSubcategories', $Message));
if ($category !== null) {
$visible = $visible && $Session->checkPermission('Vanilla.Discussions.View', true, 'Category', $category['PermissionCategoryID']);
}
return $visible;
});
return $Result;
}
示例7: editCategory
/**
* Editing a category.
*
* @since 2.0.0
* @access public
*
* @param int $CategoryID Unique ID of the category to be updated.
*/
public function editCategory($CategoryID = '')
{
// Check permission
$this->permission('Garden.Community.Manage');
// Set up models
$RoleModel = new RoleModel();
$PermissionModel = Gdn::permissionModel();
$this->Form->setModel($this->CategoryModel);
if (!$CategoryID && $this->Form->authenticatedPostBack()) {
if ($ID = $this->Form->getFormValue('CategoryID')) {
$CategoryID = $ID;
}
}
// Get category data
$this->Category = $this->CategoryModel->getID($CategoryID);
if (!$this->Category) {
throw notFoundException('Category');
}
$this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
// Set up head
$this->addJsFile('jquery.alphanumeric.js');
$this->addJsFile('categories.js');
$this->addJsFile('jquery.gardencheckboxgrid.js');
$this->title(t('Edit Category'));
$this->addSideMenu('vanilla/settings/managecategories');
// Make sure the form knows which item we are editing.
$this->Form->addHidden('CategoryID', $CategoryID);
$this->setData('CategoryID', $CategoryID);
// Load all roles with editable permissions
$this->RoleArray = $RoleModel->getArray();
$this->fireEvent('AddEditCategory');
if ($this->Form->authenticatedPostBack()) {
$this->setupDiscussionTypes($this->Category);
$Upload = new Gdn_Upload();
$TmpImage = $Upload->validateUpload('PhotoUpload', false);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image
$Parts = $Upload->saveAs($TmpImage, $ImageBaseName);
$this->Form->setFormValue('Photo', $Parts['SaveName']);
}
$this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints'));
if ($this->Form->save()) {
$Category = CategoryModel::categories($CategoryID);
$this->setData('Category', $Category);
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
redirect('vanilla/settings/managecategories');
}
}
} else {
$this->Form->setData($this->Category);
$this->setupDiscussionTypes($this->Category);
$this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
}
// Get all of the currently selected role/permission combinations for this junction.
$Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
$Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
$this->setData('PermissionData', $Permissions, true);
}
// Render default view
$this->render();
}
示例8: delete
/**
* Delete a comment.
*
* This is a hard delete that completely removes it from the database.
* Events: DeleteComment, BeforeDeleteComment.
*
* @since 2.0.0
* @access public
*
* @param int $CommentID Unique ID of the comment to be deleted.
* @param array $Options Additional options for the delete.
* @param bool Always returns TRUE.
*/
public function delete($CommentID, $Options = array())
{
$this->EventArguments['CommentID'] = $CommentID;
$Comment = $this->getID($CommentID, DATASET_TYPE_ARRAY);
if (!$Comment) {
return false;
}
$Discussion = $this->SQL->getWhere('Discussion', array('DiscussionID' => $Comment['DiscussionID']))->firstRow(DATASET_TYPE_ARRAY);
// Decrement the UserDiscussion comment count if the user has seen this comment
$Offset = $this->GetOffset($CommentID);
$this->SQL->update('UserDiscussion')->set('CountComments', 'CountComments - 1', false)->where('DiscussionID', $Comment['DiscussionID'])->where('CountComments >', $Offset)->put();
$this->EventArguments['Discussion'] = $Discussion;
$this->fireEvent('DeleteComment');
$this->fireEvent('BeforeDeleteComment');
// Log the deletion.
$Log = val('Log', $Options, 'Delete');
LogModel::insert($Log, 'Comment', $Comment, val('LogOptions', $Options, array()));
// Delete the comment.
$this->SQL->delete('Comment', array('CommentID' => $CommentID));
// Update the comment count
$this->UpdateCommentCount($Discussion, array('Slave' => false));
// Update the user's comment count
$this->UpdateUser($Comment['InsertUserID']);
// Update the category.
$Category = CategoryModel::categories(val('CategoryID', $Discussion));
if ($Category && $Category['LastCommentID'] == $CommentID) {
$CategoryModel = new CategoryModel();
$CategoryModel->SetRecentPost($Category['CategoryID']);
}
// Clear the page cache.
$this->RemovePageCache($Comment['DiscussionID']);
return true;
}
示例9: inCategory
/**
* Whether we are in (or optionally below) a category.
*
* @param int $NeedleCategoryID
* @param int $HaystackCategoryID
* @param bool $IncludeSubcategories
* @return bool
*/
protected static function inCategory($NeedleCategoryID, $HaystackCategoryID, $IncludeSubcategories = false)
{
if (!$HaystackCategoryID) {
return true;
}
if ($NeedleCategoryID == $HaystackCategoryID) {
return true;
}
if ($IncludeSubcategories) {
$Cat = CategoryModel::categories($NeedleCategoryID);
for ($i = 0; $i < 10; $i++) {
if (!$Cat) {
break;
}
if ($Cat['CategoryID'] == $HaystackCategoryID) {
return true;
}
$Cat = CategoryModel::categories($Cat['ParentCategoryID']);
}
}
return false;
}
示例10: edit
/**
* Form to edit an existing message.
*
* @since 2.0.0
* @access public
*/
public function edit($MessageID = '')
{
$this->addJsFile('jquery.autosize.min.js');
$this->addJsFile('messages.js');
$this->permission('Garden.Community.Manage');
$this->addSideMenu('dashboard/message');
// Generate some Controller & Asset data arrays
$this->setData('Locations', $this->_getLocationData());
$this->AssetData = $this->_getAssetData();
// Set the model on the form.
$this->Form->setModel($this->MessageModel);
$this->Message = $this->MessageModel->getID($MessageID);
$this->Message = $this->MessageModel->defineLocation($this->Message);
// Make sure the form knows which item we are editing.
if (is_numeric($MessageID) && $MessageID > 0) {
$this->Form->addHidden('MessageID', $MessageID);
}
$CategoriesData = CategoryModel::categories();
$Categories = array();
foreach ($CategoriesData as $Row) {
if ($Row['CategoryID'] < 0) {
continue;
}
$Categories[$Row['CategoryID']] = str_repeat(' ', max(0, $Row['Depth'] - 1)) . $Row['Name'];
}
$this->setData('Categories', $Categories);
// If seeing the form for the first time...
if (!$this->Form->authenticatedPostBack()) {
$this->Form->setData($this->Message);
} else {
if ($MessageID = $this->Form->save()) {
// Reset the message cache
$this->MessageModel->setMessageCache();
// Redirect
$this->informMessage(t('Your changes have been saved.'));
//$this->RedirectUrl = url('dashboard/message');
}
}
$this->render();
}
示例11: writeDiscussion
function writeDiscussion($Discussion, &$Sender, &$Session)
{
$CssClass = CssClass($Discussion);
$DiscussionUrl = $Discussion->Url;
$Category = CategoryModel::categories($Discussion->CategoryID);
if ($Session->UserID) {
$DiscussionUrl .= '#latest';
}
$Sender->EventArguments['DiscussionUrl'] =& $DiscussionUrl;
$Sender->EventArguments['Discussion'] =& $Discussion;
$Sender->EventArguments['CssClass'] =& $CssClass;
$First = UserBuilder($Discussion, 'First');
$Last = UserBuilder($Discussion, 'Last');
$Sender->EventArguments['FirstUser'] =& $First;
$Sender->EventArguments['LastUser'] =& $Last;
$Sender->fireEvent('BeforeDiscussionName');
$DiscussionName = $Discussion->Name;
if ($DiscussionName == '') {
$DiscussionName = t('Blank Discussion Topic');
}
$Sender->EventArguments['DiscussionName'] =& $DiscussionName;
static $FirstDiscussion = TRUE;
if (!$FirstDiscussion) {
$Sender->fireEvent('BetweenDiscussion');
} else {
$FirstDiscussion = FALSE;
}
$Discussion->CountPages = ceil($Discussion->CountComments / $Sender->CountCommentsPerPage);
?>
<li id="Discussion_<?php
echo $Discussion->DiscussionID;
?>
" class="<?php
echo $CssClass;
?>
">
<?php
if (!property_exists($Sender, 'CanEditDiscussions')) {
$Sender->CanEditDiscussions = val('PermsDiscussionsEdit', CategoryModel::categories($Discussion->CategoryID)) && c('Vanilla.AdminCheckboxes.Use');
}
$Sender->fireEvent('BeforeDiscussionContent');
// WriteOptions($Discussion, $Sender, $Session);
?>
<span class="Options">
<?php
echo OptionsList($Discussion);
echo BookmarkButton($Discussion);
?>
</span>
<div class="ItemContent Discussion">
<div class="Title">
<?php
echo AdminCheck($Discussion, array('', ' ')) . anchor($DiscussionName, $DiscussionUrl);
$Sender->fireEvent('AfterDiscussionTitle');
?>
</div>
<div class="Meta Meta-Discussion">
<?php
WriteTags($Discussion);
?>
<span class="MItem MCount ViewCount"><?php
printf(PluralTranslate($Discussion->CountViews, '%s view html', '%s views html', t('%s view'), t('%s views')), BigPlural($Discussion->CountViews, '%s view'));
?>
</span>
<span class="MItem MCount CommentCount"><?php
printf(PluralTranslate($Discussion->CountComments, '%s comment html', '%s comments html', t('%s comment'), t('%s comments')), BigPlural($Discussion->CountComments, '%s comment'));
?>
</span>
<span class="MItem MCount DiscussionScore Hidden"><?php
$Score = $Discussion->Score;
if ($Score == '') {
$Score = 0;
}
printf(Plural($Score, '%s point', '%s points', BigPlural($Score, '%s point')));
?>
</span>
<?php
echo NewComments($Discussion);
$Sender->fireEvent('AfterCountMeta');
if ($Discussion->LastCommentID != '') {
echo ' <span class="MItem LastCommentBy">' . sprintf(t('Most recent by %1$s'), userAnchor($Last)) . '</span> ';
echo ' <span class="MItem LastCommentDate">' . Gdn_Format::date($Discussion->LastDate, 'html') . '</span>';
} else {
echo ' <span class="MItem LastCommentBy">' . sprintf(t('Started by %1$s'), userAnchor($First)) . '</span> ';
echo ' <span class="MItem LastCommentDate">' . Gdn_Format::date($Discussion->FirstDate, 'html');
if ($Source = val('Source', $Discussion)) {
echo ' ' . sprintf(t('via %s'), t($Source . ' Source', $Source));
}
echo '</span> ';
}
if ($Sender->data('_ShowCategoryLink', true) && c('Vanilla.Categories.Use') && $Category) {
echo wrap(Anchor(htmlspecialchars($Discussion->Category), CategoryUrl($Discussion->CategoryUrlCode)), 'span', array('class' => 'MItem Category ' . $Category['CssClass']));
}
$Sender->fireEvent('DiscussionMeta');
?>
</div>
</div>
<?php
$Sender->fireEvent('AfterDiscussionContent');
//.........这里部分代码省略.........
示例12: populateForm
/**
* Pre-populate the form with values from the query string.
*
* @param Gdn_Form $Form
* @param bool $LimitCategories Whether to turn off the category dropdown if there is only one category to show.
*/
protected function populateForm($Form)
{
$Get = $this->Request->get();
$Get = array_change_key_case($Get);
$Values = arrayTranslate($Get, array('name' => 'Name', 'tags' => 'Tags', 'body' => 'Body'));
foreach ($Values as $Key => $Value) {
$Form->setValue($Key, $Value);
}
if (isset($Get['category'])) {
$Category = CategoryModel::categories($Get['category']);
if ($Category && $Category['PermsDiscussionsAdd']) {
$Form->setValue('CategoryID', $Category['CategoryID']);
}
}
}
示例13: foreach
</thead>
<tbody>
<?php
$Alt = FALSE;
foreach ($this->MessageData->result() as $Message) {
$Message = $this->MessageModel->DefineLocation($Message);
$Alt = $Alt ? FALSE : TRUE;
?>
<tr id="<?php
echo $Message->MessageID;
echo $Alt ? '" class="Alt' : '';
?>
">
<td class="Info nowrap"><?php
printf(t('%1$s on %2$s'), arrayValue($Message->AssetTarget, $this->_GetAssetData(), 'Custom Location'), arrayValue($Message->Location, $this->_GetLocationData(), 'Custom Page'));
if (val('CategoryID', $Message) && ($Category = CategoryModel::categories($Message->CategoryID))) {
echo '<div>' . anchor($Category['Name'], CategoryUrl($Category));
if (val('IncludeSubcategories', $Message)) {
echo ' ' . t('and subcategories');
}
echo '</div>';
}
?>
<div>
<strong><?php
echo $Message->Enabled == '1' ? t('Enabled') : t('Disabled');
?>
</strong>
<?php
echo anchor(t('Edit'), '/dashboard/message/edit/' . $Message->MessageID, 'EditMessage SmallButton');
echo anchor(t('Delete'), '/dashboard/message/delete/' . $Message->MessageID . '/' . $Session->TransientKey(), 'DeleteMessage SmallButton');
示例14: 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');
}
示例15: discussionsController_Tagged_create
/**
* Load discussions for a specific tag.
* @param DiscussionsController $Sender
*/
public function discussionsController_Tagged_create($Sender)
{
Gdn_Theme::section('DiscussionList');
$Args = $Sender->RequestArgs;
$Get = array_change_key_case($Sender->Request->get());
if ($UseCategories = c('Plugins.Tagging.UseCategories')) {
// The url is in the form /category/tag/p1
$CategoryCode = val(0, $Args);
$Tag = val(1, $Args);
$Page = val(2, $Args);
} else {
// The url is in the form /tag/p1
$CategoryCode = '';
$Tag = val(0, $Args);
$Page = val(1, $Args);
}
// Look for explcit values.
$CategoryCode = val('category', $Get, $CategoryCode);
$Tag = val('tag', $Get, $Tag);
$Page = val('page', $Get, $Page);
$Category = CategoryModel::categories($CategoryCode);
$Tag = stringEndsWith($Tag, '.rss', true, true);
list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
$MultipleTags = strpos($Tag, ',') !== false;
$Sender->setData('Tag', $Tag, true);
$TagModel = TagModel::instance();
$RecordCount = false;
if (!$MultipleTags) {
$Tags = $TagModel->getWhere(array('Name' => $Tag))->resultArray();
if (count($Tags) == 0) {
throw notFoundException('Page');
}
if (count($Tags) > 1) {
foreach ($Tags as $TagRow) {
if ($TagRow['CategoryID'] == val('CategoryID', $Category)) {
break;
}
}
} else {
$TagRow = array_pop($Tags);
}
$Tags = $TagModel->getRelatedTags($TagRow);
$RecordCount = $TagRow['CountDiscussions'];
$Sender->setData('CountDiscussions', $RecordCount);
$Sender->setData('Tags', $Tags);
$Sender->setData('Tag', $TagRow);
$ChildTags = $TagModel->getChildTags($TagRow['TagID']);
$Sender->setData('ChildTags', $ChildTags);
}
$Sender->title(htmlspecialchars($TagRow['FullName']));
$UrlTag = rawurlencode($Tag);
if (urlencode($Tag) == $Tag) {
$Sender->canonicalUrl(url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, true)), true));
$FeedUrl = url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, true, false)), '//');
} else {
$Sender->canonicalUrl(url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true)) . '?Tag=' . $UrlTag, true));
$FeedUrl = url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true, false), 'feed.rss') . '?Tag=' . $UrlTag, '//');
}
if ($Sender->Head) {
$Sender->addJsFile('discussions.js');
$Sender->Head->addRss($FeedUrl, $Sender->Head->title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Add Modules
$Sender->addModule('NewDiscussionModule');
$Sender->addModule('DiscussionFilterModule');
$Sender->addModule('BookmarkedModule');
$Sender->setData('Category', false, true);
$Sender->AnnounceData = false;
$Sender->setData('Announcements', array(), true);
$DiscussionModel = new DiscussionModel();
$TagModel->setTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->get('op', 'or'));
$Sender->DiscussionData = $DiscussionModel->get($Offset, $Limit, array('Announce' => 'all'));
$Sender->setData('Discussions', $Sender->DiscussionData, true);
$Sender->setJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->configure($Offset, $Limit, $RecordCount, '');
$Sender->View = c('Vanilla.Discussions.Layout');
/*
// If these don't equal, then there is a category that should be inserted.
if ($UseCategories && $Category && $TagRow['FullName'] != val('Name', $Category)) {
$Sender->Data['Breadcrumbs'][] = array('Name' => $Category['Name'], 'Url' => TagUrl($TagRow));
}
$Sender->Data['Breadcrumbs'][] = array('Name' => $TagRow['FullName'], 'Url' => '');
*/
// Render the controller.
$this->View = c('Vanilla.Discussions.Layout') == 'table' ? 'table' : 'index';
$Sender->render($this->View, 'discussions', 'vanilla');
}