/** * Method to get the associations for a given category * * @param integer $id Id of the item * @param string $extension Name of the component * * @return array Array of associations for the component categories * * @since 3.0 */ public static function getCategoryAssociations($id = 0, $extension = 'com_tz_portfolio', $view = '') { $return = array(); if ($id) { // if(!is_array($id)){ // Load route helper jimport('helper.route', JPATH_COMPONENT_SITE); $helperClassname = 'TZ_Portfolio_PlusHelperRoute'; $associations = TZ_Portfolio_PlusHelperCategories::getAssociations($id, $extension); foreach ($associations as $tag => $item) { if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute'))) { $return[$tag] = $helperClassname::getCategoryRoute($item, $tag); } else { $return[$tag] = 'index.php?option=com_tz_portfolio_plus&view=category&id=' . $item; } } // }else{ // $associations = CategoriesHelper::getAssociations($id, $extension); // var_dump($associations); // } } return $return; }
/** * Method to get a category. * * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. * * @return mixed Category data object on success, false on failure. * * @since 1.6 */ public function getItem($pk = null) { if ($result = parent::getItem($pk)) { // Prime required properties. if (empty($result->id)) { $result->parent_id = $this->getState('category.parent_id'); $result->extension = $this->getState('category.extension'); } // Convert the metadata field to an array. $registry = new JRegistry(); $registry->loadString($result->metadata); $result->metadata = $registry->toArray(); // Convert the created and modified dates to local user time for display in the form. jimport('joomla.utilities.date'); $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); if (intval($result->created_time)) { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } else { $result->created_time = null; } if (intval($result->modified_time)) { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } else { $result->modified_time = null; } } $assoc = $this->getAssoc(); if ($assoc) { if ($result->id != null) { $result->associations = TZ_Portfolio_PlusHelperCategories::getAssociations($result->id, $result->extension); // var_dump($result -> associations); die(); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } return $result; }
/** * 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; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { // Initialise variables. $extension = JFactory::getApplication()->input->getCmd('extension'); $user = TZ_Portfolio_PlusUser::getUser(); $userId = $user->get('id'); $isNew = $this->item->id == 0; $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $userId); // Avoid nonsense situation. if ($extension == 'com_tz_portfolio_plus') { return; } // The extension can be in the form com_foo.section $parts = explode('.', $extension); $component = $parts[0]; $section = count($parts) > 1 ? $parts[1] : null; // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = JFactory::getLanguage(); $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, $lang->getDefault(), false, false); // Load the category helper. require_once JPATH_COMPONENT . '/helpers/categories.php'; // Get the results for each action. $canDo = TZ_Portfolio_PlusHelperCategories::getActions($component, $this->item->id); // If a component categories title string is present, let's use it. if ($lang->hasKey($component_title_key = $component . ($section ? "_{$section}" : '') . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE')) { $title = JText::_($component_title_key); } elseif ($lang->hasKey($component_section_key = $component . ($section ? "_{$section}" : ''))) { $title = JText::sprintf('COM_CATEGORIES_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', $this->escape(JText::_($component_section_key))); } else { $title = JText::_('COM_CATEGORIES_CATEGORY_BASE_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE'); } // Load specific css component JHtml::_('stylesheet', $component . '/administrator/categories.css', array(), true); // Prepare the toolbar. JToolBarHelper::title($title, 'folder category-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . ($section ? "-{$section}" : '') . '-category-' . ($isNew ? 'add' : 'edit')); // For new records, check the create permission. if ($isNew && count($user->getAuthorisedCategories($component, 'core.create')) > 0) { JToolBarHelper::apply('category.apply'); JToolBarHelper::save('category.save'); JToolBarHelper::save2new('category.save2new'); } elseif (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_user_id == $userId)) { JToolBarHelper::apply('category.apply'); JToolBarHelper::save('category.save'); if ($canDo->get('core.create')) { JToolBarHelper::save2new('category.save2new'); } } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolBarHelper::save2copy('category.save2copy'); } if (empty($this->item->id)) { JToolBarHelper::cancel('category.cancel'); } else { JToolBarHelper::cancel('category.cancel', 'JTOOLBAR_CLOSE'); } JToolBarHelper::divider(); // Compute the ref_key if it does exist in the component if (!$lang->hasKey($ref_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_HELP_KEY')) { $ref_key = 'JHELP_COMPONENTS_' . strtoupper(substr($component, 4) . ($section ? "_{$section}" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT'); } // Get help for the category/section view for the component by // -remotely searching in a language defined dedicated URL: *component*_HELP_URL // -locally searching in a component help file if helpURL param exists in the component and is set to '' // -remotely searching in a component URL if helpURL param exists in the component and is NOT set to '' if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { $debug = $lang->setDebug(false); $url = JText::_($lang_help_url); $lang->setDebug($debug); } else { $url = null; } JToolBarHelper::help($ref_key, JComponentHelper::getParams('com_tz_portfolio_plus')->exists('helpURL'), $url, 'com_tz_portfolio_plus'); }
public static function resetCache() { if (count(self::$cache)) { self::$cache = array(); } return true; }
/** * 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; }