/**
  * Method to get a list of articles.
  * Overridden to add a check for access levels.
  *
  * @return	mixed	An array of data items on success, false on failure.
  * @since	1.6.1
  */
 public function getItems()
 {
     $items = parent::getItems();
     $app = JFactory::getApplication();
     // Get fields group
     $data = array();
     if ($app->isSite()) {
         $user = JFactory::getUser();
         $groups = $user->getAuthorisedViewLevels();
         for ($x = 0, $count = count($items); $x < $count; $x++) {
             //Check the access level. Remove articles the user shouldn't see
             if (!in_array($items[$x]->access, $groups)) {
                 unset($items[$x]);
             }
         }
     }
     if ($items) {
         $texts = array();
         $values = array();
         $dispatcher = JEventDispatcher::getInstance();
         TZ_Portfolio_PlusPluginHelper::importPlugin('mediatype');
         $results = $dispatcher->trigger('onAddMediaType');
         if (count($results)) {
             $texts = JArrayHelper::getColumn($results, 'text');
             $values = JArrayHelper::getColumn($results, 'value');
         }
         foreach ($items as &$item) {
             $categories = TZ_Portfolio_PlusHelperCategories::getCategoriesByArticleId($item->id, 0);
             $item->categories = $categories;
             if (isset($item->type) && in_array($item->type, $values)) {
                 $index = array_search($item->type, $values);
                 $item->type = $texts[$index];
             } else {
                 $item->type = JText::_('COM_TZ_PORTFOLIO_PLUS_OPTION_NONE_MEDIA');
             }
         }
     }
     return $items;
 }
Beispiel #2
0
 /**
  * Method to get the data that should be injected in the form.
  *
  * @return  mixed  The data for the form.
  *
  * @since   1.6
  */
 protected function loadFormData()
 {
     // Check the session for previously entered form data.
     $app = JFactory::getApplication();
     $data = $app->getUserState('com_tz_portfolio_plus.edit.article.data', array());
     if (empty($data)) {
         $data = $this->getItem();
         if ($second_categories = TZ_Portfolio_PlusHelperCategories::getCategoriesByArticleId($data->id, 0)) {
             if (is_array($second_categories)) {
                 $catids = JArrayHelper::getColumn($second_categories, 'id');
             } else {
                 $catids = $second_categories->id;
             }
             $data->set('second_catid', $catids);
         }
         if ($main_category = TZ_Portfolio_PlusHelperCategories::getCategoriesByArticleId($data->id, 1)) {
             if (is_array($main_category)) {
                 $catid = JArrayHelper::getColumn($main_category, 'id');
             } else {
                 $catid = $main_category->id;
             }
             $data->set('catid', $catid);
         }
         // Pre-select some filters (Status, Category, Language, Access) in edit form if those have been selected in Article Manager: Articles
         if ($this->getState($this->getName() . '.id') == 0) {
             $filters = (array) $app->getUserState('com_tz_portfolio_plus.articles.filter');
             $data->set('state', $app->input->getInt('state', !empty($filters['published']) ? $filters['published'] : null));
             $data->set('catid', $app->input->get('catid', !empty($filters['category_id']) ? $filters['category_id'] : array()));
             $data->set('language', $app->input->getString('language', !empty($filters['language']) ? $filters['language'] : null));
             $data->set('access', $app->input->getInt('access', !empty($filters['access']) ? $filters['access'] : JFactory::getConfig()->get('access')));
         }
     }
     $this->preprocessData('com_tz_portfolio_plus.article', $data);
     return $data;
 }