From 0fbc25ab044153a4a83e4be995bfd42af4ec83b4 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Mon, 9 Jan 2017 12:38:12 +0100 Subject: [PATCH 01/35] Merge Associations rewrite --- .../components/com_associations/access.xml | 8 + .../com_associations/associations.php | 40 ++ .../com_associations/associations.xml | 30 + .../components/com_associations/config.xml | 16 + .../com_associations/controller.php | 26 + .../controllers/association.php | 92 ++++ .../controllers/associations.php | 73 +++ .../com_associations/helpers/associations.php | 505 +++++++++++++++++ .../layouts/joomla/searchtools/default.php | 38 ++ .../joomla/searchtools/default/bar.php | 40 ++ .../com_associations/models/association.php | 36 ++ .../com_associations/models/associations.php | 521 ++++++++++++++++++ .../models/fields/itemlanguage.php | 116 ++++ .../models/fields/itemtype.php | 62 +++ .../models/fields/modalassociation.php | 105 ++++ .../models/forms/association.xml | 21 + .../models/forms/filter_associations.xml | 107 ++++ .../views/association/tmpl/edit.php | 73 +++ .../views/association/view.html.php | 202 +++++++ .../views/associations/tmpl/default.php | 174 ++++++ .../views/associations/tmpl/modal.php | 162 ++++++ .../views/associations/view.html.php | 224 ++++++++ .../com_content/helpers/associations.php | 181 ++++++ .../com_menus/helpers/associations.php | 159 ++++++ .../language/en-GB/en-GB.com_associations.ini | 49 ++ .../en-GB/en-GB.com_associations.sys.ini | 7 + layouts/joomla/content/associations.php | 2 +- .../joomla/association/extension/helper.php | 256 +++++++++ .../association/extension/interface.php | 27 + media/com_associations/css/sidebyside.css | 75 +++ .../js/sidebyside-uncompressed.js | 301 ++++++++++ media/com_associations/js/sidebyside.js | 1 + 32 files changed, 3728 insertions(+), 1 deletion(-) create mode 100644 administrator/components/com_associations/access.xml create mode 100644 administrator/components/com_associations/associations.php create mode 100644 administrator/components/com_associations/associations.xml create mode 100644 administrator/components/com_associations/config.xml create mode 100644 administrator/components/com_associations/controller.php create mode 100644 administrator/components/com_associations/controllers/association.php create mode 100644 administrator/components/com_associations/controllers/associations.php create mode 100644 administrator/components/com_associations/helpers/associations.php create mode 100644 administrator/components/com_associations/layouts/joomla/searchtools/default.php create mode 100644 administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php create mode 100644 administrator/components/com_associations/models/association.php create mode 100644 administrator/components/com_associations/models/associations.php create mode 100644 administrator/components/com_associations/models/fields/itemlanguage.php create mode 100644 administrator/components/com_associations/models/fields/itemtype.php create mode 100644 administrator/components/com_associations/models/fields/modalassociation.php create mode 100644 administrator/components/com_associations/models/forms/association.xml create mode 100644 administrator/components/com_associations/models/forms/filter_associations.xml create mode 100644 administrator/components/com_associations/views/association/tmpl/edit.php create mode 100644 administrator/components/com_associations/views/association/view.html.php create mode 100644 administrator/components/com_associations/views/associations/tmpl/default.php create mode 100644 administrator/components/com_associations/views/associations/tmpl/modal.php create mode 100644 administrator/components/com_associations/views/associations/view.html.php create mode 100644 administrator/components/com_content/helpers/associations.php create mode 100644 administrator/components/com_menus/helpers/associations.php create mode 100644 administrator/language/en-GB/en-GB.com_associations.ini create mode 100644 administrator/language/en-GB/en-GB.com_associations.sys.ini create mode 100644 libraries/joomla/association/extension/helper.php create mode 100644 libraries/joomla/association/extension/interface.php create mode 100644 media/com_associations/css/sidebyside.css create mode 100644 media/com_associations/js/sidebyside-uncompressed.js create mode 100644 media/com_associations/js/sidebyside.js diff --git a/administrator/components/com_associations/access.xml b/administrator/components/com_associations/access.xml new file mode 100644 index 0000000000000..e6fd1ec5258d2 --- /dev/null +++ b/administrator/components/com_associations/access.xml @@ -0,0 +1,8 @@ + + +
+ + + +
+
diff --git a/administrator/components/com_associations/associations.php b/administrator/components/com_associations/associations.php new file mode 100644 index 0000000000000..2c199cef7031e --- /dev/null +++ b/administrator/components/com_associations/associations.php @@ -0,0 +1,40 @@ +authorise('core.manage', 'com_associations')) +{ + throw new JAccessExceptionNotallowed(JText::_('JERROR_ALERTNOAUTHOR'), 403); +} + +JLoader::register('AssociationsHelper', __DIR__ . '/helpers/associations.php'); + +// Check if user has permission to access the component item type. +$itemtype = JFactory::getApplication()->input->get('itemtype', '', 'string'); + +if ($itemtype !== '') +{ + list($extensionName, $typeName) = explode('.', $itemtype); + + if (! AssociationsHelper::hasSupport($extensionName)) + { + throw new Exception(JText::_('COM_ASSOCIATIONS_COMPONENT_NOT_SUPPORTED') . ' ' . $itemType->realcomponent, 404); + } + + if (!JFactory::getUser()->authorise('core.manage', $extensionName)) + { + throw new JAccessExceptionNotallowed(JText::_('JERROR_ALERTNOAUTHOR'), 403); + } +} + +$controller = JControllerLegacy::getInstance('Associations'); +$controller->execute(JFactory::getApplication()->input->get('task')); +$controller->redirect(); diff --git a/administrator/components/com_associations/associations.xml b/administrator/components/com_associations/associations.xml new file mode 100644 index 0000000000000..082bab1233824 --- /dev/null +++ b/administrator/components/com_associations/associations.xml @@ -0,0 +1,30 @@ + + + com_associations + Joomla! Project + September 2016 + (C) 2005 - 2016 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + __DEPLOY_VERSION__ + COM_ASSOCIATIONS_XML_DESCRIPTION + + COM_ASSOCIATIONS + + access.xml + config.xml + associations.php + controller.php + controllers + helpers + layouts + models + views + + + language/en-GB.com_associations.ini + language/en-GB.com_associations.sys.ini + + + diff --git a/administrator/components/com_associations/config.xml b/administrator/components/com_associations/config.xml new file mode 100644 index 0000000000000..20f40eb6d9887 --- /dev/null +++ b/administrator/components/com_associations/config.xml @@ -0,0 +1,16 @@ + + +
+ +
+
diff --git a/administrator/components/com_associations/controller.php b/administrator/components/com_associations/controller.php new file mode 100644 index 0000000000000..dd8e767dcd8e4 --- /dev/null +++ b/administrator/components/com_associations/controller.php @@ -0,0 +1,26 @@ +input; + + list($extensionName, $typeName) = explode('.', $input->get('itemtype')); + + $id = $input->get('id', 0); + + // Check if reference item can be edited. + if (!AssociationsHelper::allowEdit($extensionName, $typeName, $id)) + { + JFactory::getApplication()->enqueueMessage(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'), 'error'); + $this->setRedirect(JRoute::_('index.php?option=com_associations&view=associations', false)); + + return false; + } + + return parent::display(); + } + + /** + * Method for canceling the edit action + * + * @param string $key The name of the primary key of the URL variable. + * + * @return void. + * + * @since __DEPLOY_VERSION__ + */ + public function cancel($key = null) + { + JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + $input = JFactory::getApplication()->input; + + list($extensionName, $typeName) = explode('.', $input->get('itemtype')); + + $id = $input->get('id', 0); + + // Only check in, if component item type allows to check out. + if (AssociationsHelper::typeSupportsCheckout($extensionName, $typeName)) + { + $ids = array(); + $targetId = $this->input->get('target-id', '', 'string'); + + if ($targetId !== '') + { + $ids = array_unique(explode(',', $targetId)); + } + + $ids[] = $id; + + foreach ($ids as $key => $id) + { + AssociationsHelper::getItem($extensionName, $typeName, $id)->checkin(); + } + } + + $this->setRedirect(JRoute::_('index.php?option=com_associations&view=associations', false)); + } +} diff --git a/administrator/components/com_associations/controllers/associations.php b/administrator/components/com_associations/controllers/associations.php new file mode 100644 index 0000000000000..332a05dd5aa46 --- /dev/null +++ b/administrator/components/com_associations/controllers/associations.php @@ -0,0 +1,73 @@ + true)) + { + return parent::getModel($name, $prefix, $config); + } + + /** + * Method to purge the associations table. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function purge() + { + $model = $this->getModel('associations'); + $model->purge(); + $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); + } + + /** + * Method to delete the orphans from the associations table. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function clean() + { + $model = $this->getModel('associations'); + $model->clean(); + $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); + } +} diff --git a/administrator/components/com_associations/helpers/associations.php b/administrator/components/com_associations/helpers/associations.php new file mode 100644 index 0000000000000..55ec3af62c378 --- /dev/null +++ b/administrator/components/com_associations/helpers/associations.php @@ -0,0 +1,505 @@ +getAssociationList($typeName, $itemId); + + return $items; + } + + /** + * Get the the instance of the extension helper class + * + * @param string $extensionName The extension name with com_ + * + * @return HelperClass|null + * + * @since __DEPLOY_VERSION__ + */ + public static function getExtensionHelper($extensionName) + { + if (! self::hasSupport($extensionName)) + { + return null; + } + + $support = self::$extensionsSupport[$extensionName]; + + return $support->get('helper'); + } + + /** + * Get item information + * + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * @param int $itemId The id of item for which we need the associated items + * + * @return JTable|null + * + * @since __DEPLOY_VERSION__ + */ + public static function getItem($extensionName, $typeName, $itemId) + { + if (! self::hasSupport($extensionName)) + { + return array(); + } + + // Get the extension specific helper method + $helper = self::getExtensionHelper($extensionName); + + $item = $helper->getItem($typeName, $itemId); + + return $item; + } + + /** + * Check if extension supports associations + * + * @param string $extensionName The extension name with com_ + * + * @return bool + * + * @since __DEPLOY_VERSION__ + */ + public static function hasSupport($extensionName) + { + if (is_null(self::$extensionsSupport)) + { + self::getSupportedExtensions(); + } + + return in_array($extensionName, self::$supportedExtensionsList); + } + + /** + * Get the extension specific helper class name + * + * @param string $extensionName The extension name with com_ + * + * @return bool + * + * @since __DEPLOY_VERSION__ + */ + private static function getExtensionHelperClassName($extensionName) + { + $realName = self::getExtensionRealName($extensionName); + + return ucfirst($realName) . 'AssociationsHelper'; + } + + /** + * Get the real extension name. This means without com_ + * + * @param string $extensionName The extension name with com_ + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + private static function getExtensionRealName($extensionName) + { + return strpos($extensionName, 'com_') === false ? $extensionName : substr($extensionName, 4); + } + + /** + * Get the associated language edit links Html. + * + * @param string $extensionName Extension Name + * @param string $typeName ItemType + * @param integer $itemId Item id. + * @param string $itemLanguage Item language code. + * @param boolean $addLink True for adding edit links. False for just text. + * @param boolean $allLanguages True for showing all content languages. False only languages with associations. + * + * @return string The language HTML + * + * @since __DEPLOY_VERSION__ + */ + public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $allLanguages = true) + { + // Get the associations list for this item. + $items = self::getAssociationList($extensionName, $typeName, $itemId); + + // Get all content languages. + $languages = self::getContentLanguages(); + + $canEditReference = self::allowEdit($extensionName, $typeName, $itemId); + $canCreate = self::allowAdd($extensionName, $typeName); + + // Create associated items list. + foreach ($languages as $langCode => $language) + { + // Don't do for the reference language. + if ($langCode == $itemLanguage) + { + continue; + } + + // Don't show languages without associations, if we don't want to show them. + if (!$allLanguages && !isset($items[$langCode])) + { + continue; + } + + // Get html parameters. + if (isset($items[$langCode])) + { + $title = '

' . $items[$langCode]['title']; + $additional = ''; + + if (isset($items[$langCode]['category_title'])) + { + $additional = '
' . JText::_('JCATEGORY') . ': ' . $items[$langCode]['category_title']; + } + elseif (isset($items[$langCode]['menu_title'])) + { + $additional = '
' . JText::_('COM_ASSOCIATIONS_HEADING_MENUTYPE') . ': ' . $items[$langCode]['menu_title']; + } + + $additional .= $addLink ? '

' . JText::_('COM_ASSOCIATIONS_EDIT_ASSOCIATION') : ''; + $labelClass = 'label'; + $target = $langCode . ':' . $items[$langCode]['id'] . ':edit'; + $allow = $canEditReference && self::allowEdit($extensionName, $typeName, $items[$langCode]['id']); + } + else + { + $items[$langCode] = array(); + + $title = '

' . JText::_('COM_ASSOCIATIONS_NO_ASSOCIATION'); + $additional = $addLink ? '

