Source for file associations.php

Documentation is available at associations.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Language
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Utitlity class for associations in multilang
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Language
  17.  * @since       3.1
  18.  */
  19. {
  20.     /**
  21.      * Get the associations.
  22.      *
  23.      * @param   string   $extension   The name of the component.
  24.      * @param   string   $tablename   The name of the table.
  25.      * @param   string   $context     The context
  26.      * @param   integer  $id          The primary key value.
  27.      * @param   string   $pk          The name of the primary key in the given $table.
  28.      * @param   string   $aliasField  If the table has an alias field set it here. Null to not use it
  29.      * @param   string   $catField    If the table has a catid field set it here. Null to not use it
  30.      *
  31.      * @return  array                The associated items
  32.      *
  33.      * @since   3.1
  34.      */
  35.     public static function getAssociations($extension$tablename$context$id$pk 'id'$aliasField 'alias'$catField 'catid')
  36.     {
  37.         $associations array();
  38.         $db JFactory::getDbo();
  39.         $query $db->getQuery(true)
  40.             ->select($db->quoteName('c2.language'))
  41.             ->from($db->quoteName($tablename'c'))
  42.             ->join('INNER'$db->quoteName('#__associations''a'' ON a.id = c.id AND a.context=' $db->quote($context))
  43.             ->join('INNER'$db->quoteName('#__associations''a2'' ON a.key = a2.key')
  44.             ->join('INNER'$db->quoteName($tablename'c2'' ON a2.id = c2.' $db->quoteName($pk));
  45.  
  46.         // Use alias field ?
  47.         if (!empty($aliasField))
  48.         {
  49.             $query->select(
  50.                 $query->concatenate(
  51.                     array(
  52.                         $db->quoteName('c2.' $pk),
  53.                         $db->quoteName('c2.' $aliasField)
  54.                     ),
  55.                     ':'
  56.                 ' AS ' $db->quoteName($pk)
  57.             );
  58.         }
  59.         else
  60.         {
  61.             $query->select($db->quoteName('c2.' $pk));
  62.         }
  63.  
  64.         // Use catid field ?
  65.         if (!empty($catField))
  66.         {
  67.             $query->join('INNER'$db->quoteName('#__categories''ca'' ON ' $db->quoteName('c2.' $catField' = ca.id AND ca.extension = ' $db->quote($extension))
  68.                 ->select(
  69.                     $query->concatenate(
  70.                         array('ca.id''ca.alias'),
  71.                         ':'
  72.                     ' AS ' $db->quoteName($catField)
  73.                 );
  74.         }
  75.  
  76.         $query->where('c.' $pk ' = ' . (int) $id);
  77.  
  78.         $db->setQuery($query);
  79.  
  80.         try
  81.         {
  82.             $items $db->loadObjectList('language');
  83.         }
  84.         catch (RuntimeException $e)
  85.         {
  86.             throw new Exception($e->getMessage()500);
  87.         }
  88.  
  89.         if ($items)
  90.         {
  91.             foreach ($items as $tag => $item)
  92.             {
  93.                 // Do not return itself as result
  94.                 if ((int) $item->{$pk!= $id)
  95.                 {
  96.                     $associations[$tag$item;
  97.                 }
  98.             }
  99.         }
  100.  
  101.         return $associations;
  102.     }
  103.  
  104.     /**
  105.      * Method to determine if the language filter Items Associations parameter is enabled.
  106.      * This works for both site and administrator.
  107.      *
  108.      * @return  boolean  True if the parameter is implemented; false otherwise.
  109.      *
  110.      * @since   3.2
  111.      */
  112.     public static function isEnabled()
  113.     {
  114.         // Flag to avoid doing multiple database queries.
  115.         static $tested false;
  116.  
  117.         // Status of language filter parameter.
  118.         static $enabled false;
  119.  
  120.         if (JLanguageMultilang::isEnabled())
  121.         {
  122.             // If already tested, don't test again.
  123.             if (!$tested)
  124.             {
  125.                 $params new JRegistry(JPluginHelper::getPlugin('system''languagefilter')->params);
  126.  
  127.                 $enabled  = (boolean) $params->get('item_associations'true);
  128.                 $tested true;
  129.             }
  130.         }
  131.  
  132.         return $enabled;
  133.     }
  134. }

Documentation generated on Tue, 19 Nov 2013 14:54:08 +0100 by phpDocumentor 1.4.3