[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_languages/models/ -> languages.php (source)

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


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1