本文整理汇总了PHP中DiscussionModel类的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel类的具体用法?PHP DiscussionModel怎么用?PHP DiscussionModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DiscussionModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Build
protected function Build()
{
$DiscussionModel = new DiscussionModel();
$Offset = 0;
$Limit = 1000;
while ($Discussions = $DiscussionModel->Get($Offset, $Limit)) {
if (!$Discussions->NumRows()) {
break;
}
$Offset += $Discussions->NumRows();
$Day = 24 * 3600;
$Week = 7 * $Day;
$Month = 4 * $Week;
$Year = 12 * $Month;
$PriorityMatrix = array('hourly' => 1, 'daily' => 0.8, 'weekly' => 0.6, 'monthly' => 0.4, 'yearly' => 0.2);
while ($Discussion = $Discussions->NextRow()) {
$ChangeFreq = 'hourly';
$DiffDate = time() - strtotime($Discussion->DateLastComment);
$Priority = 1;
if ($DiffDate < $Day) {
$ChangeFreq = 'hourly';
} elseif ($DiffDate < $Week) {
$ChangeFreq = 'daily';
} elseif ($DiffDate < $Month) {
$ChangeFreq = 'weekly';
} elseif ($DiffDate < $Year) {
$ChangeFreq = 'monthly';
} else {
$ChangeFreq = 'yearly';
}
$this->MapItem(DiscussionLink($Discussion, FALSE), date('Y-m-d', strtotime($Discussion->DateLastComment)), $ChangeFreq, $PriorityMatrix[$ChangeFreq]);
}
}
$this->WriteIndex();
}
示例2: GetData
public function GetData($Limit = 10) {
$this->Data = FALSE;
if (Gdn::Session()->IsValid() && C('Vanilla.Modules.ShowBookmarkedModule', TRUE)) {
$BookmarkIDs = Gdn::SQL()
->Select('DiscussionID')
->From('UserDiscussion')
->Where('UserID', Gdn::Session()->UserID)
->Where('Bookmarked', 1)
->Get()->ResultArray();
$BookmarkIDs = ConsolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID');
if (count($BookmarkIDs)) {
$DiscussionModel = new DiscussionModel();
DiscussionModel::CategoryPermissions();
$DiscussionModel->SQL->WhereIn('d.DiscussionID', $BookmarkIDs);
$this->Data = $DiscussionModel->Get(
0,
$Limit
);
} else {
$this->Data = FALSE;
}
}
}
示例3: DiscussionsController_Participated_Create
public function DiscussionsController_Participated_Create(&$Sender, $Args)
{
$Sender->Permission('Garden.SignIn.Allow');
$Page = GetValue(0, $Args);
$Limit = GetValue(1, $Args);
list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
// Get Discussions
$DiscussionModel = new DiscussionModel();
$Sender->DiscussionData = $DiscussionModel->GetParticipated(Gdn::Session()->UserID, $Offset, $Limit);
$Sender->SetData('Discussions', $Sender->DiscussionData);
$CountDiscussions = $DiscussionModel->GetCountParticipated(Gdn::Session()->UserID);
$Sender->SetData('CountDiscussions', $CountDiscussions);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Sender->EventArguments['PagerType'] = 'Pager';
$Sender->FireEvent('BeforeBuildPager');
$Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/participated/%1$s');
$Sender->FireEvent('AfterBuildPager');
// Deliver JSON data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Add modules
$Sender->AddModule('NewDiscussionModule');
$Sender->AddModule('CategoriesModule');
$BookmarkedModule = new BookmarkedModule($Sender);
$BookmarkedModule->GetData();
$Sender->AddModule($BookmarkedModule);
$Sender->Render($this->GetView('participated.php'));
}
示例4: pluginController_quoteMention_create
public function pluginController_quoteMention_create($sender, $discussionID, $commentID, $username)
{
$sender->deliveryMethod(DELIVERY_METHOD_JSON);
$user = Gdn::userModel()->getByUsername($username);
$discussionModel = new DiscussionModel();
$discussion = $discussionModel->getID($discussionID);
if (!$user || !$discussion) {
throw notFoundException();
}
// Make sure this endpoint can't be used to snoop around.
$sender->permission('Vanilla.Discussions.View', true, 'Category', $discussion->PermissionCategoryID);
// Find the previous comment of the mentioned user in this discussion.
$item = Gdn::sql()->getWhere('Comment', ['DiscussionID' => $discussion->DiscussionID, 'InsertUserID' => $user->UserID, 'CommentID <' => $commentID], 'CommentID', 'desc', 1)->firstRow();
// The items ID in the DOM used for highlighting.
if ($item) {
$target = '#Comment_' . $item->CommentID;
// The mentioned user might be the discussion creator.
} elseif ($discussion->InsertUserID == $user->UserID) {
$item = $discussion;
$target = '#Discussion_' . $item->DiscussionID;
}
if (!$item) {
// A success response code always means that a comment was found.
$sender->statusCode(404);
}
$sender->renderData($item ? ['html' => nl2br(sliceString(Gdn_Format::plainText($item->Body, $item->Format), c('QuoteMention.MaxLength', 400))), 'target' => $target] : []);
}
示例5: GetData
public function GetData($Limit = 10)
{
$Session = Gdn::Session();
if ($Session->IsValid()) {
$DiscussionModel = new DiscussionModel();
$this->_DiscussionData = $DiscussionModel->Get(0, $Limit, array('w.Bookmarked' => '1', 'w.UserID' => $Session->UserID));
}
}
示例6: GetData
public function GetData($Limit = FALSE)
{
if (!$Limit) {
$Limit = $this->Limit;
}
$DiscussionModel = new DiscussionModel();
$this->SetData('Discussions', $DiscussionModel->Get(0, $Limit, array('Announce' => 'all')));
}
示例7: Advanced
/**
* Advanced settings.
*
* Allows setting configuration values via form elements.
*
* @since 2.0.0
* @access public
*/
public function Advanced() {
// Check permission
$this->Permission('Vanilla.Settings.Manage');
// Load up config options we'll be setting
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array(
'Vanilla.Discussions.PerPage',
'Vanilla.Comments.AutoRefresh',
'Vanilla.Comments.PerPage',
'Vanilla.Archive.Date',
'Vanilla.Archive.Exclude',
'Garden.EditContentTimeout'
));
// Set the model on the form.
$this->Form->SetModel($ConfigurationModel);
// If seeing the form for the first time...
if ($this->Form->AuthenticatedPostBack() === FALSE) {
// Apply the config settings to the form.
$this->Form->SetData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Vanilla.Discussions.PerPage', 'Required');
$ConfigurationModel->Validation->ApplyRule('Vanilla.Discussions.PerPage', 'Integer');
$ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.AutoRefresh', 'Integer');
$ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.PerPage', 'Required');
$ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.PerPage', 'Integer');
$ConfigurationModel->Validation->ApplyRule('Vanilla.Archive.Date', 'Date');
$ConfigurationModel->Validation->ApplyRule('Garden.EditContentTimeout', 'Integer');
// Grab old config values to check for an update.
$ArchiveDateBak = Gdn::Config('Vanilla.Archive.Date');
$ArchiveExcludeBak = (bool)Gdn::Config('Vanilla.Archive.Exclude');
// Save new settings
$Saved = $this->Form->Save();
if($Saved) {
$ArchiveDate = Gdn::Config('Vanilla.Archive.Date');
$ArchiveExclude = (bool)Gdn::Config('Vanilla.Archive.Exclude');
if($ArchiveExclude != $ArchiveExcludeBak || ($ArchiveExclude && $ArchiveDate != $ArchiveDateBak)) {
$DiscussionModel = new DiscussionModel();
$DiscussionModel->UpdateDiscussionCount('All');
}
$this->InformMessage(T("Your changes have been saved."));
}
}
$this->AddSideMenu('vanilla/settings/advanced');
$this->AddJsFile('settings.js');
$this->Title(T('Advanced Forum Settings'));
// Render default view (settings/advanced.php)
$this->Render();
}
示例8: DiscussionsController_Tagged_Create
/**
* Load discussions for a specific tag.
*/
public function DiscussionsController_Tagged_Create($Sender)
{
$Offset = GetValue('1', $Sender->RequestArgs, 'p1');
list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30));
$Sender->Tag = GetValue('0', $Sender->RequestArgs, '');
$Sender->Title(T('Tagged with ') . $Sender->Tag);
$Sender->Head->Title($Sender->Head->Title());
$Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged/' . $Sender->Tag, PageNumber($Offset, $Limit, TRUE)), TRUE));
if ($Sender->Head) {
$Sender->AddJsFile('discussions.js');
$Sender->AddJsFile('bookmark.js');
$Sender->AddJsFile('js/library/jquery.menu.js');
$Sender->AddJsFile('options.js');
$Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Add Modules
$Sender->AddModule('NewDiscussionModule');
$BookmarkedModule = new BookmarkedModule($Sender);
$BookmarkedModule->GetData();
$Sender->AddModule($BookmarkedModule);
$Sender->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$Tag = $DiscussionModel->SQL->Select()->From('Tag')->Where('Name', $Sender->Tag)->Get()->FirstRow();
$TagID = $Tag ? $Tag->TagID : 0;
$CountDiscussions = $Tag ? $Tag->CountDiscussions : 0;
$Sender->SetData('CountDiscussions', $CountDiscussions);
$Sender->AnnounceData = FALSE;
$Sender->SetData('Announcements', array(), TRUE);
$DiscussionModel->FilterToTagID = $TagID;
$Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
$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, $CountDiscussions, 'discussions/tagged/' . $Sender->Tag . '/%1$s');
// Deliver json data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Set a definition of the user's current timezone from the db. jQuery
// will pick this up, compare to the browser, and update the user's
// timezone if necessary.
$CurrentUser = Gdn::Session()->User;
if (is_object($CurrentUser)) {
$ClientHour = $CurrentUser->HourOffset + date('G', time());
$Sender->AddDefinition('SetClientHour', $ClientHour);
}
// Render the controller
$Sender->Render(PATH_PLUGINS . '/Tagging/views/taggeddiscussions.php');
}
示例9: gdn_dispatcher_notFound_handler
/**
* Use 404 handler to look for a SimplePage.
*/
public function gdn_dispatcher_notFound_handler($dispatcher, $args)
{
$requestUri = Gdn::Request()->Path();
$discussionModel = new DiscussionModel();
$result = $discussionModel->GetWhere(array('Type' => 'SimplePage', 'ForeignID' => $requestUri))->FirstRow(DATASET_TYPE_ARRAY);
// Page exists with requested slug, so dispatch; no redirect.
if ($discussionID = val('DiscussionID', $result)) {
SaveToConfig('SimplePage.Found', true, false);
Gdn::Dispatcher()->Dispatch('/discussion/' . $discussionID);
exit;
}
}
示例10: CategoriesController_RefreshCounts_Create
public function CategoriesController_RefreshCounts_Create($Sender)
{
$Sender->Permission('Vanilla.Categories.Manage');
$DiscussionModel = new DiscussionModel();
$CategoryModel = $Sender->CategoryModel;
$Categories = $CategoryModel->GetAll();
foreach ($Categories as $Category) {
$CategoryID = $Category->CategoryID;
$DiscussionModel->UpdateDiscussionCount($CategoryID);
}
// stash the inform message for later
Gdn::Session()->Stash('RefreshCountsMessage', T('RefreshCounts.CatComplete'));
Redirect('/vanilla/settings/managecategories');
}
示例11: getData
/**
* Get the data for the module.
*
* @param int|bool $limit Override the number of discussions to display.
*/
public function getData($limit = false)
{
if (!$limit) {
$limit = $this->Limit;
}
$discussionModel = new DiscussionModel();
$categoryIDs = $this->getCategoryIDs();
$where = array('Announce' => 'all');
if ($categoryIDs) {
$where['d.CategoryID'] = CategoryModel::filterCategoryPermissions($categoryIDs);
} else {
$discussionModel->Watching = true;
}
$this->setData('Discussions', $discussionModel->get(0, $limit, $where));
}
示例12: Award
public function Award($Sender, $User, $Criteria)
{
$NecroDate = strtotime($Criteria->Duration . ' ' . $Criteria->Period . ' ago');
// Get the last comment date from the parent discussion
$Args = $Sender->EventArguments;
$DiscussionID = $Args['FormPostValues']['DiscussionID'];
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->GetID($DiscussionID);
$LastCommentDate = strtotime($Discussion->DateLastComment);
if ($LastCommentDate < $NecroDate) {
return TRUE;
} else {
return FALSE;
}
}
示例13: DiscussionController_AutoExpire_Create
public function DiscussionController_AutoExpire_Create($Sender, $Args)
{
$DiscussionID = intval($Args[0]);
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->GetID($DiscussionID);
if (!Gdn::Session()->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Discussion->PermissionCategoryID)) {
throw PermissionException('Vanilla.Discussions.Close');
}
if (strtolower($Args[1]) == 'reset') {
Gdn::SQL()->Put('Discussion', array('AutoExpire' => 1, 'Closed' => 0, 'DateReOpened' => Gdn_Format::ToDateTime()), array('DiscussionID' => $DiscussionID));
} else {
$Expire = strtolower($Args[1]) == 'on' ? 1 : 0;
Gdn::SQL()->Put('Discussion', array('AutoExpire' => $Expire), array('DiscussionID' => $DiscussionID));
}
Redirect('discussion/' . $DiscussionID . '/' . Gdn_Format::Url($Discussion->Name));
}
示例14: RefetchPageInfo
/**
* Re-fetch a discussion's content based on its foreign url.
* @param type $DiscussionID
*/
public function RefetchPageInfo($DiscussionID)
{
// Make sure we are posting back.
if (!$this->Request->IsPostBack()) {
throw PermissionException('Javascript');
}
// Grab the discussion.
$Discussion = $this->DiscussionModel->GetID($DiscussionID);
if (!$Discussion) {
throw NotFoundException('Discussion');
}
// Make sure the user has permission to edit this discussion.
$this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
$ForeignUrl = GetValueR('Attributes.ForeignUrl', $Discussion);
if (!$ForeignUrl) {
throw new Gdn_UserException(T("This discussion isn't associated with a url."));
}
$Stub = $this->DiscussionModel->FetchPageInfo($ForeignUrl, TRUE);
// decho($Stub);
// die();
// Save the stub.
$this->DiscussionModel->SetField($DiscussionID, (array) $Stub);
// Send some of the stuff back.
if (isset($Stub['Name'])) {
$this->JsonTarget('.PageTitle h1', Gdn_Format::Text($Stub['Name']));
}
if (isset($Stub['Body'])) {
$this->JsonTarget("#Discussion_{$DiscussionID} .Message", Gdn_Format::To($Stub['Body'], $Stub['Format']));
}
$this->InformMessage('The page was successfully fetched.');
$this->Render('Blank', 'Utility', 'Dashboard');
}
示例15: getData
public function getData()
{
if (Gdn::session()->isValid()) {
$BookmarkIDs = Gdn::sql()->select('DiscussionID')->from('UserDiscussion')->where('UserID', Gdn::session()->UserID)->where('Bookmarked', 1)->get()->resultArray();
$BookmarkIDs = consolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID');
if (count($BookmarkIDs)) {
$DiscussionModel = new DiscussionModel();
DiscussionModel::CategoryPermissions();
$DiscussionModel->SQL->whereIn('d.DiscussionID', $BookmarkIDs);
$Bookmarks = $DiscussionModel->get(0, $this->Limit, array('w.Bookmarked' => '1'));
$this->setData('Bookmarks', $Bookmarks);
} else {
$this->setData('Bookmarks', new Gdn_DataSet());
}
}
}