/** * Render the list of associated items * * @param integer $catid Category identifier to search its associations * @param string $extension Category Extension * * @return string The language HTML */ public static function association($catid, $extension = 'com_content') { // Defaults $html = ''; // Get the associations if ($associations = CategoriesHelper::getAssociations($catid, $extension)) { JArrayHelper::toInteger($associations); // Get the associated categories $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.id, c.title')->select('l.sef as lang_sef')->from('#__categories as c')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500); } if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); $tooltipParts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->title); $item->link = JHtml::_('tooltip', implode(' ', $tooltipParts), null, null, $text, $url, null, ' label label-association label-' . $item->lang_sef); } } $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * @param int $articleid The article item id */ public static function association($catid) { // Get the associations $associations = CategoriesHelper::getAssociations($catid); JArrayHelper::toInteger($associations); // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('c.*'); $query->from('#__categories as c'); $query->where('c.id IN (' . implode(',', array_values($associations)) . ')'); $query->leftJoin('#__languages as l ON c.language=l.lang_code'); $query->select('l.image'); $query->select('l.title as language_title'); $db->setQuery($query); $items = $db->loadObjectList('id'); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Construct html $text = array(); foreach ($associations as $tag => $associated) { if ($associated != $catid) { $text[] = JText::sprintf('COM_CATEGORIES_TIP_ASSOCIATED_LANGUAGE', JHtml::_('image', 'mod_languages/' . $items[$associated]->image . '.gif', $items[$associated]->language_title, array('title' => $items[$associated]->language_title), true), $items[$associated]->title); } } return JHtml::_('tooltip', implode('<br />', $text), JText::_('COM_CATEGORIES_TIP_ASSOCIATION'), 'admin/icon-16-links.png'); }
/** * Render the list of associated items * * @param integer $catid Category identifier to search its associations * @param string $extension Category Extension * * @return string The language HTML * * @since 3.2 * @throws Exception */ public static function association($catid, $extension = 'com_content') { // Defaults $html = ''; // Get the associations if ($associations = CategoriesHelper::getAssociations($catid, $extension)) { $associations = ArrayHelper::toInteger($associations); // Get the associated categories $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.id, c.title')->select('l.sef as lang_sef')->select('l.lang_code')->from('#__categories as c')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500, $e); } if ($items) { foreach ($items as &$item) { $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $url = JRoute::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); $classes = 'hasPopover label label-association label-' . $item->lang_sef; $item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes . '" data-content="' . $item->title . '" data-placement="top">' . $text . '</a>'; } } JHtml::_('bootstrap.popover'); $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * 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_content') { $return = array(); if ($id) { $associations = CategoriesHelper::getAssociations($id, $extension); foreach ($associations as $tag => $item) { $return[$tag] = ContentHelperRoute::getCategoryRoute($item, $tag); } } return $return; }
public static function getAssociationsForm($id, $name, $config = array()) { if (!self::hasAssociations()) { return ''; } $app = JFactory::getApplication(); $addform = new SimpleXMLElement('<form />'); $extension = $app->input->getString('extension', 'com_content'); $fields = $addform->addChild('fields'); $fields->addAttribute('name', $name); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('description', 'COM_CATEGORIES_ITEM_ASSOCIATIONS_FIELDSET_DESC'); $fieldset->addAttribute('addfieldpath', '/administrator/components/com_categories/models/fields'); $hasForm = false; $languages = JLanguageHelper::getLanguages('lang_code'); foreach ($languages as $tag => $language) { if (empty($config['language']) || $tag != $config['language']) { $hasForm = true; $f = $fieldset->addChild('field'); $f->addAttribute('name', $tag); $f->addAttribute('type', 'modal_category'); $f->addAttribute('language', $tag); $f->addAttribute('label', $language->title); $f->addAttribute('translate_label', 'false'); $f->addAttribute('extension', $extension); } } $form = JForm::getInstance($id, $addform->asXML()); if ($hasForm) { $form->load($addform, false); $associations = CategoriesHelper::getAssociations($config['pk'], $extension); if (count($associations)) { foreach ($associations as $tag => $association_id) { $form->setValue($tag, $name, $association_id); } } if ($config['translate_id'] && isset($config['translate'])) { $form->setValue($config['translate'], $name, $config['translate_id']); } } // Render Form $fields = $form->getFieldset('item_associations'); $form = ''; foreach ($fields as $f) { $form .= '<div class="control-group"><div class="control-label">' . $f->label . '</div><div class="controls">' . $f->input . '</div></div>'; } return $form; }
/** * 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_content') { $return = array(); if ($id) { // Load route helper jimport('helper.route', JPATH_COMPONENT_SITE); $helperClassname = ucfirst(substr($extension, 4)) . 'HelperRoute'; $associations = CategoriesHelper::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=' . $extension . '&view=category&id=' . $item; } } } return $return; }
/** * 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_content', $view = '') { $return = array(); if ($id) { // if(!is_array($id)){ // Load route helper jimport('helper.route', JPATH_COMPONENT_SITE); $helperClassname = 'TZ_PortfolioHelperRoute'; $associations = CategoriesHelper::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&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 Registry(); $registry->loadString($result->metadata); $result->metadata = $registry->toArray(); // Convert the created and modified dates to local user time for display in the form. $tz = new DateTimeZone(JFactory::getApplication()->get('offset')); if ((int) $result->created_time) { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } else { $result->created_time = null; } if ((int) $result->modified_time) { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } else { $result->modified_time = null; } if (!empty($result->id)) { $result->tags = new JHelperTags(); $result->tags->getTagIds($result->id, $result->extension . '.category'); } } $assoc = $this->getAssoc(); if ($assoc) { if ($result->id != null) { $result->associations = CategoriesHelper::getAssociations($result->id, $result->extension); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } return $result; }
/** * Method to get a category. * * @param integer 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) { $pk = $pk ? $pk : $this->_id; if ($result = parent::getItem($pk)) { // Prime required properties. if (empty($result->id)) { $result->parent_id = $this->getState('com_flexicontent.category.parent_id'); $result->extension = $this->getState('com_flexicontent.category.extension'); } // Convert the metadata field to an array. $registry = new JRegistry($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'); $site_zone = JFactory::getApplication()->getCfg('offset'); $user_zone = JFactory::getUser()->getParam('timezone', $site_zone); $tz_string = $user_zone; $tz = new DateTimeZone($tz_string); 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; } $this->_category = $result; } $useAssocs = $this->useAssociations(); if ($useAssocs) { if ($result->id != null) { $result->associations = CategoriesHelper::getAssociations($result->id, $result->extension); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } return $result; }
/** * 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; } } if (COM_TZ_PORTFOLIO_JVERSION_COMPARE) { $assoc = $this->getAssoc(); if ($assoc) { if ($result->id != null) { $result->associations = CategoriesHelper::getAssociations($result->id, $result->extension); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } } return $result; }