/** * Render the list of associated items * * @param int $articleid The article item id * * @return string The language HTML */ public static function association($articleid) { // Defaults $html = ''; // Get the associations if ($associations = TZ_Portfolio_PlusBackEndHelperAssociation::getArticleAssociations($articleid)) { foreach ($associations as $tag => $associated) { $associations[$tag] = (int) $associated->id; } // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.*')->select('l.sef as lang_sef')->from('#__tz_portfolio_plus_content as c')->select('cat.title as category_title')->join('LEFT', '#__tz_portfolio_plus_content_category_map as m ON m.contentid=c.id')->join('LEFT', '#__tz_portfolio_plus_categories as cat ON cat.id=m.catid')->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_tz_portfolio_plus&task=article.edit&id=' . (int) $item->id); $tooltipParts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->title, '(' . $item->category_title . ')'); $item->link = JHtml::_('tooltip', implode(' ', $tooltipParts), null, null, $text, $url, null, 'hasTooltip label label-association label-' . $item->lang_sef); } } $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * Method to get the record form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_tz_portfolio_plus.article', 'article', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } $jinput = JFactory::getApplication()->input; // The front end calls this model and uses a_id to avoid id clashes so we need to check for that first. if ($jinput->get('a_id')) { $id = $jinput->get('a_id', 0); } else { $id = $jinput->get('id', 0); } // Determine correct permissions to check. if ($this->getState('article.id')) { $id = $this->getState('article.id'); // Existing record. Can only edit in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit'); // Existing record. Can only edit own articles in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit.own'); } else { // New record. Can only create in selected categories. $form->setFieldAttribute('catid', 'action', 'core.create'); } $user = JFactory::getUser(); // Check for existing article. // Modify the form based on Edit State access controls. if ($id != 0 && !$user->authorise('core.edit.state', 'com_tz_portfolio_plus.article.' . (int) $id) || $id == 0 && !$user->authorise('core.edit.state', 'com_tz_portfolio_plus')) { // Disable fields for display. $form->setFieldAttribute('featured', 'disabled', 'true'); $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('publish_up', 'disabled', 'true'); $form->setFieldAttribute('publish_down', 'disabled', 'true'); $form->setFieldAttribute('state', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is an article you can edit. $form->setFieldAttribute('featured', 'filter', 'unset'); $form->setFieldAttribute('ordering', 'filter', 'unset'); $form->setFieldAttribute('publish_up', 'filter', 'unset'); $form->setFieldAttribute('publish_down', 'filter', 'unset'); $form->setFieldAttribute('state', 'filter', 'unset'); } // Prevent messing with article language and category when editing existing article with associations $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); // Check if article is associated if ($this->getState('article.id') && $app->isSite() && $assoc) { $associations = TZ_Portfolio_PlusBackEndHelperAssociation::getArticleAssociations($id); // Make fields read only if (!empty($associations)) { $form->setFieldAttribute('language', 'readonly', 'true'); $form->setFieldAttribute('catid', 'readonly', 'true'); $form->setFieldAttribute('language', 'filter', 'unset'); $form->setFieldAttribute('catid', 'filter', 'unset'); } } return $form; }