Source for file languages.php

Documentation is available at languages.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_languages
  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.  * Languages Model Class
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_languages
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   array  An optional associative array of configuration settings.
  24.      * @see     JController
  25.      * @since   1.6
  26.      */
  27.     public function __construct($config array())
  28.     {
  29.         if (empty($config['filter_fields']))
  30.         {
  31.             $config['filter_fields'array(
  32.                 'lang_id''a.lang_id',
  33.                 'lang_code''a.lang_code',
  34.                 'title''a.title',
  35.                 'title_native''a.title_native',
  36.                 'sef''a.sef',
  37.                 'image''a.image',
  38.                 'published''a.published',
  39.                 'ordering''a.ordering',
  40.                 'access''a.access''access_level',
  41.                 'home''l.home',
  42.             );
  43.         }
  44.  
  45.         parent::__construct($config);
  46.     }
  47.  
  48.     /**
  49.      * Method to auto-populate the model state.
  50.      *
  51.      * Note. Calling getState in this method will result in recursion.
  52.      *
  53.      * @param   string  $ordering   An optional ordering field.
  54.      * @param   string  $direction  An optional direction (asc|desc).
  55.      *
  56.      * @return  void 
  57.      *
  58.      * @since   1.6
  59.      */
  60.     protected function populateState($ordering null$direction null)
  61.     {
  62.         // Load the filter state.
  63.         $search $this->getUserStateFromRequest($this->context . '.search''filter_search');
  64.         $this->setState('filter.search'$search);
  65.  
  66.         $accessId $this->getUserStateFromRequest($this->context . '.access''filter_access'null'int');
  67.         $this->setState('filter.access'$accessId);
  68.  
  69.         $published $this->getUserStateFromRequest($this->context . '.published''filter_published''');
  70.         $this->setState('filter.published'$published);
  71.  
  72.         // Load the parameters.
  73.         $params JComponentHelper::getParams('com_languages');
  74.         $this->setState('params'$params);
  75.  
  76.         // List state information.
  77.         parent::populateState('a.title''asc');
  78.     }
  79.  
  80.     /**
  81.      * Method to get a store id based on model configuration state.
  82.      *
  83.      * This is necessary because the model is used by the component and
  84.      * different modules that might need different sets of data or different
  85.      * ordering requirements.
  86.      *
  87.      * @param   string  $id    A prefix for the store id.
  88.      *
  89.      * @return  string  A store id.
  90.      * @since   1.6
  91.      */
  92.     protected function getStoreId($id '')
  93.     {
  94.         // Compile the store id.
  95.         $id .= ':' $this->getState('filter.search');
  96.         $id .= ':' $this->getState('filter.access');
  97.         $id .= ':' $this->getState('filter.published');
  98.  
  99.         return parent::getStoreId($id);
  100.     }
  101.  
  102.     /**
  103.      * Method to build an SQL query to load the list data.
  104.      *
  105.      * @return  string    An SQL query
  106.      * @since   1.6
  107.      */
  108.     protected function getListQuery()
  109.     {
  110.         // Create a new query object.
  111.         $db $this->getDbo();
  112.         $query $db->getQuery(true);
  113.  
  114.         // Select all fields from the languages table.
  115.         $query->select($this->getState('list.select''a.*''l.home'))
  116.             ->from($db->quoteName('#__languages'' AS a');
  117.  
  118.         // Join over the asset groups.
  119.         $query->select('ag.title AS access_level')
  120.             ->join('LEFT''#__viewlevels AS ag ON ag.id = a.access');
  121.  
  122.         // Select the language home pages
  123.         $query->select('l.home AS home')
  124.             ->join('LEFT'$db->quoteName('#__menu'' AS l  ON  l.language = a.lang_code AND l.home=1  AND l.language <> ' $db->quote('*'));
  125.  
  126.         // Filter on the published state.
  127.         $published $this->getState('filter.published');
  128.         if (is_numeric($published))
  129.         {
  130.             $query->where('a.published = ' . (int) $published);
  131.         }
  132.         elseif ($published === '')
  133.         {
  134.             $query->where('(a.published IN (0, 1))');
  135.         }
  136.  
  137.         // Filter by search in title
  138.         $search $this->getState('filter.search');
  139.         if (!empty($search))
  140.         {
  141.             $search $db->quote('%' $db->escape($searchtrue'%'false);
  142.             $query->where('(a.title LIKE ' $search ')');
  143.         }
  144.  
  145.         // Filter by access level.
  146.         if ($access $this->getState('filter.access'))
  147.         {
  148.             $query->where('a.access = ' . (int) $access);
  149.         }
  150.  
  151.         // Add the list ordering clause.
  152.         $query->order($db->escape($this->getState('list.ordering''a.ordering')) ' ' $db->escape($this->getState('list.direction''ASC')));
  153.  
  154.         return $query;
  155.     }
  156.  
  157.     /**
  158.      * Set the published language(s)
  159.      *
  160.      * @param   array    $cid      An array of language IDs.
  161.      * @param   integer  $value    The value of the published state.
  162.      *
  163.      * @return  boolean  True on success, false otherwise.
  164.      * @since   1.6
  165.      */
  166.     public function setPublished($cid$value 0)
  167.     {
  168.         return JTable::getInstance('Language')->publish($cid$value);
  169.     }
  170.  
  171.     /**
  172.      * Method to delete records.
  173.      *
  174.      * @param   array  An array of item primary keys.
  175.      *
  176.      * @return  boolean  Returns true on success, false on failure.
  177.      * @since   1.6
  178.      */
  179.     public function delete($pks)
  180.     {
  181.         // Sanitize the array.
  182.         $pks = (array) $pks;
  183.  
  184.         // Get a row instance.
  185.         $table JTable::getInstance('Language');
  186.  
  187.         // Iterate the items to delete each one.
  188.         foreach ($pks as $itemId)
  189.         {
  190.             if (!$table->delete((int) $itemId))
  191.             {
  192.                 $this->setError($table->getError());
  193.  
  194.                 return false;
  195.             }
  196.         }
  197.  
  198.         // Clean the cache.
  199.         $this->cleanCache();
  200.  
  201.         return true;
  202.     }
  203.  
  204.     /**
  205.      * Custom clean cache method, 2 places for 2 clients
  206.      *
  207.      * @since   1.6
  208.      */
  209.     protected function cleanCache($group null$client_id 0)
  210.     {
  211.         parent::cleanCache('_system');
  212.         parent::cleanCache('com_languages');
  213.     }
  214. }

Documentation generated on Tue, 19 Nov 2013 15:06:39 +0100 by phpDocumentor 1.4.3