[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_contact/models/ -> contacts.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_contact
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // no direct access
  10  defined('_JEXEC') or die;
  11  
  12  jimport('joomla.application.component.modellist');
  13  
  14  /**
  15   * Methods supporting a list of contact records.
  16   *
  17   * @package        Joomla.Administrator
  18   * @subpackage    com_contact
  19   */
  20  class ContactModelContacts extends JModelList
  21  {
  22      /**
  23       * Constructor.
  24       *
  25       * @param    array    An optional associative array of configuration settings.
  26       * @see        JController
  27       * @since    1.6
  28       */
  29  	public function __construct($config = array())
  30      {
  31          if (empty($config['filter_fields'])) {
  32              $config['filter_fields'] = array(
  33                  'id', 'a.id',
  34                  'name', 'a.name',
  35                  'alias', 'a.alias',
  36                  'checked_out', 'a.checked_out',
  37                  'checked_out_time', 'a.checked_out_time',
  38                  'catid', 'a.catid', 'category_title',
  39                  'user_id', 'a.user_id',
  40                  'state', 'a.state',
  41                  'access', 'a.access', 'access_level',
  42                  'created', 'a.created',
  43                  'created_by', 'a.created_by',
  44                  'ordering', 'a.ordering',
  45                  'featured', 'a.featured',
  46                  'language', 'a.language',
  47                  'publish_up', 'a.publish_up',
  48                  'publish_down', 'a.publish_down',
  49                  'ul.name', 'linked_user',
  50              );
  51          }
  52  
  53          parent::__construct($config);
  54      }
  55  
  56      /**
  57       * Method to auto-populate the model state.
  58       *
  59       * Note. Calling getState in this method will result in recursion.
  60       *
  61       * @return    void
  62       * @since    1.6
  63       */
  64  	protected function populateState($ordering = null, $direction = null)
  65      {
  66          // Initialise variables.
  67          $app = JFactory::getApplication();
  68  
  69          // Adjust the context to support modal layouts.
  70          if ($layout = JRequest::getVar('layout')) {
  71              $this->context .= '.'.$layout;
  72          }
  73  
  74          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  75          $this->setState('filter.search', $search);
  76  
  77          $access = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', 0, 'int');
  78          $this->setState('filter.access', $access);
  79  
  80          $published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published', '');
  81          $this->setState('filter.published', $published);
  82  
  83          $categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id');
  84          $this->setState('filter.category_id', $categoryId);
  85  
  86          $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', '');
  87          $this->setState('filter.language', $language);
  88  
  89          // List state information.
  90          parent::populateState('a.name', 'asc');
  91      }
  92  
  93      /**
  94       * Method to get a store id based on model configuration state.
  95       *
  96       * This is necessary because the model is used by the component and
  97       * different modules that might need different sets of data or different
  98       * ordering requirements.
  99       *
 100       * @param    string        $id    A prefix for the store id.
 101       *
 102       * @return    string        A store id.
 103       * @since    1.6
 104       */
 105  	protected function getStoreId($id = '')
 106      {
 107          // Compile the store id.
 108          $id    .= ':'.$this->getState('filter.search');
 109          $id    .= ':'.$this->getState('filter.access');
 110          $id    .= ':'.$this->getState('filter.published');
 111          $id    .= ':'.$this->getState('filter.category_id');
 112          $id    .= ':'.$this->getState('filter.language');
 113  
 114          return parent::getStoreId($id);
 115      }
 116  
 117      /**
 118       * Build an SQL query to load the list data.
 119       *
 120       * @return    JDatabaseQuery
 121       * @since    1.6
 122       */
 123  	protected function getListQuery()
 124      {
 125          // Create a new query object.
 126          $db        = $this->getDbo();
 127          $query    = $db->getQuery(true);
 128          $user    = JFactory::getUser();
 129  
 130          // Select the required fields from the table.
 131          $query->select(
 132              $this->getState(
 133                  'list.select',
 134                  'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid, a.user_id' .
 135                  ', a.published, a.access, a.created, a.created_by, a.ordering, a.featured, a.language'.
 136                  ', a.publish_up, a.publish_down'
 137              )
 138          );
 139          $query->from('#__contact_details AS a');
 140  
 141          // Join over the users for the linked user.
 142          $query->select('ul.name AS linked_user');
 143          $query->join('LEFT', '#__users AS ul ON ul.id=a.user_id');
 144  
 145          // Join over the language
 146          $query->select('l.title AS language_title');
 147          $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language');
 148  
 149          // Join over the users for the checked out user.
 150          $query->select('uc.name AS editor');
 151          $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
 152  
 153          // Join over the asset groups.
 154          $query->select('ag.title AS access_level');
 155          $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
 156  
 157          // Join over the categories.
 158          $query->select('c.title AS category_title');
 159          $query->join('LEFT', '#__categories AS c ON c.id = a.catid');
 160  
 161          // Filter by access level.
 162          if ($access = $this->getState('filter.access')) {
 163              $query->where('a.access = ' . (int) $access);
 164          }
 165  
 166          // Implement View Level Access
 167          if (!$user->authorise('core.admin'))
 168          {
 169              $groups    = implode(',', $user->getAuthorisedViewLevels());
 170              $query->where('a.access IN ('.$groups.')');
 171          }
 172  
 173          // Filter by published state
 174          $published = $this->getState('filter.published');
 175          if (is_numeric($published)) {
 176              $query->where('a.published = ' . (int) $published);
 177          }
 178          elseif ($published === '') {
 179              $query->where('(a.published = 0 OR a.published = 1)');
 180          }
 181  
 182          // Filter by a single or group of categories.
 183          $categoryId = $this->getState('filter.category_id');
 184          if (is_numeric($categoryId)) {
 185              $query->where('a.catid = '.(int) $categoryId);
 186          }
 187          elseif (is_array($categoryId)) {
 188              JArrayHelper::toInteger($categoryId);
 189              $categoryId = implode(',', $categoryId);
 190              $query->where('a.catid IN ('.$categoryId.')');
 191          }
 192  
 193          // Filter by search in name.
 194          $search = $this->getState('filter.search');
 195          if (!empty($search)) {
 196              if (stripos($search, 'id:') === 0) {
 197                  $query->where('a.id = '.(int) substr($search, 3));
 198              }
 199              elseif (stripos($search, 'author:') === 0) {
 200                  $search = $db->Quote('%'.$db->escape(substr($search, 7), true).'%');
 201                  $query->where('(ua.name LIKE '.$search.' OR ua.username LIKE '.$search.')');
 202              }
 203              else {
 204                  $search = $db->Quote('%'.$db->escape($search, true).'%');
 205                  $query->where('(a.name LIKE '.$search.' OR a.alias LIKE '.$search.')');
 206              }
 207          }
 208  
 209          // Filter on the language.
 210          if ($language = $this->getState('filter.language')) {
 211              $query->where('a.language = '.$db->quote($language));
 212          }
 213  
 214          // Add the list ordering clause.
 215          $orderCol    = $this->state->get('list.ordering', 'a.name');
 216          $orderDirn    = $this->state->get('list.direction', 'asc');
 217          if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
 218              $orderCol = 'c.title '.$orderDirn.', a.ordering';
 219          }
 220          $query->order($db->escape($orderCol.' '.$orderDirn));
 221  
 222          //echo nl2br(str_replace('#__','jos_',$query));
 223          return $query;
 224      }
 225  }


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