' . JText::_('COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION') : ''; + $labelClass = 'label label-warning'; + $target = $langCode . ':0:add'; + $allow = $canCreate; + } + + // Generate item Html. + $options = array( + 'option' => 'com_associations', + 'view' => 'association', + 'layout' => 'edit', + 'itemtype' => $extensionName . '.' . $typeName, + 'task' => 'association.edit', + 'id' => $itemId, + 'target' => $target, + ); + $url = JRoute::_('index.php?' . http_build_query($options)); + $text = strtoupper($language->sef); + $langImage = JHtml::_('image', 'mod_languages/' . $language->image . '.gif', $language->title, array('title' => $language->title), true); + $tooltip = implode(' ', array($langImage, $language->title, $title, $additional)); + + $items[$langCode]['link'] = JHtml::_('tooltip', $tooltip, null, null, $text, $allow && $addLink ? $url : '', null, 'hasTooltip ' . $labelClass); + } + + return JLayoutHelper::render('joomla.content.associations', $items); + } + + /** + * Get all extensions with associations support. + * + * @return array The extensions. + * + * @since __DEPLOY_VERSION__ + */ + public static function getSupportedExtensions() + { + if (! is_null(self::$extensionsSupport)) + { + return self::$extensionsSupport; + } + + self::$extensionsSupport = array(); + + $extensions = self::getEnabledExtensions(); + + foreach ($extensions as $extension) + { + $support = self::getSupportedExtension($extension->element); + + if ($support->get('associationssupport') === true) + { + self::$supportedExtensionsList[] = $extension->element; + } + + self::$extensionsSupport[$extension->element] = $support; + } + + return self::$extensionsSupport; + } + + /** + * Get item context based on the item key. + * + * @param string $extensionName The extension identifier. + * + * @return Joomla\Registry\Registry The item properties. + * + * @since __DEPLOY_VERSION__ + */ + public static function getSupportedExtension($extensionName) + { + $result = new Registry; + + $result->def('component', $extensionName); + $result->def('associationssupport', false); + $result->def('helper', null); + + // Check if associations helper exists + if (! file_exists(JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php')) + { + return $result; + } + + require_once JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php'; + + $componentAssociationsHelperClassName = self::getExtensionHelperClassName($extensionName); + + if (! class_exists($componentAssociationsHelperClassName, false)) + { + return $result; + } + + // Create an instance of the helper class + $helper = new $componentAssociationsHelperClassName; + $result->set('helper', $helper); + + if ($helper->hasAssociationsSupport() === false) + { + return $result; + } + + $result->set('associationssupport', true); + + // Get the translated titles. + $languagePath = JPATH_ADMINISTRATOR . '/components/' . $extensionName; + $lang = JFactory::getLanguage(); + + $lang->load($extensionName . '.sys', JPATH_ADMINISTRATOR); + $lang->load($extensionName . '.sys', $languagePath); + $lang->load($extensionName, JPATH_ADMINISTRATOR); + $lang->load($extensionName, $languagePath); + + $result->def('title', JText::_(strtoupper($extensionName))); + + // Get the supported types + $types = $helper->getItemTypes(); + + $rTypes = array(); + + foreach ($types as $typeName) + { + $details = $helper->getType($typeName); + $context = 'component'; + $title = $helper->getTypeTitle($typeName); + $languageKey = $typeName; + + if ($typeName === 'category') + { + $languageKey = strtoupper($extensionName) . '_CATEGORIES'; + $context = 'category'; + } + + if ($lang->hasKey(strtoupper($extensionName . '_' . $title . 'S'))) + { + $languageKey = strtoupper($extensionName . '_' . $title . 'S'); + } + + $title = $lang->hasKey($languageKey) ? JText::_($languageKey) : JText::_('ITEMS'); + + $rType = new Registry; + + $rType->def('name', $typeName); + $rType->def('details', $details); + $rType->def('title', $title); + $rType->def('context', $context); + + $rTypes[$typeName] = $rType; + } + + $result->def('types', $rTypes); + + return $result; + } + + /** + * Get all installed and enabled extensions + * + * @return mixed + * + * @since __DEPLOY_VERSION__ + */ + private static function getEnabledExtensions() + { + $db = JFactory::getDbo(); + + $query = $db->getQuery(true) + ->select('*') + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('type') . ' = ' . $db->quote('component')) + ->where($db->quoteName('enabled') . ' = 1'); + + $db->setQuery($query); + + return $db->loadObjectList(); + } + + /** + * Get all the content languages. + * + * @return array Array of objects all content languages by language code. + * + * @since __DEPLOY_VERSION__ + */ + public static function getContentLanguages() + { + $db = JFactory::getDbo(); + + // Get all content languages. + $query = $db->getQuery(true) + ->select($db->quoteName(array('sef', 'lang_code', 'image', 'title', 'published'))) + ->from($db->quoteName('#__languages')) + ->order($db->quoteName('ordering') . ' ASC'); + + $db->setQuery($query); + + return $db->loadObjectList('lang_code'); + } + + /** + * Get the associated items for an item + * + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * @param int $itemId The id of item for which we need the associated items + * + * @return bool + * + * @since __DEPLOY_VERSION__ + */ + public static function allowEdit($extensionName, $typeName, $itemId) + { + if (! self::hasSupport($extensionName)) + { + return false; + } + + // Get the extension specific helper method + $helper= self::getExtensionHelper($extensionName); + + if (method_exists($helper, 'allowEdit')) + { + return $helper->allowEdit($typeName, $itemId); + } + + $user = JFactory::getUser(); + + return $user->authorise('core.edit', $extensionName); + } + + /** + * Check if user is allowed to create items. + * + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * + * @return boolean True on allowed. + * + * @since __DEPLOY_VERSION__ + */ + public static function allowAdd($extensionName, $typeName) + { + if (! self::hasSupport($extensionName)) + { + return false; + } + + // Get the extension specific helper method + $helper= self::getExtensionHelper($extensionName); + + if (method_exists($helper, 'allowAdd')) + { + return $helper->allowAdd($typeName); + } + + $user = JFactory::getUser(); + + return $user->authorise('core.create', $extensionName); + } + + /** + * Check if the type supports checkout + * + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * + * @return boolean True on allowed. + * + * @since __DEPLOY_VERSION__ + */ + public static function typeSupportsCheckout($extensionName, $typeName) + { + if (! self::hasSupport($extensionName)) + { + return false; + } + + // Get the extension specific helper method + $helper = self::getExtensionHelper($extensionName); + + $support = $helper->getTypeSupport($typeName); + + return ! empty($support['checkout']); + } +} diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default.php b/administrator/components/com_associations/layouts/joomla/searchtools/default.php new file mode 100644 index 0000000000000..e58e551374b6d --- /dev/null +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default.php @@ -0,0 +1,38 @@ +addStyleDeclaration(" + /* Fixed filter field in search bar */ + .js-stools .js-stools-selector { + float: left; + margin-right: 10px; + min-width: 220px; + } + html[dir=rtl] .js-stools .js-stools-selector { + float: right; + margin-left: 10px + margin-right: 0; + } + .js-stools .js-stools-container-bar .js-stools-selector .chzn-container { + padding: 3px 0; + } + "); +} + +// Display the main joomla layout +echo JLayoutHelper::render('joomla.searchtools.default', $data, null, array('component' => 'none')); diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php b/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php new file mode 100644 index 0000000000000..91ec2e0c8f80e --- /dev/null +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php @@ -0,0 +1,40 @@ +input->get('forcedItemType', '', 'string') == '') + { + $itemTypeField = $data['view']->filterForm->getField('itemtype'); +?> +
+ input; ?> +
+input->get('forcedLanguage', '', 'cmd') == '') + { + $languageField = $data['view']->filterForm->getField('language'); +?> +
+ input; ?> +
+ 'none')); diff --git a/administrator/components/com_associations/models/association.php b/administrator/components/com_associations/models/association.php new file mode 100644 index 0000000000000..d90a792501c85 --- /dev/null +++ b/administrator/components/com_associations/models/association.php @@ -0,0 +1,36 @@ +loadForm('com_associations.association', 'association', array('control' => 'jform', 'load_data' => $loadData)); + + return !empty($form) ? $form : false; + } +} diff --git a/administrator/components/com_associations/models/associations.php b/administrator/components/com_associations/models/associations.php new file mode 100644 index 0000000000000..a32796a5617b1 --- /dev/null +++ b/administrator/components/com_associations/models/associations.php @@ -0,0 +1,521 @@ +input->get('forcedLanguage', '', 'cmd'); + $forcedItemType = $app->input->get('forcedItemType', '', 'string'); + + // Adjust the context to support modal layouts. + if ($layout = $app->input->get('layout')) + { + $this->context .= '.' . $layout; + } + + // Adjust the context to support forced languages. + if ($forcedLanguage) + { + $this->context .= '.' . $forcedLanguage; + } + + // Adjust the context to support forced component item types. + if ($forcedItemType) + { + $this->context .= '.' . $forcedItemType; + } + + $this->setState('itemtype', $this->getUserStateFromRequest($this->context . '.itemtype', 'itemtype', '', 'string')); + $this->setState('language', $this->getUserStateFromRequest($this->context . '.language', 'language', '', 'string')); + + $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); + $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd')); + $this->setState('filter.category_id', $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '', 'cmd')); + $this->setState('filter.menutype', $this->getUserStateFromRequest($this->context . '.filter.menutype', 'filter_menutype', '', 'string')); + $this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'string')); + $this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd')); + + // List state information. + parent::populateState($ordering, $direction); + + // Force a language. + if (!empty($forcedLanguage)) + { + $this->setState('language', $forcedLanguage); + } + + // Force a component item type. + if (!empty($forcedItemType)) + { + $this->setState('itemtype', $forcedItemType); + } + } + + /** + * Method to get a store id based on model configuration state. + * + * This is necessary because the model is used by the component and + * different modules that might need different sets of data or different + * ordering requirements. + * + * @param string $id A prefix for the store id. + * + * @return string A store id. + * + * @since __DEPLOY_VERSION__ + */ + protected function getStoreId($id = '') + { + // Compile the store id. + $id .= ':' . $this->getState('itemtype'); + $id .= ':' . $this->getState('language'); + $id .= ':' . $this->getState('filter.search'); + $id .= ':' . $this->getState('filter.state'); + $id .= ':' . $this->getState('filter.category_id'); + $id .= ':' . $this->getState('filter.menutype'); + $id .= ':' . $this->getState('filter.access'); + $id .= ':' . $this->getState('filter.level'); + + return parent::getStoreId($id); + } + + /** + * Build an SQL query to load the list data. + * + * @return JDatabaseQuery + * + * @since __DEPLOY_VERSION__ + */ + protected function getListQuery() + { + $type = null; + + list($extensionName, $typeName) = explode('.', $this->state->get('itemtype')); + + $extension = AssociationsHelper::getSupportedExtension($extensionName); + + $types = $extension->get('types'); + + if (array_key_exists($typeName, $types)) + { + $type = $types[$typeName]; + } + + if (is_null($type)) + { + return false; + } + + // Create a new query object. + $user = JFactory::getUser(); + $db = $this->getDbo(); + $query = $db->getQuery(true); + + $details = $type->get('details'); + + if (! array_key_exists('support', $details)) + { + return false; + } + + $support = $details['support']; + + if (! array_key_exists('fields', $details)) + { + return false; + } + + $fields = $details['fields']; + + // Main query. + $query->select($db->qn($fields['id'], 'id')) + ->select($db->qn($fields['title'], 'title')) + ->select($db->qn($fields['alias'], 'alias')); + + if (! array_key_exists('tables', $details)) + { + return false; + } + + $tables = $details['tables']; + + foreach ($tables as $key => $table) + { + $query->from($db->qn($table, $key)); + } + + if (! array_key_exists('joins', $details)) + { + return false; + } + + $joins = $details['joins']; + + foreach ($joins as $join) + { + $query->join($join['type'], $db->qn($join['condition'])); + } + + // Join over the language. + $query->select($db->qn($fields['language'], 'language')) + ->select($db->qn('l.title', 'language_title')) + ->select($db->qn('l.image', 'language_image')) + ->join('LEFT', $db->qn('#__languages', 'l') . ' ON ' . $db->qn('l.lang_code') . ' = ' . $db->qn($fields['language'])); + + // Join over the associations. + $query->select('COUNT(' . $db->qn('asso2.id') . ') > 1 AS ' . $db->qn('association')) + ->join( + 'LEFT', + $db->qn('#__associations', 'asso') . ' ON ' . $db->qn('asso.id') . ' = ' . $db->qn($fields['id']) + . ' AND ' . $db->qn('asso.context') . ' = ' . $db->quote($extensionName . '.' . 'item') + ) + ->join('LEFT', $db->qn('#__associations', 'asso2') . ' ON ' . $db->qn('asso2.key') . ' = ' . $db->qn('asso.key')); + + // Prepare the group by clause. + $groupby = array( + $fields['id'], + $fields['title'], + $fields['language'], + 'l.title', + 'l.image', + ); + + // Select author for ACL checks. + if (! empty($fields['created_user_id'])) + { + $query->select($db->qn($fields['created_user_id'], 'created_user_id')); + } + + // Select checked out data for check in checkins. + if (! empty($fields['checked_out']) && ! empty($fields['checked_out_time'])) + { + $query->select($db->qn($fields['checked_out'], 'checked_out')) + ->select($db->qn($fields['checked_out_time'], 'checked_out_time')); + + // Join over the users. + $query->select($db->qn('u.name', 'editor')) + ->join('LEFT', $db->qn('#__users', 'u') . ' ON ' . $db->qn('u.id') . ' = ' . $db->qn($fields['checked_out'])); + + $groupby[] = 'u.name'; + } + + // If component item type supports ordering, select the ordering also. + if (! empty($fields['ordering'])) + { + $query->select($db->qn($fields['ordering'], 'ordering')); + } + + // If component item type supports state, select the item state also. + if (! empty($fields['state'])) + { + $query->select($db->qn($fields['state'], 'state')); + } + + // If component item type supports level, select the level also. + if (! empty($fields['level'])) + { + $query->select($db->qn($fields['level'], 'level')); + } + + // If component item type supports categories, select the category also. + if (! empty($fields['catid'])) + { + $query->select($db->qn($fields['catid'], 'catid')); + + // Join over the categories. + $query->select($db->qn('c.title', 'category_title')) + ->join('LEFT', $db->qn('#__categories', 'c') . ' ON ' . $db->qn('c.id') . ' = ' . $db->qn($fields['catid'])); + + $groupby[] = 'c.title'; + } + + // If component item type supports menu type, select the menu type also. + if (!empty($fields['menutype'])) + { + $query->select($db->qn($fields['menutype'], 'menutype')); + + // Join over the menu types. + $query->select($db->qn('mt.title', 'menutype_title')) + ->select($db->qn('mt.id', 'menutypeid')) + ->join('LEFT', $db->qn('#__menu_types', 'mt') . ' ON ' . $db->qn('mt.menutype') . ' = ' . $db->qn($fields['menutype'])); + + $groupby[] = 'mt.title'; + $groupby[] = 'mt.id'; + } + + // If component item type supports access level, select the access level also. + if (array_key_exists('acl', $support) && $support['acl'] == true && ! empty($fields['access'])) + { + $query->select($db->qn($fields['access'], 'access')); + + // Join over the access levels. + $query->select($db->qn('ag.title', 'access_level')) + ->join('LEFT', $db->qn('#__viewlevels', 'ag') . ' ON ' . $db->qn('ag.id') . ' = ' . $db->qn($fields['access'])); + + $groupby[] = 'ag.title'; + + // Implement View Level Access. + if (!$user->authorise('core.admin', $extension)) + { + $query->where($fields['access'] . ' IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'); + } + } + + // If component item type is menus we need to remove the root item and the administrator menu. + if ($extension === 'com_menus') + { + $query->where($db->qn($fields['id']) . ' > 1') + ->where($db->qn('a.client_id') . ' = 0'); + } + // If component item type is categories we need to remove all other component categories. + elseif ($extension === 'com_categories') + { + $query->where($db->qn('a.extension') . ' = ' . $db->quote('X')); + } + + // Filter on the language. + if ($language = $this->getState('language')) + { + $query->where($db->qn($fields['language']) . ' = ' . $db->quote($language)); + } + + // Filter by item state. + $state = $this->getState('filter.state'); + + if (is_numeric($state)) + { + $query->where($db->qn($fields['state']) . ' = ' . (int) $state); + } + elseif ($state === '') + { + $query->where($db->qn($fields['state']) . ' IN (0, 1)'); + } + + // Filter on the category. + $baselevel = 1; + + if ($categoryId = $this->getState('filter.category_id')) + { + $categoryTable = JTable::getInstance('Category', 'JTable'); + $categoryTable->load($categoryId); + $baselevel = (int) $categoryTable->level; + + $query->where($db->qn('c.lft') . ' >= ' . (int) $categoryTable->lft) + ->where($db->qn('c.rgt') . ' <= ' . (int) $categoryTable->rgt); + } + + // Filter on the level. + if ($level = $this->getState('filter.level')) + { + $tableAlias = in_array($extension, array('com_menus', 'com_categories')) ? 'a' : 'c'; + $query->where($db->qn($tableAlias . '.level') . ' <= ' . ((int) $level + (int) $baselevel - 1)); + } + + // Filter by menu type. + if ($menutype = $this->getState('filter.menutype')) + { + $query->where($fields['menutype'] . ' = ' . $db->quote($menutype)); + } + + // Filter by access level. + if ($access = $this->getState('filter.access')) + { + $query->where($fields['access'] . ' = ' . (int) $access); + } + + // Filter by search in name. + if ($search = $this->getState('filter.search')) + { + if (stripos($search, 'id:') === 0) + { + $query->where($db->qn($fields['id']) . ' = ' . (int) substr($search, 3)); + } + else + { + $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); + $query->where('(' . $db->qn($fields['title']) . ' LIKE ' . $search + . ' OR ' . $db->qn($fields['alias']) . ' LIKE ' . $search . ')'); + } + } + + // Add the group by clause + $query->group($db->qn($groupby)); + + // Add the list ordering clause. + $query->order($db->escape($this->getState('list.ordering') . ' ' . $this->getState('list.direction'))); + + return $query; + } + + /** + * Delete associations from #__associations table. + * + * @param string $context The associations context. Empty for all. + * @param string $key The associations key. Empty for all. + * + * @return boolean True on success. + * + * @since __DEPLOY_VERSION__ + */ + public function purge($context = '', $key = '') + { + $db = $this->getDbo(); + $app = JFactory::getApplication(); + + $query = $db->getQuery(true)->delete($db->qn('#__associations')); + + // Filter by associations context. + if ($context) + { + $query->where($db->qn('context') . ' = ' . $db->quote($context)); + } + + // Filter by key. + if ($key) + { + $query->where($db->qn('key') . ' = ' . $db->quote($key)); + } + + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (JDatabaseExceptionExecuting $e) + { + $app->enqueueMessage(JText::_('COM_ASSOCIATIONS_PURGE_FAILED'), 'error'); + + return false; + } + + $app->enqueueMessage(JText::_((int) $db->getAffectedRows() > 0 ? 'COM_ASSOCIATIONS_PURGE_SUCCESS' : 'COM_ASSOCIATIONS_PURGE_NONE'), 'message'); + + return true; + } + + /** + * Delete orphans from the #__associations table. + * + * @param string $context The associations context. Empty for all. + * @param string $key The associations key. Empty for all. + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function clean($context = '', $key = '') + { + $db = $this->getDbo(); + $app = JFactory::getApplication(); + + $query = $db->getQuery(true) + ->select($db->qn('key') . ', COUNT(*)') + ->from($db->qn('#__associations')) + ->group($db->qn('key')) + ->having('COUNT(*) = 1'); + + // Filter by associations context. + if ($context) + { + $query->where($db->qn('context') . ' = ' . $db->quote($context)); + } + + // Filter by key. + if ($key) + { + $query->where($db->qn('key') . ' = ' . $db->quote($key)); + } + + $db->setQuery($query); + + $assocKeys = $db->loadObjectList(); + + $count = 0; + + // We have orphans. Let's delete them. + foreach ($assocKeys as $value) + { + $query->clear() + ->delete($db->qn('#__associations')) + ->where($db->qn('key') . ' = ' . $db->quote($value->key)); + + $db->setQuery($query); + + try + { + $db->execute(); + } + catch (JDatabaseExceptionExecuting $e) + { + $app->enqueueMessage(JText::_('COM_ASSOCIATIONS_DELETE_ORPHANS_FAILED'), 'error'); + + return false; + } + + $count += (int) $db->getAffectedRows(); + } + + $app->enqueueMessage(JText::_($count > 0 ? 'COM_ASSOCIATIONS_DELETE_ORPHANS_SUCCESS' : 'COM_ASSOCIATIONS_DELETE_ORPHANS_NONE'), 'message'); + + return true; + } +} diff --git a/administrator/components/com_associations/models/fields/itemlanguage.php b/administrator/components/com_associations/models/fields/itemlanguage.php new file mode 100644 index 0000000000000..a49eb636b0b5c --- /dev/null +++ b/administrator/components/com_associations/models/fields/itemlanguage.php @@ -0,0 +1,116 @@ +input; + + list($extensionName, $typeName) = explode('.', $input->get('itemtype')); + + $extension = AssociationsHelper::getSupportedExtension($extensionName); + $types = $extension->get('types'); + + if (array_key_exists($typeName, $types)) + { + $type = $types[$typeName]; + } + + $details = $type->get('details'); + + if (array_key_exists('fields', $details)) + { + $fields = $details['fields']; + } + + $languageField = substr($fields['language'], 2); + $referenceId = $input->get('id', 0, 'int'); + $reference = ArrayHelper::fromObject(AssociationsHelper::getItem($extensionName, $typeName, $referenceId)); + $referenceLang = $reference[$languageField]; + + // Get item associations given ID and item type + $associations = AssociationsHelper::getAssociationList($extensionName, $typeName, $referenceId); + + // Check if user can create items in this component item type. + $canCreate = AssociationsHelper::allowAdd($extensionName, $typeName); + + // Gets existing languages. + $existingLanguages = AssociationsHelper::getContentLanguages(); + + $options = array(); + + // Each option has the format "|", example: "en-GB|1" + foreach ($existingLanguages as $langCode => $language) + { + // If language code is equal to reference language we don't need it. + if ($language->lang_code == $referenceLang) + { + continue; + } + + $options[$langCode] = new stdClass; + $options[$langCode]->text = $language->title; + + // If association exists in this language. + if (isset($associations[$language->lang_code])) + { + $itemId = (int) $associations[$language->lang_code]['id']; + $options[$langCode]->value = $language->lang_code . ':' . $itemId . ':edit'; + + // Check if user does have permission to edit the associated item. + $canEdit = AssociationsHelper::allowEdit($extensionName, $typeName, $itemId); + + // ToDo: Do an additional check to check if user can edit a checked out item (if component item type supports it). + $canCheckout = true; + + // Disable language if user is not allowed to edit the item associated to it. + $options[$langCode]->disable = !($canEdit && $canCheckout); + } + else + { + // New item, id = 0 and disabled if user is not allowed to create new items. + $options[$langCode]->value = $language->lang_code . ':0:add'; + + // Disable language if user is not allowed to create items. + $options[$langCode]->disable = !$canCreate; + } + } + + return array_merge(parent::getOptions(), $options); + } +} diff --git a/administrator/components/com_associations/models/fields/itemtype.php b/administrator/components/com_associations/models/fields/itemtype.php new file mode 100644 index 0000000000000..45d01e7aae237 --- /dev/null +++ b/administrator/components/com_associations/models/fields/itemtype.php @@ -0,0 +1,62 @@ +get('associationssupport') === true) + { + foreach ($extension->get('types') as $type) + { + $context = $extension->get('component') . '.' . $type->get('name'); + $options[$extension->get('title')][] = JHtml::_('select.option', $context, $type->get('title')); + } + } + } + + // Sort by alpha order. + ksort($options, SORT_NATURAL); + + // Add options to parent array. + return array_merge(parent::getGroups(), $options); + } +} diff --git a/administrator/components/com_associations/models/fields/modalassociation.php b/administrator/components/com_associations/models/fields/modalassociation.php new file mode 100644 index 0000000000000..be7f594c316b7 --- /dev/null +++ b/administrator/components/com_associations/models/fields/modalassociation.php @@ -0,0 +1,105 @@ +value > 0 ? (int) $this->value : ''; + + // Build the script. + $script = array(); + + // Select button script + $script[] = ' function jSelectAssociation_' . $this->id . '(id) {'; + $script[] = ' target = document.getElementById("target-association");'; + $script[] = ' document.getElementById("target-association").src = target.getAttribute("data-editurl") + ' + . '"&task=" + target.getAttribute("data-item") + ".edit" + "&id=" + id'; + $script[] = ' jQuery("#associationSelect' . $this->id . 'Modal").modal("hide");'; + $script[] = ' }'; + + // Add the script to the document head. + JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); + + // Setup variables for display. + $html = array(); + + $linkAssociations = 'index.php?option=com_associations&view=associations&layout=modal&tmpl=component' + . '&forcedItemType=' . JFactory::getApplication()->input->get('itemtype', '', 'string') . '&function=jSelectAssociation_' . $this->id; + + $linkAssociations .= "&forcedLanguage=' + document.getElementById('target-association').getAttribute('data-language') + '"; + + $urlSelect = $linkAssociations . '&' . JSession::getFormToken() . '=1'; + + // Select custom association button + $html[] = '' + . '' + . '' + . ''; + + // Clear association button + $html[] = '' + . '' . JText::_('JCLEAR') + . ''; + + $html[] = ''; + + // Select custom association modal + $html[] = JHtml::_( + 'bootstrap.renderModal', + 'associationSelect' . $this->id . 'Modal', + array( + 'title' => JText::_('COM_ASSOCIATIONS_SELECT_TARGET'), + 'backdrop' => 'static', + 'url' => $urlSelect, + 'height' => '400px', + 'width' => '800px', + 'bodyHeight' => '70', + 'modalWidth' => '80', + 'footer' => '', + ) + ); + + return implode("\n", $html); + } +} diff --git a/administrator/components/com_associations/models/forms/association.xml b/administrator/components/com_associations/models/forms/association.xml new file mode 100644 index 0000000000000..9e8d880e22984 --- /dev/null +++ b/administrator/components/com_associations/models/forms/association.xml @@ -0,0 +1,21 @@ + +
+
+ + + + + +
+ + + +
diff --git a/administrator/components/com_associations/models/forms/filter_associations.xml b/administrator/components/com_associations/models/forms/filter_associations.xml new file mode 100644 index 0000000000000..72d2c980c8afc --- /dev/null +++ b/administrator/components/com_associations/models/forms/filter_associations.xml @@ -0,0 +1,107 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/administrator/components/com_associations/views/association/tmpl/edit.php b/administrator/components/com_associations/views/association/tmpl/edit.php new file mode 100644 index 0000000000000..51454d113a514 --- /dev/null +++ b/administrator/components/com_associations/views/association/tmpl/edit.php @@ -0,0 +1,73 @@ +app->input; +$options = array( + 'layout' => $input->get('layout', '', 'string'), + 'itemtype' => $this->itemtype, + 'id' => $this->referenceId, + ); +?> + + +
+ +
+ +
+
+

