当前位置: 首页>>代码示例>>PHP>>正文


PHP CategoryModel::DefaultCategory方法代码示例

本文整理汇总了PHP中CategoryModel::DefaultCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::DefaultCategory方法的具体用法?PHP CategoryModel::DefaultCategory怎么用?PHP CategoryModel::DefaultCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CategoryModel的用法示例。


在下文中一共展示了CategoryModel::DefaultCategory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Save

 /**
  * Inserts or updates the discussion via form values.
  * 
  * Events: BeforeSaveDiscussion, AfterSaveDiscussion.
  *
  * @since 2.0.0
  * @access public
  * 
  * @param array $FormPostValues Data sent from the form model.
  * @return int $DiscussionID Unique ID of the discussion.
  */
 public function Save($FormPostValues)
 {
     $Session = Gdn::Session();
     // Define the primary key in this model's table.
     $this->DefineSchema();
     // Add & apply any extra validation rules:
     $this->Validation->ApplyRule('Body', 'Required');
     $this->Validation->AddRule('MeAction', 'function:ValidateMeAction');
     $this->Validation->ApplyRule('Body', 'MeAction');
     $MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength');
     if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
         $this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
         $this->Validation->ApplyRule('Body', 'Length');
     }
     // Validate category permissions.
     $CategoryID = GetValue('CategoryID', $FormPostValues);
     if ($CategoryID > 0) {
         $Category = CategoryModel::Categories($CategoryID);
         if ($Category && !$Session->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('PermissionCategoryID', $Category))) {
             $this->Validation->AddValidationResult('CategoryID', 'You do not have permission to post in this category');
         }
     }
     // Get the DiscussionID from the form so we know if we are inserting or updating.
     $DiscussionID = ArrayValue('DiscussionID', $FormPostValues, '');
     // See if there is a source ID.
     if (GetValue('SourceID', $FormPostValues)) {
         $DiscussionID = $this->SQL->GetWhere('Discussion', ArrayTranslate($FormPostValues, array('Source', 'SourceID')))->Value('DiscussionID');
         if ($DiscussionID) {
             $FormPostValues['DiscussionID'] = $DiscussionID;
         }
     } elseif (GetValue('ForeignID', $FormPostValues)) {
         $DiscussionID = $this->SQL->GetWhere('Discussion', array('ForeignID' => $FormPostValues['ForeignID']))->Value('DiscussionID');
         if ($DiscussionID) {
             $FormPostValues['DiscussionID'] = $DiscussionID;
         }
     }
     $Insert = $DiscussionID == '' ? TRUE : FALSE;
     $this->EventArguments['Insert'] = $Insert;
     if ($Insert) {
         unset($FormPostValues['DiscussionID']);
         // If no categoryid is defined, grab the first available.
         if (!GetValue('CategoryID', $FormPostValues) && !C('Vanilla.Categories.Use')) {
             $FormPostValues['CategoryID'] = GetValue('CategoryID', CategoryModel::DefaultCategory(), -1);
         }
         $this->AddInsertFields($FormPostValues);
         // The UpdateUserID used to be required. Just add it if it still is.
         if (!$this->Schema->GetProperty('UpdateUserID', 'AllowNull', TRUE)) {
             $FormPostValues['UpdateUserID'] = $FormPostValues['InsertUserID'];
         }
         // $FormPostValues['LastCommentUserID'] = $Session->UserID;
         $FormPostValues['DateLastComment'] = $FormPostValues['DateInserted'];
     } else {
         // Add the update fields.
         $this->AddUpdateFields($FormPostValues);
     }
     // Set checkbox values to zero if they were unchecked
     if (ArrayValue('Announce', $FormPostValues, '') === FALSE) {
         $FormPostValues['Announce'] = 0;
     }
     if (ArrayValue('Closed', $FormPostValues, '') === FALSE) {
         $FormPostValues['Closed'] = 0;
     }
     if (ArrayValue('Sink', $FormPostValues, '') === FALSE) {
         $FormPostValues['Sink'] = 0;
     }
     //	Prep and fire event
     $this->EventArguments['FormPostValues'] =& $FormPostValues;
     $this->EventArguments['DiscussionID'] = $DiscussionID;
     $this->FireEvent('BeforeSaveDiscussion');
     // Validate the form posted values
     $this->Validate($FormPostValues, $Insert);
     $ValidationResults = $this->ValidationResults();
     // If the body is not required, remove it's validation errors.
     $BodyRequired = C('Vanilla.DiscussionBody.Required', TRUE);
     if (!$BodyRequired && array_key_exists('Body', $ValidationResults)) {
         unset($ValidationResults['Body']);
     }
     if (count($ValidationResults) == 0) {
         // If the post is new and it validates, make sure the user isn't spamming
         if (!$Insert || !$this->CheckForSpam('Discussion')) {
             // Get all fields on the form that relate to the schema
             $Fields = $this->Validation->SchemaValidationFields();
             // Get DiscussionID if one was sent
             $DiscussionID = intval(ArrayValue('DiscussionID', $Fields, 0));
             // Remove the primary key from the fields for saving
             $Fields = RemoveKeyFromArray($Fields, 'DiscussionID');
             $StoredCategoryID = FALSE;
             if ($DiscussionID > 0) {
                 // Updating
//.........这里部分代码省略.........
开发者ID:bishopb,项目名称:vanilla,代码行数:101,代码来源:class.discussionmodel.php

示例2: DiscussionModel

 * @copyright 2009-2016 Vanilla Forums Inc.
 * @license http://www.opensource.org/licenses/gpl-2.0.php GNU GPL v2
 * @since 2.0
 * @package Vanilla
 */
$SQL = Gdn::database()->sql();
// Only do this once, ever.
$Row = $SQL->get('Discussion', '', 'asc', 1)->firstRow(DATASET_TYPE_ARRAY);
if ($Row) {
    return;
}
$DiscussionModel = new DiscussionModel();
// Prep default content
$DiscussionTitle = "BAM! You’ve got a sweet forum";
$DiscussionBody = "There&rsquo;s nothing sweeter than a fresh new forum, ready to welcome your community. A Vanilla Forum has all the bits and pieces you need to build an awesome discussion platform customized to your needs. Here&rsquo;s a few tips:\n<ul>\n   <li>Use the <a href=\"/dashboard/settings/gettingstarted\">Getting Started</a> list in the Dashboard to configure your site.</li>\n   <li>Don&rsquo;t use too many categories. We recommend 3-8. Keep it simple!</li>\n   <li>&ldquo;Announce&rdquo; a discussion (click the gear) to stick to the top of the list, and &ldquo;Close&rdquo; it to stop further comments.</li>\n   <li>Use &ldquo;Sink&rdquo; to take attention away from a discussion. New comments will no longer bring it back to the top of the list.</li>\n   <li>Bookmark a discussion (click the star) to get notifications for new comments. You can edit notification settings from your profile.</li>\n</ul>\nGo ahead and edit or delete this discussion, then spread the word to get this place cooking. Cheers!";
$CommentBody = "This is the first comment on your site and it&rsquo;s an important one.\n\nDon&rsquo;t see your must-have feature? We keep Vanilla nice and simple by default. Use <b>addons</b> to get the special sauce your community needs.\n\nNot sure which addons to enable? Our favorites are Button Bar and Tagging. They&rsquo;re almost always a great start.";
$WallBody = "Ping! An activity post is a public way to talk at someone. When you update your status here, it posts it on your activity feed.";
// Prep content meta data
$SystemUserID = Gdn::userModel()->GetSystemUserID();
$TargetUserID = Gdn::session()->UserID;
$Now = Gdn_Format::toDateTime();
$CategoryID = val('CategoryID', CategoryModel::DefaultCategory());
// Get wall post type ID
$WallCommentTypeID = $SQL->getWhere('ActivityType', array('Name' => 'WallPost'))->value('ActivityTypeID');
// Insert first discussion & comment
$DiscussionID = $SQL->Options('Ignore', true)->insert('Discussion', array('Name' => t('StubDiscussionTitle', $DiscussionTitle), 'Body' => t('StubDiscussionBody', $DiscussionBody), 'Format' => 'Html', 'CategoryID' => $CategoryID, 'ForeignID' => 'stub', 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now, 'DateLastComment' => $Now, 'LastCommentUserID' => $SystemUserID, 'CountComments' => 1));
$CommentID = $SQL->insert('Comment', array('DiscussionID' => $DiscussionID, 'Body' => t('StubCommentBody', $CommentBody), 'Format' => 'Html', 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now));
$SQL->update('Discussion')->set('LastCommentID', $CommentID)->where('DiscussionID', $DiscussionID)->put();
$DiscussionModel->UpdateDiscussionCount($CategoryID);
// Insert first wall post
$SQL->insert('Activity', array('Story' => t('StubWallBody', $WallBody), 'Format' => 'Html', 'HeadlineFormat' => '{RegardingUserID,you} &rarr; {ActivityUserID,you}', 'NotifyUserID' => -1, 'ActivityUserID' => $TargetUserID, 'RegardingUserID' => $SystemUserID, 'ActivityTypeID' => $WallCommentTypeID, 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now, 'DateUpdated' => $Now));
开发者ID:sitexa,项目名称:vanilla,代码行数:31,代码来源:stub.php

示例3: DiscussionModel

 * Vanilla stub content for a new forum.
 *
 * Called by VanillaHooks::Setup() to insert stub content upon enabling app.
 * @package Vanilla
 */
// Only do this once, ever.
$DiscussionModel = new DiscussionModel();
if ($DiscussionModel->GetCount()) {
    return;
}
$SQL = Gdn::Database()->SQL();
$DiscussionModel = new DiscussionModel();
// Prep default content
$DiscussionTitle = "BAM! You&rsquo;ve got a sweet forum";
$DiscussionBody = "There&rsquo;s nothing sweeter than a fresh new forum, ready to welcome your community. A Vanilla Forum has all the bits and pieces you need to build an awesome discussion platform customized to your needs. Here&rsquo;s a few tips:\n<ul>\n   <li>Use the <a href=\"/dashboard/settings/gettingstarted\">Getting Started</a> list in the Dashboard to configure your site.</li>\n   <li>Don&rsquo;t use too many categories. We recommend 3-8. Keep it simple!</li>\n   <li>&ldquo;Announce&rdquo; a discussion (click the gear) to stick to the top of the list, and &ldquo;Close&rdquo; it to stop further comments.</li>\n   <li>Use &ldquo;Sink&rdquo; to take attention away from a discussion. New comments will no longer bring it back to the top of the list.</li>\n   <li>Bookmark a discussion (click the star) to get notifications for new comments. You can edit notification settings from your profile.</li>\n</ul>\nGo ahead and edit or delete this discussion, then spread the word to get this place cooking. Cheers!";
$CommentBody = "This is the first comment on your site and it&rsquo;s an important one. \n\nDon&rsquo;t see your must-have feature? We keep Vanilla nice and simple by default. Use <b>addons</b> to get the special sauce your community needs.\n\nNot sure which addons to enable? Our favorites are Button Bar and Tagging. They&rsquo;re almost always a great start.";
$WallBody = "Ping! An activity post is a public way to talk at someone. When you update your status here, it posts it on your activity feed.";
// Prep content meta data
$SystemUserID = Gdn::UserModel()->GetSystemUserID();
$TargetUserID = Gdn::Session()->UserID;
$Now = Gdn_Format::ToDateTime();
$CategoryID = GetValue('CategoryID', CategoryModel::DefaultCategory());
// Get wall post type ID
$WallCommentTypeID = $SQL->GetWhere('ActivityType', array('Name' => 'WallPost'))->Value('ActivityTypeID');
// Insert first discussion & comment
$DiscussionID = $SQL->Insert('Discussion', array('Name' => T('StubDiscussionTitle', $DiscussionTitle), 'Body' => T('StubDiscussionBody', $DiscussionBody), 'Format' => 'Html', 'CategoryID' => $CategoryID, 'ForeignID' => 'stub', 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now, 'DateLastComment' => $Now, 'LastCommentUserID' => $SystemUserID, 'CountComments' => 1));
$CommentID = $SQL->Insert('Comment', array('DiscussionID' => $DiscussionID, 'Body' => T('StubCommentBody', $CommentBody), 'Format' => 'Html', 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now));
$SQL->Update('Discussion')->Set('LastCommentID', $CommentID)->Where('DiscussionID', $DiscussionID)->Put();
$DiscussionModel->UpdateDiscussionCount($CategoryID);
// Insert first wall post
$SQL->Insert('Activity', array('Story' => T('StubWallBody', $WallBody), 'Format' => 'Html', 'HeadlineFormat' => '{RegardingUserID,you} &rarr; {ActivityUserID,you}', 'NotifyUserID' => -1, 'ActivityUserID' => $TargetUserID, 'RegardingUserID' => $SystemUserID, 'ActivityTypeID' => $WallCommentTypeID, 'InsertUserID' => $SystemUserID, 'DateInserted' => $Now, 'DateUpdated' => $Now));
开发者ID:bishopb,项目名称:vanilla,代码行数:31,代码来源:stub.php


注:本文中的CategoryModel::DefaultCategory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。