get() публичный Метод

Sorts results based on config options Vanilla.Discussions.SortField and Vanilla.Discussions.SortDirection. Events: BeforeGet, AfterAddColumns.
С версии: 2.0.0
public get ( integer $Offset = '0', integer $Limit = '', array $Wheres = '', array $AdditionalFields = null ) : Gdn_DataSet
$Offset integer Number of discussions to skip.
$Limit integer Max number of discussions to return.
$Wheres array SQL conditions.
$AdditionalFields array Allows selection of additional fields as Alias=>Table.Fieldname.
Результат Gdn_DataSet SQL result.
Пример #1
0
 /**
  * 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));
 }
Пример #2
0
 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());
         }
     }
 }
Пример #3
0
 /**
  * Homepage & single addon view.
  *
  * @param string $ID The addon to view.
  * @throws Exception Addon not found.
  */
 public function index($ID = '')
 {
     if ($ID != '') {
         $Addon = $this->AddonModel->getSlug($ID, true);
         if (!is_array($Addon)) {
             throw notFoundException('Addon');
         } else {
             $this->addCssFile('confidence.css');
             $AddonID = $Addon['AddonID'];
             $this->setData($Addon);
             $Description = val('Description', $Addon);
             if ($Description) {
                 $this->Head->addTag('meta', array('name' => 'description', 'content' => Gdn_Format::plainText($Description, false)));
             }
             $this->addCssFile('fancyzoom.css');
             $this->addJsFile('fancyzoom.js');
             $this->addJsFile('addon.js');
             $PictureModel = new Gdn_Model('AddonPicture');
             $this->PictureData = $PictureModel->getWhere(array('AddonID' => $AddonID));
             $DiscussionModel = new DiscussionModel();
             $this->DiscussionData = $DiscussionModel->get(0, 50, array('AddonID' => $AddonID));
             $this->View = 'addon';
             $this->title($this->data('Name') . ' ' . $this->data('Version'));
             // Set the canonical url.
             $this->canonicalUrl(url('/addon/' . AddonModel::slug($Addon, false), true));
             $this->loadConfidenceRecord($Addon);
         }
     } else {
         $this->View = 'browse';
         $this->browse();
         return;
     }
     $this->addModule('AddonHelpModule');
     $this->setData('_Types', AddonModel::$Types);
     $this->setData('_TypesPlural', AddonModel::$TypesPlural);
     $this->render();
 }
