[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_messages/models/ -> messages.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  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.component.modellist');
  11  
  12  /**
  13   * Messages Component Messages Model
  14   *
  15   * @package        Joomla.Administrator
  16   * @subpackage    com_messages
  17   * @since        1.6
  18   */
  19  class MessagesModelMessages 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                  'message_id', 'a.id',
  33                  'subject', 'a.subject',
  34                  'state', 'a.state',
  35                  'user_id_from', 'a.user_id_from',
  36                  'user_id_to', 'a.user_id_to',
  37                  'date_time', 'a.date_time',
  38                  'priority', 'a.priority',
  39              );
  40          }
  41  
  42          parent::__construct($config);
  43      }
  44  
  45      /**
  46       * Method to auto-populate the model state.
  47       *
  48       * Note. Calling getState in this method will result in recursion.
  49       *
  50       * @since    1.6
  51       */
  52  	protected function populateState($ordering = null, $direction = null)
  53      {
  54          // Initialise variables.
  55          $app = JFactory::getApplication('administrator');
  56  
  57          // Load the filter state.
  58          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  59          $this->setState('filter.search', $search);
  60  
  61          $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string');
  62          $this->setState('filter.state', $state);
  63  
  64          // List state information.
  65          parent::populateState('a.date_time', 'desc');
  66      }
  67  
  68      /**
  69       * Method to get a store id based on model configuration state.
  70       *
  71       * This is necessary because the model is used by the component and
  72       * different modules that might need different sets of data or different
  73       * ordering requirements.
  74       *
  75       * @param    string    A prefix for the store id.
  76       *
  77       * @return    string    A store id.
  78       */
  79  	protected function getStoreId($id = '')
  80      {
  81          // Compile the store id.
  82          $id    .= ':'.$this->getState('filter.search');
  83          $id    .= ':'.$this->getState('filter.state');
  84  
  85          return parent::getStoreId($id);
  86      }
  87  
  88      /**
  89       * Build an SQL query to load the list data.
  90       *
  91       * @return    JDatabaseQuery
  92       */
  93  	protected function getListQuery()
  94      {
  95          // Create a new query object.
  96          $db        = $this->getDbo();
  97          $query    = $db->getQuery(true);
  98          $user    = JFactory::getUser();
  99  
 100          // Select the required fields from the table.
 101          $query->select(
 102              $this->getState(
 103                  'list.select',
 104                  'a.*, '.
 105                  'u.name AS user_from'
 106              )
 107          );
 108          $query->from('#__messages AS a');
 109  
 110          // Join over the users for message owner.
 111          $query->join('INNER', '#__users AS u ON u.id = a.user_id_from');
 112          $query->where('a.user_id_to = '.(int) $user->get('id'));
 113  
 114          // Filter by published state.
 115          $state = $this->getState('filter.state');
 116          if (is_numeric($state)) {
 117              $query->where('a.state = '.(int) $state);
 118          }
 119          elseif ($state === '') {
 120              $query->where('(a.state IN (0, 1))');
 121          }
 122  
 123          // Filter by search in subject or message.
 124          $search = $this->getState('filter.search');
 125  
 126          if (!empty($search)) {
 127              $search = $db->Quote('%'.$db->escape($search, true).'%', false);
 128              $query->where('a.subject LIKE '.$search.' OR a.message LIKE '.$search);
 129          }
 130  
 131          // Add the list ordering clause.
 132          $query->order($db->escape($this->getState('list.ordering', 'a.date_time')).' '.$db->escape($this->getState('list.direction', 'DESC')));
 133  
 134          //echo nl2br(str_replace('#__','jos_',$query));
 135          return $query;
 136      }
 137  }


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