+ +
+
+
+
+
+

+ form->getInput('modalassociation'); ?> + form->getInput('itemlanguage'); ?> +
+ +
+
+ +
+ + + + +
diff --git a/administrator/components/com_associations/views/association/view.html.php b/administrator/components/com_associations/views/association/view.html.php new file mode 100644 index 0000000000000..c4ce0ea7d22c3 --- /dev/null +++ b/administrator/components/com_associations/views/association/view.html.php @@ -0,0 +1,202 @@ +get('Errors'))) + { + throw new Exception(implode("\n", $errors), 500); + + return false; + } + + $this->app = JFactory::getApplication(); + + $this->form = $this->get('Form'); + $input = $this->app->input; + + $this->referenceId = $input->get('id', 0, 'int'); + + list($extensionName, $typeName) = explode('.', $input->get('itemtype')); + + $extension = AssociationsHelper::getSupportedExtension($extensionName); + + $types = $extension->get('types'); + + if (array_key_exists($typeName, $types)) + { + $this->type = $types[$typeName]; + } + + $this->itemtype = $extensionName . '.' . $typeName; + + $details = $this->type->get('details'); + + if (array_key_exists('fields', $details)) + { + $fields = $details['fields']; + } + + $languageField = substr($fields['language'], 2); + $referenceId = $input->get('id', 0, 'int'); + $reference = ArrayHelper::fromObject(AssociationsHelper::getItem($extensionName, $typeName, $referenceId)); + + $this->referenceLanguage = $reference[$languageField]; + + $options = array( + 'option' => $typeName === 'category' ? 'com_categories' : $extensionName, + 'view' => $typeName, + 'extension' => $extensionName, + 'tmpl' => 'component', + ); + + // Reference and target edit links. + $this->editUri = 'index.php?' . http_build_query($options); + + // Get target language. + $this->targetId = '0'; + $this->targetLanguage = ''; + $this->defaultTargetSrc = ''; + $this->targetAction = ''; + + if ($target = $input->get('target', '', 'string')) + { + $matches = preg_split("#[\:]+#", $target); + $this->targetAction = $matches[2]; + $this->targetId = $matches[1]; + $this->targetLanguage = $matches[0]; + $task = $typeName . '.' . $this->targetAction; + $this->defaultTargetSrc = JRoute::_($this->editUri . '&task= ' . $task . ' &id=' . (int) $this->targetId); + $this->form->setValue('itemlanguage', '', $this->targetLanguage . ':' . $this->targetId . ':' . $this->targetAction); + } + + /* + * @todo Review later + */ + + // We don't need toolbar in the modal window. + if ($this->getLayout() !== 'modal') + { + $this->addToolbar(); + $this->sidebar = JHtmlSidebar::render(); + } + else + { + // In article associations modal we need to remove language filter if forcing a language. + // We also need to change the category filter to show show categories with All or the forced language. + if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD')) + { + // If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field. + $languageXml = new SimpleXMLElement(''); + $this->filterForm->setField($languageXml, 'filter', true); + + // Also, unset the active language filter so the search tools is not open by default with this filter. + unset($this->activeFilters['language']); + + // One last changes needed is to change the category filter to just show categories with All language or with the forced language. + $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter'); + } + } + + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + protected function addToolbar() + { + // Hide main menu. + JFactory::getApplication()->input->set('hidemainmenu', 1); + + JToolbarHelper::title(JText::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', 'componentTitle', 'title'), 'contract'); + + $bar = JToolbar::getInstance('toolbar'); + + $bar->appendButton( + 'Custom', '', 'reference' + ); + + $bar->appendButton( + 'Custom', '', 'target' + ); + + JToolBarHelper::custom('copy', 'copy.png', '', 'COM_ASSOCIATIONS_COPY_REFERENCE', false); + + JToolbarHelper::cancel('association.cancel', 'JTOOLBAR_CLOSE'); + JToolbarHelper::help('JGLOBAL_HELP'); + + JHtmlSidebar::setAction('index.php?option=com_associations'); + } +} diff --git a/administrator/components/com_associations/views/associations/tmpl/default.php b/administrator/components/com_associations/views/associations/tmpl/default.php new file mode 100644 index 0000000000000..7943bff2f4d26 --- /dev/null +++ b/administrator/components/com_associations/views/associations/tmpl/default.php @@ -0,0 +1,174 @@ +escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); +$canManageCheckin = JFactory::getUser()->authorise('core.manage', 'com_checkin'); +$colSpan = 5; +$iconStates = array( + -2 => 'icon-trash', + 0 => 'icon-unpublish', + 1 => 'icon-publish', + 2 => 'icon-archive', +); + +JText::script('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT'); + +JFactory::getDocument()->addScriptDeclaration(' + Joomla.submitbutton = function(pressbutton) + { + if (pressbutton == "associations.purge") + { + if (confirm(Joomla.JText._("COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT"))) + { + Joomla.submitform(pressbutton); + } + else + { + return false; + } + } + else + { + Joomla.submitform(pressbutton); + } + }; +'); +?> +
+ +sidebar)) : ?> +
+ sidebar; ?> +
+
+ +
+ + + $this, 'options' => array('filterButton' => !is_null($this->itemType)))); ?> + items)) : ?> +
+ +
+ + + + + typeSupports['state'])) : ?> + + + + + + typeFields['menutype'])) : ?> + + + typeFields['access'])) : ?> + + + + + + + + + + + + items as $i => $item) : + $canCheckin = true; + $canEdit = AssociationsHelper::allowEdit($this->extensionName, $this->typeName, $item->id); + $canCheckin = $canManageCheckin || AssociationsHelper::typeSupportsCheckout($this->extensionName, $this->typeName); + ?> + + typeSupports['state'])) : ?> + + + + + + typeFields['menutype'])) : ?> + + + typeFields['access'])) : ?> + + + + + + +
+ + + + + + + + + + + + + +
+ pagination->getListFooter(); ?> +
+ + + level)) : ?> + $item->level)); ?> + + checked_out) && $item->checked_out) : ?> + editor, $item->checked_out_time, 'associations.', $canCheckin); ?> + + + + escape($item->title); ?> + + escape($item->title); ?> + + typeFields['alias'])) : ?> + + escape($item->alias)); ?> + + + typeFields['catid'])) : ?> +
+ escape($item->category_title); ?> +
+ +
+ language_title ? JHtml::_('image', 'mod_languages/' . $item->language_image . '.gif', $item->language_title, array('title' => $item->language_title), true) . ' ' . $this->escape($item->language_title) : JText::_('JUNDEFINED'); ?> + + extensionName, $this->typeName, (int) $item->id, $item->language); ?> + + escape($item->menutype_title); ?> + + escape($item->access_level); ?> + + id; ?> +
+ + + + + +
+ diff --git a/administrator/components/com_associations/views/associations/tmpl/modal.php b/administrator/components/com_associations/views/associations/tmpl/modal.php new file mode 100644 index 0000000000000..8ed89e8a6ca4b --- /dev/null +++ b/administrator/components/com_associations/views/associations/tmpl/modal.php @@ -0,0 +1,162 @@ +isSite()) +{ + JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN')); +} + +JHtml::_('jquery.framework'); +JHtml::_('bootstrap.tooltip'); +JHtml::_('behavior.multiselect'); +JHtml::_('formbehavior.chosen', 'select'); + +$function = $app->input->getCmd('function', 'jSelectAssociation'); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); +$colSpan = 4; +$iconStates = array( + -2 => 'icon-trash', + 0 => 'icon-unpublish', + 1 => 'icon-publish', + 2 => 'icon-archive', +); + +$app->getDocument()->addScriptDeclaration( + "jQuery(document).ready(function($) { + // Run function on parent window. + $('.select-link').on('click', function() { + if (self != top) + { + window.parent." . $function . "(this.getAttribute('data-id')); + } + }); + });" +); +?> +
+ +sidebar)) : ?> +
+ sidebar; ?> +
+
+ +
+ + + $this)); ?> + items)) : ?> +
+ +
+ + + + + typeSupports['state'])) : ?> + + + + + + typeFields['menutype'])) : ?> + + + typeSupports['acl'])) : ?> + + + + + + + + + + + + items as $i => $item) : + ?> + + typeSupports['state'])) : ?> + + + + + + typeFields['menutype'])) : ?> + + + typeSupports['acl'])) : ?> + + + + + + +
+ + + + + + + + + + + + + +
+ pagination->getListFooter(); ?> +
+ + + level)) : ?> + $item->level)); ?> + + escape($item->title); ?> + typeFields['alias'])) : ?> + + escape($item->alias)); ?> + + + typeFields['catid'])) : ?> +
+ escape($item->category_title); ?> +
+ +
+ language_title ? JHtml::_('image', 'mod_languages/' . $item->language_image . '.gif', $item->language_title, array('title' => $item->language_title), true) . ' ' . $this->escape($item->language_title) : JText::_('JUNDEFINED'); ?> + + association) : ?> + extensionName, $this->typeName, (int) $item->id, $item->language, false); ?> + + + escape($item->menutype_title); ?> + + escape($item->access_level); ?> + + id; ?> +
+ + + + + + + +
+ diff --git a/administrator/components/com_associations/views/associations/view.html.php b/administrator/components/com_associations/views/associations/view.html.php new file mode 100644 index 0000000000000..d8c9d29f4eae5 --- /dev/null +++ b/administrator/components/com_associations/views/associations/view.html.php @@ -0,0 +1,224 @@ +state = $this->get('State'); + $this->filterForm = $this->get('FilterForm'); + $this->activeFilters = $this->get('ActiveFilters'); + + if (!JLanguageAssociations::isEnabled()) + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_ASSOCIATIONS_ERROR_NO_ASSOC'), 'warning'); + } + elseif ($this->state->get('itemtype') == '' || $this->state->get('language') == '') + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_ASSOCIATIONS_NOTICE_NO_SELECTORS'), 'notice'); + } + else + { + $type = null; + + list($extensionName, $typeName) = explode('.', $this->state->get('itemtype')); + + $extension = AssociationsHelper::getSupportedExtension($extensionName); + + $types = $extension->get('types'); + + if (array_key_exists($typeName, $types)) + { + $type = $types[$typeName]; + } + + $this->itemType = $type; + + if (is_null($type)) + { + JFactory::getApplication()->enqueueMessage(JText::_('COM_ASSOCIATIONS_ERROR_NO_TYPE'), 'warning'); + } + else + { + $this->extensionName = $extensionName; + $this->typeName = $typeName; + $this->typeSupports = array(); + $this->typeFields = array(); + + $details = $type->get('details'); + + if (array_key_exists('support', $details)) + { + $support = $details['support']; + $this->typeSupports = $support; + } + + if (array_key_exists('fields', $details)) + { + $fields = $details['fields']; + $this->typeFields = $fields; + } + + // Dynamic filter form. + // This selectors doesn't have to activate the filter bar. + unset($this->activeFilters['itemtype']); + unset($this->activeFilters['language']); + + // Remove filters options depending on selected type. + if (empty($support['state'])) + { + unset($this->activeFilters['state']); + $this->filterForm->removeField('state', 'filter'); + } + if ($type !== 'category') + { + unset($this->activeFilters['category_id']); + $this->filterForm->removeField('category_id', 'filter'); + } + if ($extension !== 'com_menu') + { + unset($this->activeFilters['menutype']); + $this->filterForm->removeField('menutype', 'filter'); + } + if (! in_array($extension, array('com_categories', 'com_menus'))) + { + unset($this->activeFilters['level']); + $this->filterForm->removeField('level', 'filter'); + } + if (empty($support['acl'])) + { + unset($this->activeFilters['access']); + $this->filterForm->removeField('access', 'filter'); + } + + // Add extension attribute to category filter. + if (empty($support['catid'])) + { + $this->filterForm->setFieldAttribute('category_id', 'extension', $extension, 'filter'); + } + + $this->items = $this->get('Items'); + $this->pagination = $this->get('Pagination'); + + $linkParameters = array( + 'layout' => 'edit', + 'itemtype' => $extensionName . '.' . $typeName, + 'task' => 'association.edit', + ); + + $this->editUri = 'index.php?option=com_associations&view=association&' . http_build_query($linkParameters); + } + } + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + throw new Exception(implode("\n", $errors), 500); + + return false; + } + + $this->addToolbar(); + + // Will add sidebar if needed $this->sidebar = JHtmlSidebar::render(); + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + protected function addToolbar() + { + $user = JFactory::getUser(); + + if (isset($this->itemType)) + { + JToolbarHelper::title( + JText::sprintf( + 'COM_ASSOCIATIONS_TITLE_LIST', JText::_($this->extensionName), JText::_($this->typeName) + ), 'contract' + ); + } + else + { + JToolbarHelper::title(JText::_('COM_ASSOCIATIONS_TITLE_LIST_SELECT'), 'contract'); + } + + if ($user->authorise('core.admin', 'com_associations') || $user->authorise('core.options', 'com_associations')) + { + if (!isset($this->typeName)) + { + JToolbarHelper::custom('associations.purge', 'purge', 'purge', 'COM_ASSOCIATIONS_PURGE', false, false); + JToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false); + } + JToolbarHelper::preferences('com_associations'); + } + + /* + * @todo Help page + */ + JToolbarHelper::help('JGLOBAL_HELP'); + } +} diff --git a/administrator/components/com_content/helpers/associations.php b/administrator/components/com_content/helpers/associations.php new file mode 100644 index 0000000000000..cfad7fbaa9e5b --- /dev/null +++ b/administrator/components/com_content/helpers/associations.php @@ -0,0 +1,181 @@ +getType($typeName); + + $context = $this->extension . '.item'; + $catidField = 'catid'; + + if ($typeName === 'category') + { + $context = 'com_categories.item'; + $catidField = ''; + } + + // Get the associations. + $associations = JLanguageAssociations::getAssociations( + $this->extension, + $type['tables']['a'], + $context, + $id, + 'id', + 'alias', + $catidField + ); + + return $associations; + } + + /** + * Get item information + * + * @param string $typeName The item type + * @param int $id The id of item for which we need the associated items + * + * @return JTable|null + * + * @since __DEPLOY_VERSION__ + */ + public function getItem($typeName, $id) + { + if (empty($id)) + { + return null; + } + + $table = null; + + switch ($typeName) + { + case 'article': + $table = JTable::getInstance('content'); + break; + + case 'category': + $table = JTable::getInstance('category'); + break; + } + + if (is_null($table)) + { + return null; + } + + $table->load($id); + + return $table; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getType($typeName = '') + { + $fields = $this->getFieldsTemplate(); + $tables = array(); + $joins = array(); + $support = $this->getSupportTemplate(); + $title = ''; + + if (in_array($typeName, $this->itemTypes)) + { + + switch ($typeName) + { + case 'article': + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__content' + ); + $title = 'article'; + break; + + case 'category': + $fields['created_user_id'] = 'a.created_user_id'; + $fields['ordering'] = 'a.lft'; + $fields['level'] = 'a.level'; + $fields['catid'] = ''; + $fields['state'] = 'a.published'; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__categories' + ); + $title = 'category'; + break; + } + } + + return array( + 'fields' => $fields, + 'support' => $support, + 'tables' => $tables, + 'joins' => $joins, + 'title' => $title + ); + } +} diff --git a/administrator/components/com_menus/helpers/associations.php b/administrator/components/com_menus/helpers/associations.php new file mode 100644 index 0000000000000..44525efe92484 --- /dev/null +++ b/administrator/components/com_menus/helpers/associations.php @@ -0,0 +1,159 @@ +getType($typeName); + + $context = $this->extension . '.item'; + + // Get the associations. + $associations = JLanguageAssociations::getAssociations( + $this->extension, + $type['tables']['a'], + $context, + $id, + 'id', + 'alias', + '' + ); + + return $associations; + } + + /** + * Get item information + * + * @param string $typeName The item type + * @param int $id The id of item for which we need the associated items + * + * @return JTable|null + * + * @since __DEPLOY_VERSION__ + */ + public function getItem($typeName, $id) + { + if (empty($id)) + { + return null; + } + + $table = null; + + switch ($typeName) + { + case 'item': + $table = JTable::getInstance('menu'); + break; + } + + if (is_null($table)) + { + return null; + } + + $table->load($id); + + return $table; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getType($typeName = '') + { + $fields = $this->getFieldsTemplate(); + $tables = array(); + $joins = array(); + $support = $this->getSupportTemplate(); + $title = ''; + + if (in_array($typeName, $this->itemTypes)) + { + + switch ($typeName) + { + case 'item': + $fields['ordering'] = 'a.lft'; + $fields['level'] = 'a.level'; + $fields['catid'] = ''; + $fields['state'] = 'a.published'; + $fields['created_user_id'] = ''; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__menu' + ); + + $title = 'menu'; + break; + } + } + + return array( + 'fields' => $fields, + 'support' => $support, + 'tables' => $tables, + 'joins' => $joins, + 'title' => $title + ); + } +} diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini new file mode 100644 index 0000000000000..f251d5df4a03f --- /dev/null +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -0,0 +1,49 @@ +; Joomla! Project +; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +COM_ASSOCIATIONS="Multilingual Associations" +COM_ASSOCIATIONS_ADD_NEW_ASSOCIATION="Add new association" +COM_ASSOCIATIONS_ASSOCIATED_ITEM="Target" +COM_ASSOCIATIONS_CHANGE_TARGET="Change Target" +COM_ASSOCIATIONS_COMPONENT_NOT_SUPPORTED="The following component doesn't support associations:" +COM_ASSOCIATIONS_COMPONENT_SELECTOR_DESC="Select a component from this list" +COM_ASSOCIATIONS_COMPONENT_SELECTOR_LABEL="Select component" +COM_ASSOCIATIONS_CONFIGURATION="Multilingual Associations: Options" +COM_ASSOCIATIONS_COPY_REFERENCE="Copy Reference to Target" +COM_ASSOCIATIONS_DELETE_ORPHANS="Delete Orphans" +COM_ASSOCIATIONS_DELETE_ORPHANS_FAILED="Failed to delete orphans." +COM_ASSOCIATIONS_DELETE_ORPHANS_NONE="There were no orphans to delete." +COM_ASSOCIATIONS_DELETE_ORPHANS_SUCCESS="All orphans have been deleted." +COM_ASSOCIATIONS_EDIT_ASSOCIATION="Edit association" +COM_ASSOCIATIONS_EDIT_HIDE_REFERENCE="Hide Reference" +COM_ASSOCIATIONS_EDIT_SHOW_REFERENCE="Show Reference" +COM_ASSOCIATIONS_ERROR_NO_ASSOC="The Multilingual Associations component can't be used if the site is not set as multilingual and/or Items Associations is not enabled in the Language Filter plugin." +COM_ASSOCIATIONS_FILTER_MENUTYPE_DESC="Select a Menu" +COM_ASSOCIATIONS_FILTER_MENUTYPE_LABEL="Menu" +COM_ASSOCIATIONS_FILTER_SEARCH_DESC="Search an item by it's title" +COM_ASSOCIATIONS_FILTER_SEARCH_LABEL="Search item" +COM_ASSOCIATIONS_FILTER_SELECT_ITEM_TYPE="- Select Item Type -" +COM_ASSOCIATIONS_HEADING_ASSOCIATION="Associations" +COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" +COM_ASSOCIATIONS_HEADING_MENUTYPE_ASC="Menu ascending" +COM_ASSOCIATIONS_HEADING_MENUTYPE_DESC="Menu descending" +COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" +COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." +COM_ASSOCIATIONS_PURGE="Delete All Associations" +COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT="Are you sure you want to delete all associations? Confirming will permanently delete them!" +COM_ASSOCIATIONS_PURGE_FAILED="Failed to delete all associations." +COM_ASSOCIATIONS_PURGE_NONE="There were no associations to delete." +COM_ASSOCIATIONS_PURGE_SUCCESS="All associations have been deleted." +COM_ASSOCIATIONS_REFERENCE_ITEM="Reference" +COM_ASSOCIATIONS_SAVE_REFERENCE="Save Reference" +COM_ASSOCIATIONS_SAVE_TARGET="Save Target" +COM_ASSOCIATIONS_SELECT_MENU="- Select Menu -" +COM_ASSOCIATIONS_SELECT_TARGET="Select Target" +COM_ASSOCIATIONS_SELECT_TARGET_LANGUAGE="- Select Target Language -" +COM_ASSOCIATIONS_TITLE="Associations" +COM_ASSOCIATIONS_TITLE_EDIT="Multilingual Associations: Edit Associations (%1s > %2s)" +COM_ASSOCIATIONS_TITLE_LIST="Multilingual Associations (%1s > %2s)" +COM_ASSOCIATIONS_TITLE_LIST_SELECT="Multilingual Associations: Select Item Type and Language" +COM_ASSOCIATIONS_XML_DESCRIPTION="Improved multilingual content management component" diff --git a/administrator/language/en-GB/en-GB.com_associations.sys.ini b/administrator/language/en-GB/en-GB.com_associations.sys.ini new file mode 100644 index 0000000000000..e9846cdcd5aa3 --- /dev/null +++ b/administrator/language/en-GB/en-GB.com_associations.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +COM_ASSOCIATIONS="Multilingual Associations" +COM_ASSOCIATIONS_XML_DESCRIPTION="Improved multilingual content management component" \ No newline at end of file diff --git a/layouts/joomla/content/associations.php b/layouts/joomla/content/associations.php index 578d161317f1d..1af8a02ca76bf 100644 --- a/layouts/joomla/content/associations.php +++ b/layouts/joomla/content/associations.php @@ -15,7 +15,7 @@
    $item) : ?>
  • - link; ?> + link; ?>
diff --git a/libraries/joomla/association/extension/helper.php b/libraries/joomla/association/extension/helper.php new file mode 100644 index 0000000000000..7d961aa0a9252 --- /dev/null +++ b/libraries/joomla/association/extension/helper.php @@ -0,0 +1,256 @@ +associationsSupport; + } + + /** + * Get the item types + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getItemTypes() + { + return $this->itemTypes; + } + + /** + * Get the associated items for an item + * + * @param string $typeName The item type + * @param int $itemId The id of item for which we need the associated items + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function getAssociationList($typeName, $itemId) + { + $items = array(); + + $associations = $this->getAssociations($typeName, $itemId); + + foreach ($associations as $key => $association) + { + $items[$key] = ArrayHelper::fromObject($this->getItem($typeName, (int) $association->id), false); + } + + return $items; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getType($typeName = '') + { + $fields = $this->getFieldsTemplate(); + $tables = array(); + $joins = array(); + $support = $this->getSupportTemplate(); + $title = ''; + + return array( + 'fields' => $fields, + 'support' => $support, + 'tables' => $tables, + 'joins' => $joins, + 'title' => $title + ); + } + + /** + * Get information about the fields the type provides + * + * @param string $typeName The item type + * + * @return array Array of support information + * + * @since __DEPLOY_VERSION__ + */ + public function getTypeFields($typeName) + { + return $this->getTypeInformation($typeName, 'fields'); + } + + /** + * Get information about the fields the type provides + * + * @param string $typeName The item type + * + * @return array Array of support information + * + * @since __DEPLOY_VERSION__ + */ + public function getTypeSupport($typeName) + { + return $this->getTypeInformation($typeName, 'support'); + } + + /** + * Get information about the tables the type use + * + * @param string $typeName The item type + * + * @return array Array of support information + * + * @since __DEPLOY_VERSION__ + */ + public function getTypeTables($typeName) + { + return $this->getTypeInformation($typeName, 'tables'); + } + + /** + * Get information about the table joins for the type + * + * @param string $typeName The item type + * + * @return array Array of support information + * + * @since __DEPLOY_VERSION__ + */ + public function getTypeJoins($typeName) + { + return $this->getTypeInformation($typeName, 'joins'); + } + + /** + * Get the type title + * + * @param string $typeName The item type + * + * @return array Array of support information + * + * @since __DEPLOY_VERSION__ + */ + public function getTypeTitle($typeName) + { + $type = $this->getType($typeName); + + if (! array_key_exists('title', $type)) + { + return ''; + } + + return $type['title']; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * @param string $part part of the information + * + * @return array Array of support information + * + * @since __DEPLOY_VERSION__ + */ + private function getTypeInformation($typeName, $part = 'support') + { + $type = $this->getType($typeName); + + if (! array_key_exists($part, $type)) + { + return array(); + } + + return $type[$part]; + } + + /** + * Get default values for support array + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + protected function getSupportTemplate() + { + return array( + 'state' => false, + 'acl' => false, + 'checkout' => false + ); + } + + /** + * Get default values for fields array + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + protected function getFieldsTemplate() + { + return array( + 'id' => 'a.id', + 'title' => 'a.title', + 'alias' => 'a.alias', + 'ordering' => 'a.ordering', + 'menutype' => '', + 'level' => '', + 'catid' => 'a.catid', + 'language' => 'a.language', + 'access' => 'a.access', + 'state' => 'a.state', + 'created_user_id' => 'a.created_by', + 'checked_out_user_id' => 'a.checked_out', + 'checked_out_time' => 'a.checked_out_time' + ); + } +} diff --git a/libraries/joomla/association/extension/interface.php b/libraries/joomla/association/extension/interface.php new file mode 100644 index 0000000000000..8d194e5bb22b6 --- /dev/null +++ b/libraries/joomla/association/extension/interface.php @@ -0,0 +1,27 @@ +' + title + ''); + $(reference).contents().find('#jform_associations_' + languageCode).val(targetLoadedId).change().chosen(); + } + + // Update the target item associations tab. + var reference = document.getElementById('reference-association'); + var referenceId = reference.getAttribute('data-id'); + var languageCode = reference.getAttribute('data-language').replace(/-/, '_'); + var title = $(reference).contents().find('#jform_title').val(); + var target = $(this).contents(); + + // - For modal association selectors. + target.find('#jform_associations_' + languageCode + '_id').val(referenceId); + target.find('#jform_associations_' + languageCode + '_name').val(title); + + // - For chosen association selectors (menus). + target.find('#jform_associations_' + languageCode + '_chzn').remove(); + var chznField = target.find('#jform_associations_' + languageCode); + chznField.append(''); + chznField.val(referenceId).change().chosen(); + + var parse, langAssociation; + + $('#jform_itemlanguage option').each(function() + { + parse = $(this).val().split(':'); + + if (typeof parse[1] !== 'undefined' && parse[1] !== '0') + { + // - For modal association selectors. + langAssociation = parse[0].replace(/-/,'_'); + target.find('#jform_associations_' + langAssociation + '_id').val(parse[1]); + + // - For chosen association selectors (menus). + target.find('#jform_associations_' + langAssociation + '_chzn').remove(); + chznField = target.find('#jform_associations_' + langAssociation); + chznField.append(''); + chznField.val(parse[1]).change().chosen(); + } + }); + + // Iframe load finished, hide Joomla loading layer. + Joomla.loadingLayer('hide'); + } + }); +}); diff --git a/media/com_associations/js/sidebyside.js b/media/com_associations/js/sidebyside.js new file mode 100644 index 0000000000000..89e3c7484dcfc --- /dev/null +++ b/media/com_associations/js/sidebyside.js @@ -0,0 +1 @@ +jQuery(document).ready(function(a){a("#toolbar-target").hide(),a("#toolbar-copy").hide(),Joomla.submitbutton=function(b){if("association.cancel"==b)Joomla.submitform(b);else if("copy"==b)window.frames["reference-association"].Joomla.submitbutton(document.getElementById("adminForm").getAttribute("data-associatedview")+".save2copy");else if("undo-association"==b){var c=document.getElementById("reference-association"),d=document.getElementById("target-association"),f=(c.getAttribute("data-id"),c.getAttribute("data-language").replace(/-/,"_")),h=(d.getAttribute("data-id"),d.getAttribute("data-language").replace(/-/,"_"));c=a(c).contents(),d=a(d).contents(),c.find("#jform_associations_"+h+"_id").val(""),c.find("#jform_associations_"+h+"_name").val(""),c.find("#jform_associations_"+h+"_chzn").remove(),c.find("#jform_associations_"+h).val("").change().chosen();var i="";a("#jform_itemlanguage option").each(function(){i=a(this).val().split("|")[0],"undefined"!=typeof i&&(i=i.replace(/-/,"_"),d.find("#jform_associations_"+i+"_id").val(""),d.find("#jform_associations_"+i+"_chzn").remove(),d.find("#jform_associations_"+i).val("").change().chosen())}),d.find("#jform_associations_"+f+"_id").val(""),d.find("#jform_associations_"+f+"_name").val(""),d.find("#jform_associations_"+f+"_chzn").remove(),d.find("#jform_associations_"+f).val("").change().chosen();var j=a("#jform_itemlanguage").val(),k=h.replace(/_/,"-");a('#jform_itemlanguage option[value="'+j+'"]').val(k+":0:add"),a("#jform_itemlanguage").val("").change(),a("#jform_itemlanguage").trigger("liszt:updated"),Joomla.submitbutton("reference")}else a("#"+b+"-association").contents().find("#jform_language").attr("disabled",!1),window.frames[b+"-association"].Joomla.submitbutton(document.getElementById("adminForm").getAttribute("data-associatedview")+".apply");return!1},Joomla.loadingLayer("load"),a("body").on("click","#toogle-left-panel",function(){var b=this.getAttribute("data-hide-reference"),c=this.getAttribute("data-show-reference");a(this).text()===b?a(this).text(c):a(this).text(b),a("#left-panel").toggle(),a("#right-panel").toggleClass("full-width")}),a("body").on("change","#jform_itemlanguage",function(){var b=document.getElementById("target-association"),c=a(this).val();""!=c&&"undefined"!=typeof c?(b.setAttribute("data-action",c.split(":")[2]),b.setAttribute("data-id",c.split(":")[1]),b.setAttribute("data-language",c.split(":")[0]),Joomla.loadingLayer("show"),b.src=b.getAttribute("data-editurl")+"&task="+b.getAttribute("data-item")+"."+b.getAttribute("data-action")+"&id="+b.getAttribute("data-id")):(a("#toolbar-target").hide(),a("#toolbar-copy").hide(),a("#select-change").addClass("hidden"),a("#remove-assoc").addClass("hidden"),b.setAttribute("data-action",""),b.setAttribute("data-id","0"),b.setAttribute("data-language",""),b.src="")}),a("#reference-association").on("load",function(){if(a(this).contents().find("#jform_id").val()!==this.getAttribute("data-id")){var b=document.getElementById("target-association");b.src=b.getAttribute("data-editurl")+"&task="+b.getAttribute("data-item")+".edit&id="+a(this).contents().find("#jform_id").val(),this.src=this.getAttribute("data-editurl")+"&task="+this.getAttribute("data-item")+".edit&id="+this.getAttribute("data-id")}var c=a(this).contents();c.find("#jform_language_chzn").remove(),c.find("#jform_language").attr("disabled",!0).chosen(),c.find("#associations").find(".btn").remove();var d="";a("#jform_itemlanguage option").each(function(){d=a(this).val().split(":"),"undefined"!=typeof d[0]&&(langAssociation=d[0].replace(/-/,"_"),""==c.find("#jform_associations_"+langAssociation+"_id").val()&&c.find("#jform_associations_"+langAssociation+"_name").val(document.getElementById("reference-association").getAttribute("data-no-assoc")))}),Joomla.loadingLayer("hide")}),a("#target-association").on("load",function(){if(""!=this.getAttribute("src")){a("#toolbar-target").show(),a("#toolbar-copy").show(),a("#select-change").removeClass("hidden");var b=this.getAttribute("data-language"),c=this.getAttribute("data-id"),d=a(this).contents().find("#jform_id").val()||"0";if(a(this).contents().find('a[href="#associations"]').parent().hide(),a(this).contents().find("#associations").hasClass("active")&&(a(this).contents().find('a[href="#associations"]').parent().removeClass("active"),a(this).contents().find("#associations").removeClass("active"),a(this).contents().find(".nav-tabs").find("li").first().addClass("active"),a(this).contents().find(".tab-content").find(".tab-pane").first().addClass("active")),a(this).contents().find("#jform_language_chzn").remove(),a(this).contents().find("#jform_language").val(b).change().attr("disabled",!0).chosen(),"0"==d)document.getElementById("select-change-text").innerHTML=document.getElementById("select-change").getAttribute("data-select");else{document.getElementById("select-change-text").innerHTML=document.getElementById("select-change").getAttribute("data-change"),a("#remove-assoc").removeClass("hidden");var e=document.getElementById("target-id").value,f=""==e?d:e+","+d;document.getElementById("target-id").value=f,d!=c&&(a('#jform_itemlanguage option[value^="'+b+":"+c+':add"]').val(b+":"+d+":edit"),this.setAttribute("data-id",d),this.setAttribute("data-action","edit"));var g=document.getElementById("reference-association"),h=b.replace(/-/,"_"),i=a(this).contents().find("#jform_title").val();a(g).contents().find("#jform_associations_"+h+"_id").val(d),a(g).contents().find("#jform_associations_"+h+"_name").val(i),a(g).contents().find("#jform_associations_"+h+"_chzn").remove(),a(g).contents().find("#jform_associations_"+h).append('"),a(g).contents().find("#jform_associations_"+h).val(d).change().chosen()}var g=document.getElementById("reference-association"),j=g.getAttribute("data-id"),h=g.getAttribute("data-language").replace(/-/,"_"),i=a(g).contents().find("#jform_title").val(),k=a(this).contents();k.find("#jform_associations_"+h+"_id").val(j),k.find("#jform_associations_"+h+"_name").val(i),k.find("#jform_associations_"+h+"_chzn").remove();var l=k.find("#jform_associations_"+h);l.append('"),l.val(j).change().chosen();var m,n;a("#jform_itemlanguage option").each(function(){m=a(this).val().split(":"),"undefined"!=typeof m[1]&&"0"!==m[1]&&(n=m[0].replace(/-/,"_"),k.find("#jform_associations_"+n+"_id").val(m[1]),k.find("#jform_associations_"+n+"_chzn").remove(),l=k.find("#jform_associations_"+n),l.append(''),l.val(m[1]).change().chosen())}),Joomla.loadingLayer("hide")}})}); \ No newline at end of file From f341aad9c1f2ce2d958ef46d59ae75fe1571b997 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Mon, 9 Jan 2017 16:38:48 +0100 Subject: [PATCH 02/35] updated searchtool with the new way --- .../layouts/joomla/searchtools/default.php | 38 ------------------- .../models/forms/filter_associations.xml | 2 + .../views/associations/tmpl/default.php | 2 +- 3 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 administrator/components/com_associations/layouts/joomla/searchtools/default.php diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default.php b/administrator/components/com_associations/layouts/joomla/searchtools/default.php deleted file mode 100644 index e58e551374b6d..0000000000000 --- a/administrator/components/com_associations/layouts/joomla/searchtools/default.php +++ /dev/null @@ -1,38 +0,0 @@ -addStyleDeclaration(" - /* Fixed filter field in search bar */ - .js-stools .js-stools-selector { - float: left; - margin-right: 10px; - min-width: 220px; - } - html[dir=rtl] .js-stools .js-stools-selector { - float: right; - margin-left: 10px - margin-right: 0; - } - .js-stools .js-stools-container-bar .js-stools-selector .chzn-container { - padding: 3px 0; - } - "); -} - -// Display the main joomla layout -echo JLayoutHelper::render('joomla.searchtools.default', $data, null, array('component' => 'none')); diff --git a/administrator/components/com_associations/models/forms/filter_associations.xml b/administrator/components/com_associations/models/forms/filter_associations.xml index 72d2c980c8afc..f66f0f91588e6 100644 --- a/administrator/components/com_associations/models/forms/filter_associations.xml +++ b/administrator/components/com_associations/models/forms/filter_associations.xml @@ -5,6 +5,7 @@ type="itemtype" label="COM_ASSOCIATIONS_COMPONENT_SELECTOR_LABEL" description="COM_ASSOCIATIONS_COMPONENT_SELECTOR_DESC" + filtermode="selector" onchange="jQuery('select[id^=\'filter_\']').val('');jQuery('select[id^=\'list_\']').val('');this.form.submit();" > @@ -13,6 +14,7 @@ name="language" type="contentlanguage" label="JOPTION_FILTER_LANGUAGE" + filtermode="selector" description="JOPTION_FILTER_LANGUAGE_DESC" onchange="this.form.submit();" > diff --git a/administrator/components/com_associations/views/associations/tmpl/default.php b/administrator/components/com_associations/views/associations/tmpl/default.php index 7943bff2f4d26..13dcd056fc78a 100644 --- a/administrator/components/com_associations/views/associations/tmpl/default.php +++ b/administrator/components/com_associations/views/associations/tmpl/default.php @@ -61,7 +61,7 @@
- $this, 'options' => array('filterButton' => !is_null($this->itemType)))); ?> + $this)); ?> items)) : ?>
From 79d95a5aaa63cb9e59f5f654d05ca775e2c93c92 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Mon, 9 Jan 2017 16:48:46 +0100 Subject: [PATCH 03/35] udpated edit view title --- .../com_associations/views/association/view.html.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/views/association/view.html.php b/administrator/components/com_associations/views/association/view.html.php index c4ce0ea7d22c3..478f61d2d4147 100644 --- a/administrator/components/com_associations/views/association/view.html.php +++ b/administrator/components/com_associations/views/association/view.html.php @@ -82,6 +82,9 @@ public function display($tpl = null) list($extensionName, $typeName) = explode('.', $input->get('itemtype')); + $this->extensionName = $extensionName; + $this->typeName = $typeName; + $extension = AssociationsHelper::getSupportedExtension($extensionName); $types = $extension->get('types'); @@ -176,7 +179,7 @@ protected function addToolbar() // Hide main menu. JFactory::getApplication()->input->set('hidemainmenu', 1); - JToolbarHelper::title(JText::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', 'componentTitle', 'title'), 'contract'); + JToolbarHelper::title(JText::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', JText::_($this->extensionName), JText::_($this->typeName)), 'contract'); $bar = JToolbar::getInstance('toolbar'); From 7cf3996b621684a65660e12772cb409c48e6a913 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 09:00:10 +0100 Subject: [PATCH 04/35] added contact associationshelper class --- .../com_contact/helpers/associations.php | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 administrator/components/com_contact/helpers/associations.php diff --git a/administrator/components/com_contact/helpers/associations.php b/administrator/components/com_contact/helpers/associations.php new file mode 100644 index 0000000000000..588661fafb0e2 --- /dev/null +++ b/administrator/components/com_contact/helpers/associations.php @@ -0,0 +1,185 @@ +getType($typeName); + + $context = $this->extension . '.item'; + $catidField = 'catid'; + + if ($typeName === 'category') + { + $context = 'com_categories.item'; + $catidField = ''; + } + + // Get the associations. + $associations = JLanguageAssociations::getAssociations( + $this->extension, + $type['tables']['a'], + $context, + $id, + 'id', + 'alias', + $catidField + ); + + return $associations; + } + + /** + * Get item information + * + * @param string $typeName The item type + * @param int $id The id of item for which we need the associated items + * + * @return JTable|null + * + * @since __DEPLOY_VERSION__ + */ + public function getItem($typeName, $id) + { + if (empty($id)) + { + return null; + } + + $table = null; + + switch ($typeName) + { + case 'contact': + $table = JTable::getInstance('contact', 'ContactTable'); + break; + + case 'category': + $table = JTable::getInstance('category'); + break; + } + + if (empty($table)) + { + return null; + } + + $table->load($id); + + return $table; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getType($typeName = '') + { + $fields = $this->getFieldsTemplate(); + $tables = array(); + $joins = array(); + $support = $this->getSupportTemplate(); + $title = ''; + + if (in_array($typeName, $this->itemTypes)) + { + + switch ($typeName) + { + case 'contact': + $fields['title'] = 'a.name'; + $fields['state'] = 'a.published'; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__contact_details' + ); + $title = 'contact'; + break; + + case 'category': + $fields['created_user_id'] = 'a.created_user_id'; + $fields['ordering'] = 'a.lft'; + $fields['level'] = 'a.level'; + $fields['catid'] = ''; + $fields['state'] = 'a.published'; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__categories' + ); + $title = 'category'; + break; + } + } + + return array( + 'fields' => $fields, + 'support' => $support, + 'tables' => $tables, + 'joins' => $joins, + 'title' => $title + ); + } +} From c1ebda1315fa9688a2265e74e515b322b83770bf Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 09:00:24 +0100 Subject: [PATCH 05/35] temp fix --- .../components/com_associations/helpers/associations.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_associations/helpers/associations.php b/administrator/components/com_associations/helpers/associations.php index 55ec3af62c378..3aba5229ffa12 100644 --- a/administrator/components/com_associations/helpers/associations.php +++ b/administrator/components/com_associations/helpers/associations.php @@ -173,6 +173,11 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); + // Todo: move to a helper function + $helper = self::getExtensionHelper($extensionName); + $typeFields = $helper->getTypeFields($typeName); + $titleFieldName = substr($typeFields['title'], 2); + // Get all content languages. $languages = self::getContentLanguages(); @@ -197,7 +202,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Get html parameters. if (isset($items[$langCode])) { - $title = '