Пример #4
0
 /**
  * Record the user's watch data.
  *
  * @since 2.0.0
  * @access public
  *
  * @param object $Discussion Discussion being watched.
  * @param int $Limit Max number to get.
  * @param int $Offset Number to skip.
  * @param int $TotalComments Total in entire discussion (hard limit).
  */
 public function setWatch($Discussion, $Limit, $Offset, $TotalComments)
 {
     $NewComments = false;
     $Session = Gdn::session();
     if ($Session->UserID > 0) {
         // Max comments we could have seen
         $CountWatch = $Limit + $Offset;
         if ($CountWatch > $TotalComments) {
             $CountWatch = $TotalComments;
         }
         // This dicussion looks familiar...
         if (is_numeric($Discussion->CountCommentWatch)) {
             if ($CountWatch < $Discussion->CountCommentWatch) {
                 $CountWatch = $Discussion->CountCommentWatch;
             }
             if (isset($Discussion->DateLastViewed)) {
                 $NewComments |= Gdn_Format::toTimestamp($Discussion->DateLastComment) > Gdn_Format::toTimestamp($Discussion->DateLastViewed);
             }
             if ($TotalComments > $Discussion->CountCommentWatch) {
                 $NewComments |= true;
             }
             // Update the watch data.
             if ($NewComments) {
                 // Only update the watch if there are new comments.
                 $this->SQL->put('UserDiscussion', array('CountComments' => $CountWatch, 'DateLastViewed' => Gdn_Format::toDateTime()), array('UserID' => $Session->UserID, 'DiscussionID' => $Discussion->DiscussionID));
             }
         } else {
             // Make sure the discussion isn't archived.
             $ArchiveDate = c('Vanilla.Archive.Date', false);
             if (!$ArchiveDate || Gdn_Format::toTimestamp($Discussion->DateLastComment) > Gdn_Format::toTimestamp($ArchiveDate)) {
                 $NewComments = true;
                 // Insert watch data.
                 $this->SQL->Options('Ignore', true);
                 $this->SQL->insert('UserDiscussion', array('UserID' => $Session->UserID, 'DiscussionID' => $Discussion->DiscussionID, 'CountComments' => $CountWatch, 'DateLastViewed' => Gdn_Format::toDateTime()));
             }
         }
         /**
          * Fuzzy way of trying to automatically mark a cateogyr read again
          * if the user reads all the comments on the first few pages.
          */
         // If this discussion is in a category that has been marked read,
         // check if reading this thread causes it to be completely read again
         $CategoryID = val('CategoryID', $Discussion);
         if ($CategoryID) {
             $Category = CategoryModel::categories($CategoryID);
             if ($Category) {
                 $DateMarkedRead = val('DateMarkedRead', $Category);
                 if ($DateMarkedRead) {
                     // Fuzzy way of looking back about 2 pages into the past
                     $LookBackCount = c('Vanilla.Discussions.PerPage', 50) * 2;
                     // Find all discussions with content from after DateMarkedRead
                     $DiscussionModel = new DiscussionModel();
                     $Discussions = $DiscussionModel->get(0, 101, array('CategoryID' => $CategoryID, 'DateLastComment>' => $DateMarkedRead));
                     unset($DiscussionModel);
                     // Abort if we get back as many as we asked for, meaning a
                     // lot has happened.
                     $NumDiscussions = $Discussions->numRows();
                     if ($NumDiscussions <= $LookBackCount) {
                         // Loop over these and see if any are still unread
                         $MarkAsRead = true;
                         while ($Discussion = $Discussions->NextRow(DATASET_TYPE_ARRAY)) {
                             if ($Discussion['Read']) {
                                 continue;
                             }
                             $MarkAsRead = false;
                             break;
                         }
                         // Mark this category read if all the new content is read
                         if ($MarkAsRead) {
                             $CategoryModel = new CategoryModel();
                             $CategoryModel->SaveUserTree($CategoryID, array('DateMarkedRead' => Gdn_Format::toDateTime()));
                             unset($CategoryModel);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Display discussions started by the user.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $Offset Number of discussions to skip.
  */
 public function mine($Page = 'p1')
 {
     $this->permission('Garden.SignIn.Allow');
     Gdn_Theme::section('DiscussionList');
     // Set criteria & get discussions data
     list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
     $Session = Gdn::session();
     $Wheres = array('d.InsertUserID' => $Session->UserID);
     $DiscussionModel = new DiscussionModel();
     $this->DiscussionData = $DiscussionModel->get($Offset, $Limit, $Wheres);
     $this->setData('Discussions', $this->DiscussionData);
     $CountDiscussions = $this->setData('CountDiscussions', $DiscussionModel->getCount($Wheres));
     $this->View = 'index';
     if (c('Vanilla.Discussions.Layout') === 'table') {
         $this->View = 'table';
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->EventArguments['PagerType'] = 'MorePager';
     $this->fireEvent('BeforeBuildMinePager');
     $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
     $this->Pager->MoreCode = 'More Discussions';
     $this->Pager->LessCode = 'Newer Discussions';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($Offset, $Limit, $CountDiscussions, 'discussions/mine/%1$s');
     $this->setData('_PagerUrl', 'discussions/mine/{Page}');
     $this->setData('_Page', $Page);
     $this->setData('_Limit', $Limit);
     $this->fireEvent('AfterBuildMinePager');
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
         $this->View = 'discussions';
     }
     // Add modules
     $this->addModule('DiscussionFilterModule');
     $this->addModule('NewDiscussionModule');
     $this->addModule('CategoriesModule');
     $this->addModule('BookmarkedModule');
     // Render view
     $this->setData('Title', t('My Discussions'));
     $this->setData('Breadcrumbs', array(array('Name' => t('My Discussions'), 'Url' => '/discussions/mine')));
     $this->render();
 }
 /**
  * Show all categories and few discussions from each.
  *
  * @param string $Category The url code of the parent category.
  * @since 2.0.0
  * @access public
  */
 public function discussions($Category = '')
 {
     // Setup head
     $this->addJsFile('discussions.js');
     $this->Menu->highlightRoute('/discussions');
     if (!$this->title()) {
         $Title = c('Garden.HomepageTitle');
         if ($Title) {
             $this->title($Title, '');
         } else {
             $this->title(t('All Categories'));
         }
     }
     if (!$Category) {
         $this->Description(c('Garden.Description', null));
     }
     Gdn_Theme::section('CategoryDiscussionList');
     // Set the category follow toggle before we load category data so that it affects the category query appropriately.
     $CategoryFollowToggleModule = new CategoryFollowToggleModule($this);
     $CategoryFollowToggleModule->SetToggle();
     $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories');
     if ($Category) {
         $Subtree = CategoryModel::GetSubtree($Category, false);
         $CategoryIDs = consolidateArrayValuesByKey($Subtree, 'CategoryID');
         $Categories = $this->CategoryModel->GetFull($CategoryIDs)->resultArray();
     } else {
         $Categories = $this->CategoryModel->GetFull()->resultArray();
     }
     $this->setData('Categories', $Categories);
     // Get category data and discussions
     $this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5);
     $DiscussionModel = new DiscussionModel();
     $this->CategoryDiscussionData = array();
     foreach ($this->CategoryData->result() as $Category) {
         if ($Category->CategoryID > 0) {
             $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all'));
         }
     }
     // Add modules
     $this->addModule('NewDiscussionModule');
     $this->addModule('DiscussionFilterModule');
     $this->addModule('CategoriesModule');
     $this->addModule('BookmarkedModule');
     $this->addModule($CategoryFollowToggleModule);
     // Set view and render
     $this->View = 'discussions';
     $this->canonicalUrl(url('/categories', true));
     $Path = $this->fetchViewLocation('helper_functions', 'discussions', false, false);
     if ($Path) {
         include_once $Path;
     }
     // For GetOptions function
     $Path2 = $this->fetchViewLocation('helper_functions', 'categories', false, false);
     if ($Path2) {
         include_once $Path2;
     }
     $this->render();
 }
Пример #7
0
 /**
  * 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');
 }
Пример #8
0
 /**
  *
  *
  * @param $Tag
  * @param $Limit
  * @param $Offset
  * @param string $Op
  * @return Gdn_DataSet
  */
 public function getDiscussions($Tag, $Limit, $Offset, $Op = 'or')
 {
     $DiscussionModel = new DiscussionModel();
     $this->setTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Op);
     $Result = $DiscussionModel->get($Offset, $Limit, array('Announce' => 'all'));
     return $Result;
 }