public function __construct($Sender = '', $ApplicationFolder = '')
 {
     $this->Data = FALSE;
     $NoFollowing = TRUE;
     if (C('Vanilla.Categories.Use') == TRUE) {
         // Load categories with respect to view permissions
         $Categories = CategoryModel::Categories();
         $Categories2 = $Categories;
         foreach ($Categories2 as $i => $Category) {
             if (!$Category['PermsDiscussionsView']) {
                 unset($Categories[$i]);
             } elseif (!$Category['Following']) {
                 $NoFollowing = FALSE;
             }
         }
         // delete view filter if no categories are hidden
         $Session = Gdn::Session();
         if ($NoFollowing && $Session->IsValid()) {
             $Session->SetPreference('ShowAllCategories', TRUE);
         }
         // set categories to data
         $Data = new Gdn_DataSet($Categories);
         $Data->DatasetType(DATASET_TYPE_ARRAY);
         $Data->DatasetType(DATASET_TYPE_OBJECT);
         $this->Data['Categories'] = $Data;
         // calculate additional needed data
         $this->Data['CategoryID'] = isset($Sender->CategoryID) ? $Sender->CategoryID : '';
         $this->Data['OnCategories'] = strtolower($Sender->ControllerName) == 'categoriescontroller' && !is_numeric($this->Data['CategoryID']);
         $this->Data['ShowAllCategoriesPref'] = $Session->GetPreference('ShowAllCategories');
         $this->Data['Url'] = Gdn::Request()->Path();
         if ($this->Data['Url'] == '') {
             $this->Data['Url'] = '/';
         }
         $this->Data['ShowAllCategoriesUrl'] = Gdn::Request()->Url('categories/settoggle?ShowAllCategories=true&Target=' . $this->Data['Url']);
         $this->Data['ShowFollowedCategoriesUrl'] = Gdn::Request()->Url('categories/settoggle?ShowAllCategories=false&Target=' . $this->Data['Url']);
         $this->Data['TKey'] = urlencode(Gdn::Session()->TransientKey());
         $this->Data['ValidSession'] = $Session->UserID > 0 && $Session->ValidateTransientKey($this->Data['TKey']);
         $this->Data['MaxDepth'] = C('Vanilla.Categories.MaxDisplayDepth');
         $this->Data['DoHeadings'] = C('Vanilla.Categories.DoHeadings');
     }
     parent::__construct($Sender, $ApplicationFolder);
 }
 public function __construct($Sender = '')
 {
     // Load categories
     $this->Data = FALSE;
     if (C('Vanilla.Categories.Use') == TRUE && !C('Vanilla.Categories.HideModule')) {
         $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;
     }
     parent::__construct($Sender);
 }
 /**
  * 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;
 }
 public function __get($Name)
 {
     switch ($Name) {
         case 'CommentData':
             Deprecated('ActivityController->CommentData', "ActivityController->Data('Activities')");
             $Result = new Gdn_DataSet(array(), DATASET_TYPE_OBJECT);
             return $Result;
         case 'ActivityData':
             Deprecated('ActivityController->ActivityData', "ActivityController->Data('Activities')");
             $Result = new Gdn_DataSet($this->Data('Activities'), DATASET_TYPE_ARRAY);
             $Result->DatasetType(DATASET_TYPE_OBJECT);
             return $Result;
     }
 }
Example #5
0
 /**
  * Get a list of categories, considering several filters
  * 
  * @param array $RestrictIDs Optional list of category ids to mask the dataset
  * @param string $Permissions Optional permission to require. Defaults to Vanilla.Discussions.View.
  * @param array $ExcludeWhere Exclude categories with any of these flags
  * @return \Gdn_DataSet
  */
 public function GetFiltered($RestrictIDs = FALSE, $Permissions = FALSE, $ExcludeWhere = FALSE)
 {
     // Get the current category list
     $Categories = self::Categories();
     // Filter out the categories we aren't supposed to view.
     if ($RestrictIDs && !is_array($RestrictIDs)) {
         $RestrictIDs = array($RestrictIDs);
     } elseif ($this->Watching) {
         $RestrictIDs = self::CategoryWatch();
     }
     switch ($Permissions) {
         case 'Vanilla.Discussions.Add':
             $Permissions = 'PermsDiscussionsAdd';
             break;
         case 'Vanilla.Disussions.Edit':
             $Permissions = 'PermsDiscussionsEdit';
             break;
         default:
             $Permissions = 'PermsDiscussionsView';
             break;
     }
     $IDs = array_keys($Categories);
     foreach ($IDs as $ID) {
         // Exclude the root category
         if ($ID < 0) {
             unset($Categories[$ID]);
         } elseif (!$Categories[$ID][$Permissions]) {
             unset($Categories[$ID]);
         } elseif (is_array($ExcludeWhere)) {
             foreach ($ExcludeWhere as $Filter => $FilterValue) {
                 if (GetValue($Filter, $Categories[$ID], FALSE) == $FilterValue) {
                     unset($Categories[$ID]);
                 }
             }
         } elseif (is_array($RestrictIDs) && !in_array($ID, $RestrictIDs)) {
             unset($Categories[$ID]);
         }
     }
     Gdn::UserModel()->JoinUsers($Categories, array('LastUserID'));
     $Result = new Gdn_DataSet($Categories, DATASET_TYPE_ARRAY);
     $Result->DatasetType(DATASET_TYPE_OBJECT);
     return $Result;
 }
Example #6
0
 public function GetFullCache($CategoryID = FALSE, $Permissions = FALSE)
 {
     $Categories = self::Categories();
     $Joined = self::JoinRecentPosts($Categories);
     if ($Joined) {
         Gdn::Cache()->Store(self::CACHE_KEY, $Categories);
     }
     // Filter our the categories we aren't supposed to view.
     if ($CategoryID && !is_array($CategoryID)) {
         $CategoryID = array($CategoryID);
     } elseif ($this->Watching) {
         $CategoryID = self::CategoryWatch();
     }
     switch ($Permissions) {
         case 'Vanilla.Discussions.Add':
             $Permissions = 'PermsDiscussionsAdd';
             break;
         case 'Vanilla.Disussions.Edit':
             $Permissions = 'PermsDiscussionsEdit';
             break;
         default:
             $Permissions = 'PermsDiscussionsView';
             break;
     }
     $IDs = array_keys($Categories);
     foreach ($IDs as $ID) {
         if ($ID < 0) {
             unset($Categories[$ID]);
         } elseif (!$Categories[$ID][$Permissions]) {
             unset($Categories[$ID]);
         } elseif (is_array($CategoryID) && !in_array($ID, $CategoryID)) {
             unset($Categories[$ID]);
         }
     }
     Gdn::UserModel()->JoinUsers($Categories, array('LastUserID'));
     $Result = new Gdn_DataSet($Categories, DATASET_TYPE_ARRAY);
     $Result->DatasetType(DATASET_TYPE_OBJECT);
     return $Result;
 }