' . $items[$langCode]['title']; + $title = '

' . $items[$langCode][$titleFieldName]; $additional = ''; if (isset($items[$langCode]['category_title'])) From b6624914ed3f614002b59dccc721815ee648fc49 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 09:15:35 +0100 Subject: [PATCH 06/35] fix for category filter --- .../components/com_associations/models/associations.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_associations/models/associations.php b/administrator/components/com_associations/models/associations.php index a32796a5617b1..831d7a67df9d3 100644 --- a/administrator/components/com_associations/models/associations.php +++ b/administrator/components/com_associations/models/associations.php @@ -325,10 +325,11 @@ protected function getListQuery() $query->where($db->qn($fields['id']) . ' > 1') ->where($db->qn('a.client_id') . ' = 0'); } - // If component item type is categories we need to remove all other component categories. - elseif ($extension === 'com_categories') + + // If component item type is category we need to remove all other component categories. + if ($typeName === 'category') { - $query->where($db->qn('a.extension') . ' = ' . $db->quote('X')); + $query->where($db->qn('a.extension') . ' = ' . $db->quote($extensionName)); } // Filter on the language. From f7c85a5f40d99336963c5e6f9f40a9dc23f3d9be Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 09:25:00 +0100 Subject: [PATCH 07/35] added newsfeeds associations helper --- .../com_newsfeeds/helpers/associations.php | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 administrator/components/com_newsfeeds/helpers/associations.php diff --git a/administrator/components/com_newsfeeds/helpers/associations.php b/administrator/components/com_newsfeeds/helpers/associations.php new file mode 100644 index 0000000000000..30f397e3b3839 --- /dev/null +++ b/administrator/components/com_newsfeeds/helpers/associations.php @@ -0,0 +1,185 @@ +getType($typeName); + + $context = $this->extension . '.item'; + $catidField = 'catid'; + + if ($typeName === 'category') + { + $context = 'com_categories.item'; + $catidField = ''; + } + + // Get the associations. + $associations = JLanguageAssociations::getAssociations( + $this->extension, + $type['tables']['a'], + $context, + $id, + 'id', + 'alias', + $catidField + ); + + return $associations; + } + + /** + * Get item information + * + * @param string $typeName The item type + * @param int $id The id of item for which we need the associated items + * + * @return JTable|null + * + * @since __DEPLOY_VERSION__ + */ + public function getItem($typeName, $id) + { + if (empty($id)) + { + return null; + } + + $table = null; + + switch ($typeName) + { + case 'contact': + $table = JTable::getInstance('Newsfeed', 'NewsfeedsTable'); + break; + + case 'category': + $table = JTable::getInstance('category'); + break; + } + + if (empty($table)) + { + return null; + } + + $table->load($id); + + return $table; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getType($typeName = '') + { + $fields = $this->getFieldsTemplate(); + $tables = array(); + $joins = array(); + $support = $this->getSupportTemplate(); + $title = ''; + + if (in_array($typeName, $this->itemTypes)) + { + + switch ($typeName) + { + case 'newsfeed': + $fields['title'] = 'a.name'; + $fields['state'] = 'a.published'; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__newsfeeds' + ); + $title = 'newsfeed'; + break; + + case 'category': + $fields['created_user_id'] = 'a.created_user_id'; + $fields['ordering'] = 'a.lft'; + $fields['level'] = 'a.level'; + $fields['catid'] = ''; + $fields['state'] = 'a.published'; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + + $tables = array( + 'a' => '#__categories' + ); + $title = 'category'; + break; + } + } + + return array( + 'fields' => $fields, + 'support' => $support, + 'tables' => $tables, + 'joins' => $joins, + 'title' => $title + ); + } +} From 04958860ad7707e07fc31d250a3ce8d104a5e245 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 09:30:26 +0100 Subject: [PATCH 08/35] CAPS for params --- administrator/components/com_contact/helpers/associations.php | 4 ++-- administrator/components/com_content/helpers/associations.php | 4 ++-- .../components/com_newsfeeds/helpers/associations.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_contact/helpers/associations.php b/administrator/components/com_contact/helpers/associations.php index 588661fafb0e2..0550a2f8fb567 100644 --- a/administrator/components/com_contact/helpers/associations.php +++ b/administrator/components/com_contact/helpers/associations.php @@ -101,11 +101,11 @@ public function getItem($typeName, $id) switch ($typeName) { case 'contact': - $table = JTable::getInstance('contact', 'ContactTable'); + $table = JTable::getInstance('Contact', 'ContactTable'); break; case 'category': - $table = JTable::getInstance('category'); + $table = JTable::getInstance('Category'); break; } diff --git a/administrator/components/com_content/helpers/associations.php b/administrator/components/com_content/helpers/associations.php index cfad7fbaa9e5b..f1e9da2713e07 100644 --- a/administrator/components/com_content/helpers/associations.php +++ b/administrator/components/com_content/helpers/associations.php @@ -99,11 +99,11 @@ public function getItem($typeName, $id) switch ($typeName) { case 'article': - $table = JTable::getInstance('content'); + $table = JTable::getInstance('Content'); break; case 'category': - $table = JTable::getInstance('category'); + $table = JTable::getInstance('Category'); break; } diff --git a/administrator/components/com_newsfeeds/helpers/associations.php b/administrator/components/com_newsfeeds/helpers/associations.php index 30f397e3b3839..6a61334315948 100644 --- a/administrator/components/com_newsfeeds/helpers/associations.php +++ b/administrator/components/com_newsfeeds/helpers/associations.php @@ -105,7 +105,7 @@ public function getItem($typeName, $id) break; case 'category': - $table = JTable::getInstance('category'); + $table = JTable::getInstance('Category'); break; } From ebe4afc494dddf776ebabc38de688abd9115bc1f Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 09:47:04 +0100 Subject: [PATCH 09/35] lang tag and added a helper function --- .../com_associations/helpers/associations.php | 31 ++++++++++++++++--- .../joomla/association/extension/helper.php | 30 ++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_associations/helpers/associations.php b/administrator/components/com_associations/helpers/associations.php index 3aba5229ffa12..2d42eff54403f 100644 --- a/administrator/components/com_associations/helpers/associations.php +++ b/administrator/components/com_associations/helpers/associations.php @@ -173,10 +173,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId // Get the associations list for this item. $items = self::getAssociationList($extensionName, $typeName, $itemId); - // Todo: move to a helper function - $helper = self::getExtensionHelper($extensionName); - $typeFields = $helper->getTypeFields($typeName); - $titleFieldName = substr($typeFields['title'], 2); + $titleFieldName = self::getTypeFieldName($extensionName, $typeName, 'title'); // Get all content languages. $languages = self::getContentLanguages(); @@ -361,7 +358,7 @@ public static function getSupportedExtension($extensionName) $languageKey = strtoupper($extensionName . '_' . $title . 'S'); } - $title = $lang->hasKey($languageKey) ? JText::_($languageKey) : JText::_('ITEMS'); + $title = $lang->hasKey($languageKey) ? JText::_($languageKey) : JText::_('COM_ASSOCIATIONS_ITEMS'); $rType = new Registry; @@ -507,4 +504,28 @@ public static function typeSupportsCheckout($extensionName, $typeName) return ! empty($support['checkout']); } + + /** + * Get a table field name for a type + * + * @param string $extensionName The extension name with com_ + * @param string $typeName The item type + * @param string $fieldName The item type + * + * @return boolean True on allowed. + * + * @since __DEPLOY_VERSION__ + */ + public static function getTypeFieldName($extensionName, $typeName, $fieldName) + { + if (! self::hasSupport($extensionName)) + { + return false; + } + + // Get the extension specific helper method + $helper = self::getExtensionHelper($extensionName); + + return $helper->getTypeFieldName($typeName, $fieldName); + } } diff --git a/libraries/joomla/association/extension/helper.php b/libraries/joomla/association/extension/helper.php index 7d961aa0a9252..49dc1a6c2bba0 100644 --- a/libraries/joomla/association/extension/helper.php +++ b/libraries/joomla/association/extension/helper.php @@ -212,6 +212,36 @@ private function getTypeInformation($typeName, $part = 'support') return $type[$part]; } + /** + * Get a table field name for a type + * + * @param string $typeName The item type + * @param string $fieldName The item type + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public function getTypeFieldName($typeName, $fieldName) + { + $fields = $this->getTypeFields($typeName); + + if (! array_key_exists($fieldName, $fields)) + { + return ''; + } + + $tmp = $fields[$fieldName]; + $pos = strpos($tmp, '.'); + + if ($pos === false) + { + return $tmp; + } + + return substr($tmp, $pos + 1); + } + /** * Get default values for support array * From 00eb70b0957dbe0ad362a527c0c83ca24d7bc20c Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 10:17:23 +0100 Subject: [PATCH 10/35] added land tags --- administrator/language/en-GB/en-GB.com_associations.ini | 1 + administrator/language/en-GB/en-GB.com_contact.ini | 1 + administrator/language/en-GB/en-GB.com_menus.ini | 7 ++++--- administrator/language/en-GB/en-GB.com_newsfeeds.ini | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index f251d5df4a03f..95cd0ee122f5d 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -29,6 +29,7 @@ COM_ASSOCIATIONS_HEADING_ASSOCIATION="Associations" COM_ASSOCIATIONS_HEADING_MENUTYPE="Menu" COM_ASSOCIATIONS_HEADING_MENUTYPE_ASC="Menu ascending" COM_ASSOCIATIONS_HEADING_MENUTYPE_DESC="Menu descending" +COM_ASSOCIATIONS_ITEMS="Items" COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language" COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations." COM_ASSOCIATIONS_PURGE="Delete All Associations" diff --git a/administrator/language/en-GB/en-GB.com_contact.ini b/administrator/language/en-GB/en-GB.com_contact.ini index e58d9bdb19fd9..6c5feccb97f0f 100644 --- a/administrator/language/en-GB/en-GB.com_contact.ini +++ b/administrator/language/en-GB/en-GB.com_contact.ini @@ -20,6 +20,7 @@ COM_CONTACT_CONTACT_DETAILS="Details" COM_CONTACT_CONTACT_DISPLAY_DETAILS="Display options for the individual contact page." COM_CONTACT_CONTACT_SETTINGS_LABEL="Contact Options" COM_CONTACT_CONTACT_VIEW_DEFAULT_DESC="This links to the contact information for one contact." +COM_CONTACT_CONTACTS="Contact Items" COM_CONTACT_DETAILS="Contact Information" COM_CONTACT_EDIT_CONTACT="Edit Contact" COM_CONTACT_EDIT_DETAILS="Edit contact information displayed on an individual page." diff --git a/administrator/language/en-GB/en-GB.com_menus.ini b/administrator/language/en-GB/en-GB.com_menus.ini index fd62d4f5a8373..4a5442d843117 100644 --- a/administrator/language/en-GB/en-GB.com_menus.ini +++ b/administrator/language/en-GB/en-GB.com_menus.ini @@ -133,6 +133,7 @@ COM_MENUS_ITEMS_SET_HOME_0="No menu item set to home." COM_MENUS_ITEMS_SET_HOME_1="1 menu item successfully set to home." COM_MENUS_ITEMS_SET_HOME_MORE="%d menu items successfully set to home." COM_MENUS_ITEMS_UNSET_HOME="1 menu item successfully unset to home." +COM_MENUS_LABEL_HIDDEN="Hidden" COM_MENUS_LAYOUT_FEATURED_OPTIONS="Layout" COM_MENUS_LAYOUT_MENUTYPE_OPTIONS_LABEL="Menu Type" COM_MENUS_LINKTYPE_OPTIONS_LABEL="Link Type" @@ -145,13 +146,11 @@ COM_MENUS_MENU_MENUTYPE_LABEL="Menu Type" COM_MENUS_MENU_SAVE_SUCCESS="Menu successfully saved" COM_MENUS_MENU_SEARCH_FILTER="Search in Title or Menu type" COM_MENUS_MENU_SPRINTF="Menu: %s" -COM_MENUS_TYPE_SYSTEM="System Links" +COM_MENUS_MENUS="Menu items" COM_MENUS_MENU_TITLE_DESC="The title of the menu to display in the Administrator Menubar and lists." COM_MENUS_MENU_TYPE_NOT_ALLOWED="This is a reserved menutype." COM_MENUS_MENUS_FILTER_SEARCH_DESC="Search in title and menu type." COM_MENUS_MENUS_FILTER_SEARCH_LABEL="Search Menus" -COM_MENUS_PAGE_OPTIONS_LABEL="Page Display" -COM_MENUS_LABEL_HIDDEN="Hidden" ; in the following string ; %1$s is for module title, %2$s is for access-title, %3$s is for position COM_MENUS_MODULE_ACCESS_POSITION="%1$s (%2$s in %3$s)" @@ -176,6 +175,7 @@ COM_MENUS_NEW_MENUITEM="New Menu Item" COM_MENUS_NO_ITEM_SELECTED="No menu items selected." COM_MENUS_NO_MENUS_SELECTED="No menu selected." COM_MENUS_OPTION_SELECT_LEVEL="- Select Max Levels -" +COM_MENUS_PAGE_OPTIONS_LABEL="Page Display" COM_MENUS_REQUEST_FIELDSET_LABEL="Required Settings" COM_MENUS_SAVE_SUCCESS="Menu item successfully saved." COM_MENUS_SELECT_A_MENUITEM="Select a Menu Item" @@ -198,6 +198,7 @@ COM_MENUS_TYPE_HEADING="Menu Heading" COM_MENUS_TYPE_HEADING_DESC="A heading for use within menus, useful when separating menus with a separator." COM_MENUS_TYPE_SEPARATOR="Text Separator" COM_MENUS_TYPE_SEPARATOR_DESC="A text separator." +COM_MENUS_TYPE_SYSTEM="System Links" COM_MENUS_TYPE_UNEXISTING="Component '%s' does not exist." COM_MENUS_TYPE_UNKNOWN="Unknown" COM_MENUS_VIEW_EDIT_ITEM_TITLE="Menus: Edit Item" diff --git a/administrator/language/en-GB/en-GB.com_newsfeeds.ini b/administrator/language/en-GB/en-GB.com_newsfeeds.ini index adcc0aad9b756..dd1e3cdef50c3 100644 --- a/administrator/language/en-GB/en-GB.com_newsfeeds.ini +++ b/administrator/language/en-GB/en-GB.com_newsfeeds.ini @@ -115,6 +115,7 @@ COM_NEWSFEEDS_N_ITEMS_TRASHED_1="News feed successfully trashed." COM_NEWSFEEDS_N_ITEMS_UNPUBLISHED="%d news feeds successfully unpublished." COM_NEWSFEEDS_N_ITEMS_UNPUBLISHED_1="News feed successfully unpublished." COM_NEWSFEEDS_NEW_NEWSFEED="New News Feed" +COM_NEWSFEEDS_NEWSFEEDS="Newsfeeds" COM_NEWSFEEDS_NO_ITEM_SELECTED="No news feeds selected." COM_NEWSFEEDS_NONE="None" COM_NEWSFEEDS_NUM_ARTICLES_HEADING="# Articles" From a54d3f7a8411387a996b1a29b165aae2a17ee6f9 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 10:20:21 +0100 Subject: [PATCH 11/35] code style fix --- libraries/joomla/association/extension/helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/association/extension/helper.php b/libraries/joomla/association/extension/helper.php index 49dc1a6c2bba0..6d3af05182bf1 100644 --- a/libraries/joomla/association/extension/helper.php +++ b/libraries/joomla/association/extension/helper.php @@ -215,8 +215,8 @@ private function getTypeInformation($typeName, $part = 'support') /** * Get a table field name for a type * - * @param string $typeName The item type - * @param string $fieldName The item type + * @param string $typeName The item type + * @param string $fieldName The item type * * @return string * From f7ebff90344da168cbb46a3bcfffdbeb6bd54e93 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 10:41:38 +0100 Subject: [PATCH 12/35] better title in associations view --- .../views/associations/view.html.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_associations/views/associations/view.html.php b/administrator/components/com_associations/views/associations/view.html.php index d8c9d29f4eae5..e2278b37d4e3f 100644 --- a/administrator/components/com_associations/views/associations/view.html.php +++ b/administrator/components/com_associations/views/associations/view.html.php @@ -193,11 +193,22 @@ protected function addToolbar() { $user = JFactory::getUser(); - if (isset($this->itemType)) + if (isset($this->typeName) && isset($this->extensionName)) { + + $helper = AssociationsHelper::getExtensionHelper($this->extensionName); + $title = $helper->getTypeTitle($this->typeName); + + $languageKey = strtoupper($this->extensionName . '_' . $title . 'S'); + + if ($this->typeName === 'category') + { + $languageKey = strtoupper($this->extensionName) . '_CATEGORIES'; + } + JToolbarHelper::title( JText::sprintf( - 'COM_ASSOCIATIONS_TITLE_LIST', JText::_($this->extensionName), JText::_($this->typeName) + 'COM_ASSOCIATIONS_TITLE_LIST', JText::_($this->extensionName), JText::_($languageKey) ), 'contract' ); } From 87a3138d67758d94c78312ffc064162f71501a4b Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 10:43:45 +0100 Subject: [PATCH 13/35] better title --- .../com_associations/views/association/view.html.php | 12 +++++++++++- .../views/associations/view.html.php | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_associations/views/association/view.html.php b/administrator/components/com_associations/views/association/view.html.php index 478f61d2d4147..07e56af4b9fbc 100644 --- a/administrator/components/com_associations/views/association/view.html.php +++ b/administrator/components/com_associations/views/association/view.html.php @@ -179,7 +179,17 @@ protected function addToolbar() // Hide main menu. JFactory::getApplication()->input->set('hidemainmenu', 1); - JToolbarHelper::title(JText::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', JText::_($this->extensionName), JText::_($this->typeName)), 'contract'); + $helper = AssociationsHelper::getExtensionHelper($this->extensionName); + $title = $helper->getTypeTitle($this->typeName); + + $languageKey = strtoupper($this->extensionName . '_' . $title . 'S'); + + if ($this->typeName === 'category') + { + $languageKey = strtoupper($this->extensionName) . '_CATEGORIES'; + } + + JToolbarHelper::title(JText::sprintf('COM_ASSOCIATIONS_TITLE_EDIT', JText::_($this->extensionName), JText::_($languageKey)), 'contract'); $bar = JToolbar::getInstance('toolbar'); diff --git a/administrator/components/com_associations/views/associations/view.html.php b/administrator/components/com_associations/views/associations/view.html.php index e2278b37d4e3f..81fc381d251e1 100644 --- a/administrator/components/com_associations/views/associations/view.html.php +++ b/administrator/components/com_associations/views/associations/view.html.php @@ -195,7 +195,6 @@ protected function addToolbar() if (isset($this->typeName) && isset($this->extensionName)) { - $helper = AssociationsHelper::getExtensionHelper($this->extensionName); $title = $helper->getTypeTitle($this->typeName); From 100fb42b8aecb2dc0ec1e53c80597bfe09750cfb Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 12:50:10 +0100 Subject: [PATCH 14/35] use the usual naming --- administrator/language/en-GB/en-GB.com_contact.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/en-GB.com_contact.ini b/administrator/language/en-GB/en-GB.com_contact.ini index 6c5feccb97f0f..8440e4ff585c2 100644 --- a/administrator/language/en-GB/en-GB.com_contact.ini +++ b/administrator/language/en-GB/en-GB.com_contact.ini @@ -20,7 +20,7 @@ COM_CONTACT_CONTACT_DETAILS="Details" COM_CONTACT_CONTACT_DISPLAY_DETAILS="Display options for the individual contact page." COM_CONTACT_CONTACT_SETTINGS_LABEL="Contact Options" COM_CONTACT_CONTACT_VIEW_DEFAULT_DESC="This links to the contact information for one contact." -COM_CONTACT_CONTACTS="Contact Items" +COM_CONTACT_CONTACTS="Contact" COM_CONTACT_DETAILS="Contact Information" COM_CONTACT_EDIT_CONTACT="Edit Contact" COM_CONTACT_EDIT_DETAILS="Edit contact information displayed on an individual page." From 7b0b75f2a02b690ef39cc3b3aa5096917cb795a8 Mon Sep 17 00:00:00 2001 From: Robert Deutz Date: Tue, 10 Jan 2017 14:55:04 +0100 Subject: [PATCH 15/35] fix language tag, thanks to brian teeman and twitter :-) --- administrator/language/en-GB/en-GB.com_associations.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/en-GB.com_associations.ini b/administrator/language/en-GB/en-GB.com_associations.ini index 95cd0ee122f5d..a0657bdfd4366 100644 --- a/administrator/language/en-GB/en-GB.com_associations.ini +++ b/administrator/language/en-GB/en-GB.com_associations.ini @@ -22,7 +22,7 @@ COM_ASSOCIATIONS_EDIT_SHOW_REFERENCE="Show Reference" COM_ASSOCIATIONS_ERROR_NO_ASSOC="The Multilingual Associations component can't be used if the site is not set as multilingual and/or Items Associations is not enabled in the Language Filter plugin." COM_ASSOCIATIONS_FILTER_MENUTYPE_DESC="Select a Menu" COM_ASSOCIATIONS_FILTER_MENUTYPE_LABEL="Menu" -COM_ASSOCIATIONS_FILTER_SEARCH_DESC="Search an item by it's title" +COM_ASSOCIATIONS_FILTER_SEARCH_DESC="Search an item by its title" COM_ASSOCIATIONS_FILTER_SEARCH_LABEL="Search item" COM_ASSOCIATIONS_FILTER_SELECT_ITEM_TYPE="- Select Item Type -" COM_ASSOCIATIONS_HEADING_ASSOCIATION="Associations" From f50ad7885aaf592e01902de6784d581e60e435eb Mon Sep 17 00:00:00 2001 From: zero-24 Date: Tue, 10 Jan 2017 22:51:08 +0100 Subject: [PATCH 16/35] initial review --- .../com_associations/associations.php | 3 +- .../com_associations/associations.xml | 2 +- .../components/com_associations/config.xml | 3 +- .../com_associations/controller.php | 4 +- .../controllers/association.php | 14 +-- .../controllers/associations.php | 6 +- .../com_associations/helpers/associations.php | 91 +++++++++---------- .../joomla/searchtools/default/bar.php | 44 ++++----- .../com_associations/models/associations.php | 70 +++++++------- .../models/fields/itemlanguage.php | 7 +- .../models/fields/itemtype.php | 6 +- .../models/fields/modalassociation.php | 12 +-- .../models/forms/association.xml | 2 +- .../models/forms/filter_associations.xml | 23 +++-- .../views/association/tmpl/edit.php | 13 +-- .../views/association/view.html.php | 29 +++--- .../views/associations/tmpl/default.php | 27 +++--- .../views/associations/tmpl/modal.php | 19 ++-- .../views/associations/view.html.php | 22 ++--- 19 files changed, 188 insertions(+), 209 deletions(-) diff --git a/administrator/components/com_associations/associations.php b/administrator/components/com_associations/associations.php index 2c199cef7031e..e9aa67f8e8336 100644 --- a/administrator/components/com_associations/associations.php +++ b/administrator/components/com_associations/associations.php @@ -8,6 +8,7 @@ */ defined('_JEXEC') or die; + JHtml::_('behavior.tabstate'); if (!JFactory::getUser()->authorise('core.manage', 'com_associations')) @@ -24,7 +25,7 @@ { list($extensionName, $typeName) = explode('.', $itemtype); - if (! AssociationsHelper::hasSupport($extensionName)) + if (!AssociationsHelper::hasSupport($extensionName)) { throw new Exception(JText::_('COM_ASSOCIATIONS_COMPONENT_NOT_SUPPORTED') . ' ' . $itemType->realcomponent, 404); } diff --git a/administrator/components/com_associations/associations.xml b/administrator/components/com_associations/associations.xml index 082bab1233824..2e058c522c09b 100644 --- a/administrator/components/com_associations/associations.xml +++ b/administrator/components/com_associations/associations.xml @@ -2,7 +2,7 @@ com_associations Joomla! Project - September 2016 + Januar 2017 (C) 2005 - 2016 Open Source Matters. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt admin@joomla.org diff --git a/administrator/components/com_associations/config.xml b/administrator/components/com_associations/config.xml index 20f40eb6d9887..1074b48ec73fb 100644 --- a/administrator/components/com_associations/config.xml +++ b/administrator/components/com_associations/config.xml @@ -11,6 +11,7 @@ filter="rules" validate="rules" component="com_associations" - section="component" /> + section="component" + /> diff --git a/administrator/components/com_associations/controller.php b/administrator/components/com_associations/controller.php index dd8e767dcd8e4..a70159e56d8b2 100644 --- a/administrator/components/com_associations/controller.php +++ b/administrator/components/com_associations/controller.php @@ -17,7 +17,9 @@ class AssociationsController extends JControllerLegacy { /** - * @var string The default view. + * The default view. + * + * @var string * * @since __DEPLOY_VERSION__ */ diff --git a/administrator/components/com_associations/controllers/association.php b/administrator/components/com_associations/controllers/association.php index 2489d5feebff2..3b50827e5be77 100644 --- a/administrator/components/com_associations/controllers/association.php +++ b/administrator/components/com_associations/controllers/association.php @@ -31,11 +31,9 @@ class AssociationsControllerAssociation extends JControllerForm */ public function edit($key = null, $urlVar = null) { - $input = JFactory::getApplication()->input; + list($extensionName, $typeName) = explode('.', $this->input->get('itemtype')); - list($extensionName, $typeName) = explode('.', $input->get('itemtype')); - - $id = $input->get('id', 0); + $id = $this->input->get('id', 0); // Check if reference item can be edited. if (!AssociationsHelper::allowEdit($extensionName, $typeName, $id)) @@ -62,11 +60,7 @@ public function cancel($key = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); - $input = JFactory::getApplication()->input; - - list($extensionName, $typeName) = explode('.', $input->get('itemtype')); - - $id = $input->get('id', 0); + list($extensionName, $typeName) = explode('.', $this->input->get('itemtype')); // Only check in, if component item type allows to check out. if (AssociationsHelper::typeSupportsCheckout($extensionName, $typeName)) @@ -79,7 +73,7 @@ public function cancel($key = null) $ids = array_unique(explode(',', $targetId)); } - $ids[] = $id; + $ids[] = $this->input->get('id', 0); foreach ($ids as $key => $id) { diff --git a/administrator/components/com_associations/controllers/associations.php b/administrator/components/com_associations/controllers/associations.php index 332a05dd5aa46..5012e2e838a16 100644 --- a/administrator/components/com_associations/controllers/associations.php +++ b/administrator/components/com_associations/controllers/associations.php @@ -52,8 +52,7 @@ public function getModel($name = 'Associations', $prefix = 'AssociationsModel', */ public function purge() { - $model = $this->getModel('associations'); - $model->purge(); + $this->getModel('associations')->purge(); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); } @@ -66,8 +65,7 @@ public function purge() */ public function clean() { - $model = $this->getModel('associations'); - $model->clean(); + $this->getModel('associations')->clean(); $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); } } diff --git a/administrator/components/com_associations/helpers/associations.php b/administrator/components/com_associations/helpers/associations.php index 2d42eff54403f..9e0252667f1a5 100644 --- a/administrator/components/com_associations/helpers/associations.php +++ b/administrator/components/com_associations/helpers/associations.php @@ -19,16 +19,20 @@ class AssociationsHelper extends JHelperContent { /** - * var array $extensionsSupport Array of Registry objects of extensions + * Array of Registry objects of extensions * - * @since __DEPLOY_VERSION__ + * var array $extensionsSupport + * + * @since __DEPLOY_VERSION__ */ public static $extensionsSupport = null; /** - * var array $supportedExtensionsList List of extensions name with support + * List of extensions name with support + * + * var array $supportedExtensionsList * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static $supportedExtensionsList = array(); @@ -41,11 +45,11 @@ class AssociationsHelper extends JHelperContent * * @return array * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getAssociationList($extensionName, $typeName, $itemId) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return array(); } @@ -53,9 +57,8 @@ public static function getAssociationList($extensionName, $typeName, $itemId) // Get the extension specific helper method $helper = self::getExtensionHelper($extensionName); - $items = $helper->getAssociationList($typeName, $itemId); + return $helper->getAssociationList($typeName, $itemId); - return $items; } /** @@ -65,11 +68,11 @@ public static function getAssociationList($extensionName, $typeName, $itemId) * * @return HelperClass|null * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getExtensionHelper($extensionName) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return null; } @@ -88,11 +91,11 @@ public static function getExtensionHelper($extensionName) * * @return JTable|null * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getItem($extensionName, $typeName, $itemId) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return array(); } @@ -100,9 +103,7 @@ public static function getItem($extensionName, $typeName, $itemId) // Get the extension specific helper method $helper = self::getExtensionHelper($extensionName); - $item = $helper->getItem($typeName, $itemId); - - return $item; + return $helper->getItem($typeName, $itemId); } /** @@ -110,9 +111,9 @@ public static function getItem($extensionName, $typeName, $itemId) * * @param string $extensionName The extension name with com_ * - * @return bool + * @return bool * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function hasSupport($extensionName) { @@ -129,9 +130,9 @@ public static function hasSupport($extensionName) * * @param string $extensionName The extension name with com_ * - * @return bool + * @return bool * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ private static function getExtensionHelperClassName($extensionName) { @@ -145,9 +146,9 @@ private static function getExtensionHelperClassName($extensionName) * * @param string $extensionName The extension name with com_ * - * @return string + * @return string * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ private static function getExtensionRealName($extensionName) { @@ -164,9 +165,9 @@ private static function getExtensionRealName($extensionName) * @param boolean $addLink True for adding edit links. False for just text. * @param boolean $allLanguages True for showing all content languages. False only languages with associations. * - * @return string The language HTML + * @return string The language HTML * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getAssociationHtmlList($extensionName, $typeName, $itemId, $itemLanguage, $addLink = true, $allLanguages = true) { @@ -237,6 +238,7 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId 'id' => $itemId, 'target' => $target, ); + $url = JRoute::_('index.php?' . http_build_query($options)); $text = strtoupper($language->sef); $langImage = JHtml::_('image', 'mod_languages/' . $language->image . '.gif', $language->title, array('title' => $language->title), true); @@ -253,11 +255,11 @@ public static function getAssociationHtmlList($extensionName, $typeName, $itemId * * @return array The extensions. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getSupportedExtensions() { - if (! is_null(self::$extensionsSupport)) + if (!is_null(self::$extensionsSupport)) { return self::$extensionsSupport; } @@ -288,7 +290,7 @@ public static function getSupportedExtensions() * * @return Joomla\Registry\Registry The item properties. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getSupportedExtension($extensionName) { @@ -299,7 +301,7 @@ public static function getSupportedExtension($extensionName) $result->def('helper', null); // Check if associations helper exists - if (! file_exists(JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php')) + if (!file_exists(JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php')) { return $result; } @@ -308,7 +310,7 @@ public static function getSupportedExtension($extensionName) $componentAssociationsHelperClassName = self::getExtensionHelperClassName($extensionName); - if (! class_exists($componentAssociationsHelperClassName, false)) + if (!class_exists($componentAssociationsHelperClassName, false)) { return $result; } @@ -336,8 +338,7 @@ public static function getSupportedExtension($extensionName) $result->def('title', JText::_(strtoupper($extensionName))); // Get the supported types - $types = $helper->getItemTypes(); - + $types = $helper->getItemTypes(); $rTypes = array(); foreach ($types as $typeName) @@ -380,7 +381,7 @@ public static function getSupportedExtension($extensionName) * * @return mixed * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ private static function getEnabledExtensions() { @@ -402,7 +403,7 @@ private static function getEnabledExtensions() * * @return array Array of objects all content languages by language code. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getContentLanguages() { @@ -428,11 +429,11 @@ public static function getContentLanguages() * * @return bool * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function allowEdit($extensionName, $typeName, $itemId) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return false; } @@ -445,9 +446,7 @@ public static function allowEdit($extensionName, $typeName, $itemId) return $helper->allowEdit($typeName, $itemId); } - $user = JFactory::getUser(); - - return $user->authorise('core.edit', $extensionName); + return JFactory::getUser()->authorise('core.edit', $extensionName); } /** @@ -458,11 +457,11 @@ public static function allowEdit($extensionName, $typeName, $itemId) * * @return boolean True on allowed. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function allowAdd($extensionName, $typeName) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return false; } @@ -475,9 +474,7 @@ public static function allowAdd($extensionName, $typeName) return $helper->allowAdd($typeName); } - $user = JFactory::getUser(); - - return $user->authorise('core.create', $extensionName); + return JFactory::getUser()->authorise('core.create', $extensionName); } /** @@ -488,11 +485,11 @@ public static function allowAdd($extensionName, $typeName) * * @return boolean True on allowed. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function typeSupportsCheckout($extensionName, $typeName) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return false; } @@ -502,7 +499,7 @@ public static function typeSupportsCheckout($extensionName, $typeName) $support = $helper->getTypeSupport($typeName); - return ! empty($support['checkout']); + return !empty($support['checkout']); } /** @@ -514,11 +511,11 @@ public static function typeSupportsCheckout($extensionName, $typeName) * * @return boolean True on allowed. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ public static function getTypeFieldName($extensionName, $typeName, $fieldName) { - if (! self::hasSupport($extensionName)) + if (!self::hasSupport($extensionName)) { return false; } diff --git a/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php b/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php index 91ec2e0c8f80e..9d9001b19a512 100644 --- a/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php +++ b/administrator/components/com_associations/layouts/joomla/searchtools/default/bar.php @@ -11,30 +11,22 @@ $data = $displayData; -if ($data['view'] instanceof AssociationsViewAssociations) -{ - $app = JFactory::getApplication(); - - // We will get the component item type and language filters & remove it from the form filters. - if ($app->input->get('forcedItemType', '', 'string') == '') - { - $itemTypeField = $data['view']->filterForm->getField('itemtype'); -?> -
- input; ?> -
-input->get('forcedLanguage', '', 'cmd') == '') - { - $languageField = $data['view']->filterForm->getField('language'); ?> -
- input; ?> -
- 'none')); + + + + input->get('forcedItemType', '', 'string') == '') : ?> + filterForm->getField('itemtype'); ?> +
+ input; ?> +
+ + input->get('forcedLanguage', '', 'cmd') == '') : ?> + filterForm->getField('language'); ?> +
+ input; ?> +
+ + + + 'none')); ?> diff --git a/administrator/components/com_associations/models/associations.php b/administrator/components/com_associations/models/associations.php index 831d7a67df9d3..24684a1cf8f74 100644 --- a/administrator/components/com_associations/models/associations.php +++ b/administrator/components/com_associations/models/associations.php @@ -21,7 +21,8 @@ class AssociationsModelAssociations extends JModelList * * @param array $config An optional associative array of configuration settings. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ + * * @see JController */ public function __construct($config = array()) @@ -35,11 +36,14 @@ public function __construct($config = array()) 'itemtype', 'language', 'association', - 'menutype', 'menutype_title', + 'menutype', + 'menutype_title', 'level', 'state', - 'category_id', 'category_title', - 'access', 'access_level', + 'category_id', + 'category_title', + 'access', + 'access_level', ); } @@ -60,13 +64,11 @@ public function __construct($config = array()) */ protected function populateState($ordering = 'ordering', $direction = 'asc') { - $app = JFactory::getApplication(); - - $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); - $forcedItemType = $app->input->get('forcedItemType', '', 'string'); + $forcedLanguage = $this->app->input->get('forcedLanguage', '', 'cmd'); + $forcedItemType = $this->app->input->get('forcedItemType', '', 'string'); // Adjust the context to support modal layouts. - if ($layout = $app->input->get('layout')) + if ($layout = $this->app->input->get('layout')) { $this->context .= '.' . $layout; } @@ -120,7 +122,7 @@ protected function populateState($ordering = 'ordering', $direction = 'asc') * * @return string A store id. * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ protected function getStoreId($id = '') { @@ -142,17 +144,16 @@ protected function getStoreId($id = '') * * @return JDatabaseQuery * - * @since __DEPLOY_VERSION__ + * @since __DEPLOY_VERSION__ */ protected function getListQuery() { - $type = null; + $type = null; list($extensionName, $typeName) = explode('.', $this->state->get('itemtype')); $extension = AssociationsHelper::getSupportedExtension($extensionName); - - $types = $extension->get('types'); + $types = $extension->get('types'); if (array_key_exists($typeName, $types)) { @@ -171,14 +172,14 @@ protected function getListQuery() $details = $type->get('details'); - if (! array_key_exists('support', $details)) + if (!array_key_exists('support', $details)) { return false; } $support = $details['support']; - if (! array_key_exists('fields', $details)) + if (!array_key_exists('fields', $details)) { return false; } @@ -190,7 +191,7 @@ protected function getListQuery() ->select($db->qn($fields['title'], 'title')) ->select($db->qn($fields['alias'], 'alias')); - if (! array_key_exists('tables', $details)) + if (!array_key_exists('tables', $details)) { return false; } @@ -202,7 +203,7 @@ protected function getListQuery() $query->from($db->qn($table, $key)); } - if (! array_key_exists('joins', $details)) + if (!array_key_exists('joins', $details)) { return false; } @@ -239,13 +240,13 @@ protected function getListQuery() ); // Select author for ACL checks. - if (! empty($fields['created_user_id'])) + if (!empty($fields['created_user_id'])) { $query->select($db->qn($fields['created_user_id'], 'created_user_id')); } // Select checked out data for check in checkins. - if (! empty($fields['checked_out']) && ! empty($fields['checked_out_time'])) + if (!empty($fields['checked_out']) && !empty($fields['checked_out_time'])) { $query->select($db->qn($fields['checked_out'], 'checked_out')) ->select($db->qn($fields['checked_out_time'], 'checked_out_time')); @@ -258,25 +259,25 @@ protected function getListQuery() } // If component item type supports ordering, select the ordering also. - if (! empty($fields['ordering'])) + if (!empty($fields['ordering'])) { $query->select($db->qn($fields['ordering'], 'ordering')); } // If component item type supports state, select the item state also. - if (! empty($fields['state'])) + if (!empty($fields['state'])) { $query->select($db->qn($fields['state'], 'state')); } // If component item type supports level, select the level also. - if (! empty($fields['level'])) + if (!empty($fields['level'])) { $query->select($db->qn($fields['level'], 'level')); } // If component item type supports categories, select the category also. - if (! empty($fields['catid'])) + if (!empty($fields['catid'])) { $query->select($db->qn($fields['catid'], 'catid')); @@ -302,7 +303,7 @@ protected function getListQuery() } // If component item type supports access level, select the access level also. - if (array_key_exists('acl', $support) && $support['acl'] == true && ! empty($fields['access'])) + if (array_key_exists('acl', $support) && $support['acl'] == true && !empty($fields['access'])) { $query->select($db->qn($fields['access'], 'access')); @@ -313,14 +314,14 @@ protected function getListQuery() $groupby[] = 'ag.title'; // Implement View Level Access. - if (!$user->authorise('core.admin', $extension)) + if (!$user->authorise('core.admin', $extensionName)) { $query->where($fields['access'] . ' IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'); } } // If component item type is menus we need to remove the root item and the administrator menu. - if ($extension === 'com_menus') + if ($extensionName === 'com_menus') { $query->where($db->qn($fields['id']) . ' > 1') ->where($db->qn('a.client_id') . ' = 0'); @@ -366,7 +367,7 @@ protected function getListQuery() // Filter on the level. if ($level = $this->getState('filter.level')) { - $tableAlias = in_array($extension, array('com_menus', 'com_categories')) ? 'a' : 'c'; + $tableAlias = in_array($extensionName, array('com_menus', 'com_categories')) ? 'a' : 'c'; $query->where($db->qn($tableAlias . '.level') . ' <= ' . ((int) $level + (int) $baselevel - 1)); } @@ -418,9 +419,7 @@ protected function getListQuery() */ public function purge($context = '', $key = '') { - $db = $this->getDbo(); - $app = JFactory::getApplication(); - + $db = $this->getDbo(); $query = $db->getQuery(true)->delete($db->qn('#__associations')); // Filter by associations context. @@ -443,12 +442,12 @@ public function purge($context = '', $key = '') } catch (JDatabaseExceptionExecuting $e) { - $app->enqueueMessage(JText::_('COM_ASSOCIATIONS_PURGE_FAILED'), 'error'); + $this->app->enqueueMessage(JText::_('COM_ASSOCIATIONS_PURGE_FAILED'), 'error'); return false; } - $app->enqueueMessage(JText::_((int) $db->getAffectedRows() > 0 ? 'COM_ASSOCIATIONS_PURGE_SUCCESS' : 'COM_ASSOCIATIONS_PURGE_NONE'), 'message'); + $this->app->enqueueMessage(JText::_((int) $db->getAffectedRows() > 0 ? 'COM_ASSOCIATIONS_PURGE_SUCCESS' : 'COM_ASSOCIATIONS_PURGE_NONE'), 'message'); return true; } @@ -466,7 +465,6 @@ public function purge($context = '', $key = '') public function clean($context = '', $key = '') { $db = $this->getDbo(); - $app = JFactory::getApplication(); $query = $db->getQuery(true) ->select($db->qn('key') . ', COUNT(*)') @@ -507,7 +505,7 @@ public function clean($context = '', $key = '') } catch (JDatabaseExceptionExecuting $e) { - $app->enqueueMessage(JText::_('COM_ASSOCIATIONS_DELETE_ORPHANS_FAILED'), 'error'); + $this->app->enqueueMessage(JText::_('COM_ASSOCIATIONS_DELETE_ORPHANS_FAILED'), 'error'); return false; } @@ -515,7 +513,7 @@ public function clean($context = '', $key = '') $count += (int) $db->getAffectedRows(); } - $app->enqueueMessage(JText::_($count > 0 ? 'COM_ASSOCIATIONS_DELETE_ORPHANS_SUCCESS' : 'COM_ASSOCIATIONS_DELETE_ORPHANS_NONE'), 'message'); + $this->app->enqueueMessage(JText::_($count > 0 ? 'COM_ASSOCIATIONS_DELETE_ORPHANS_SUCCESS' : 'COM_ASSOCIATIONS_DELETE_ORPHANS_NONE'), 'message'); return true; } diff --git a/administrator/components/com_associations/models/fields/itemlanguage.php b/administrator/components/com_associations/models/fields/itemlanguage.php index a49eb636b0b5c..d1b5e21996879 100644 --- a/administrator/components/com_associations/models/fields/itemlanguage.php +++ b/administrator/components/com_associations/models/fields/itemlanguage.php @@ -12,7 +12,6 @@ use Joomla\Utilities\ArrayHelper; JLoader::register('AssociationsHelper', JPATH_ADMINISTRATOR . '/components/com_associations/helpers/associations.php'); - JFormHelper::loadFieldClass('list'); /** @@ -25,8 +24,8 @@ class JFormFieldItemLanguage extends JFormFieldList /** * The form field type. * - * @var string - * @since __DEPLOY_VERSION__ + * @var string + * @since __DEPLOY_VERSION__ */ protected $type = 'ItemLanguage'; @@ -104,7 +103,7 @@ protected function getOptions() else { // New item, id = 0 and disabled if user is not allowed to create new items. - $options[$langCode]->value = $language->lang_code . ':0:add'; + $options[$langCode]->value = $language->lang_code . ':0:add'; // Disable language if user is not allowed to create items. $options[$langCode]->disable = !$canCreate; diff --git a/administrator/components/com_associations/models/fields/itemtype.php b/administrator/components/com_associations/models/fields/itemtype.php index 45d01e7aae237..d077f711d7530 100644 --- a/administrator/components/com_associations/models/fields/itemtype.php +++ b/administrator/components/com_associations/models/fields/itemtype.php @@ -9,7 +9,6 @@ defined('JPATH_BASE') or die; JLoader::register('AssociationsHelper', JPATH_ADMINISTRATOR . '/components/com_associations/helpers/associations.php'); - JFormHelper::loadFieldClass('groupedlist'); /** @@ -34,11 +33,12 @@ class JFormFieldItemType extends JFormFieldGroupedList * @return array The field option objects as a nested array in groups. * * @since __DEPLOY_VERSION__ + * * @throws UnexpectedValueException */ protected function getGroups() { - $options = array(); + $options = array(); $extensions = AssociationsHelper::getSupportedExtensions(); foreach ($extensions as $extension) @@ -47,7 +47,7 @@ protected function getGroups() { foreach ($extension->get('types') as $type) { - $context = $extension->get('component') . '.' . $type->get('name'); + $context = $extension->get('component') . '.' . $type->get('name'); $options[$extension->get('title')][] = JHtml::_('select.option', $context, $type->get('title')); } } diff --git a/administrator/components/com_associations/models/fields/modalassociation.php b/administrator/components/com_associations/models/fields/modalassociation.php index be7f594c316b7..ee3f593095c9b 100644 --- a/administrator/components/com_associations/models/fields/modalassociation.php +++ b/administrator/components/com_associations/models/fields/modalassociation.php @@ -40,12 +40,12 @@ protected function getInput() $script = array(); // Select button script - $script[] = ' function jSelectAssociation_' . $this->id . '(id) {'; - $script[] = ' target = document.getElementById("target-association");'; - $script[] = ' document.getElementById("target-association").src = target.getAttribute("data-editurl") + ' - . '"&task=" + target.getAttribute("data-item") + ".edit" + "&id=" + id'; - $script[] = ' jQuery("#associationSelect' . $this->id . 'Modal").modal("hide");'; - $script[] = ' }'; + $script[] = 'function jSelectAssociation_' . $this->id . '(id) {'; + $script[] = ' target = document.getElementById("target-association");'; + $script[] = ' document.getElementById("target-association").src = target.getAttribute("data-editurl") + ' + . '"&task=" + target.getAttribute("data-item") + ".edit" + "&id=" + id'; + $script[] = ' jQuery("#associationSelect' . $this->id . 'Modal").modal("hide");'; + $script[] = '}'; // Add the script to the document head. JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); diff --git a/administrator/components/com_associations/models/forms/association.xml b/administrator/components/com_associations/models/forms/association.xml index 9e8d880e22984..89add5542b210 100644 --- a/administrator/components/com_associations/models/forms/association.xml +++ b/administrator/components/com_associations/models/forms/association.xml @@ -6,7 +6,7 @@ type="itemlanguage" label="COM_ASSOCIATIONS_ITEM_FIELD_LANGUAGE_LABEL" description="COM_ASSOCIATIONS_ITEM_FIELD_LANGUAGE_DESC" - > + > diff --git a/administrator/components/com_associations/models/forms/filter_associations.xml b/administrator/components/com_associations/models/forms/filter_associations.xml index f66f0f91588e6..fb2199975e28a 100644 --- a/administrator/components/com_associations/models/forms/filter_associations.xml +++ b/administrator/components/com_associations/models/forms/filter_associations.xml @@ -7,9 +7,10 @@ description="COM_ASSOCIATIONS_COMPONENT_SELECTOR_DESC" filtermode="selector" onchange="jQuery('select[id^=\'filter_\']').val('');jQuery('select[id^=\'list_\']').val('');this.form.submit();" - > + > + + > + + + > + + > + + > + + > + + > @@ -86,7 +93,7 @@ type="list" default="ordering ASC" onchange="this.form.submit();" - > + > diff --git a/administrator/components/com_associations/views/association/tmpl/edit.php b/administrator/components/com_associations/views/association/tmpl/edit.php index 51454d113a514..1930bf1b191b8 100644 --- a/administrator/components/com_associations/views/association/tmpl/edit.php +++ b/administrator/components/com_associations/views/association/tmpl/edit.php @@ -16,11 +16,10 @@ JHtml::_('script', 'com_associations/sidebyside.js', false, true); JHtml::_('stylesheet', 'com_associations/sidebyside.css', array(), true); -$input = $this->app->input; $options = array( - 'layout' => $input->get('layout', '', 'string'), - 'itemtype' => $this->itemtype, - 'id' => $this->referenceId, + 'layout' => $this->app->input->get('layout', '', 'string'), + 'itemtype' => $this->itemtype, + 'id' => $this->referenceId, ); ?>