From 23e07f6cae3e2e2a98c8a6d99b5cfbfd41824de0 Mon Sep 17 00:00:00 2001 From: infograf768 Date: Sun, 12 Mar 2017 14:56:34 +0100 Subject: [PATCH] Create associations.php helper to let weblinks be used into com_associations (#294) * Create associations.php This should be merged after the new com_associations gets in core https://github.com/joomla/joomla-cms/pull/13537 * some CS fixes --- .../com_weblinks/helpers/associations.php | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 src/administrator/components/com_weblinks/helpers/associations.php diff --git a/src/administrator/components/com_weblinks/helpers/associations.php b/src/administrator/components/com_weblinks/helpers/associations.php new file mode 100644 index 0000000..1e6f7e5 --- /dev/null +++ b/src/administrator/components/com_weblinks/helpers/associations.php @@ -0,0 +1,172 @@ +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 '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 '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 + ); + } +}