Source for file messages.php

Documentation is available at messages.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_messages
  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.  * Messages Component Messages Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_messages
  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.                 '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.         // Load the filter state.
  55.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  56.         $this->setState('filter.search'$search);
  57.  
  58.         $state $this->getUserStateFromRequest($this->context . '.filter.state''filter_state''''string');
  59.         $this->setState('filter.state'$state);
  60.  
  61.         // List state information.
  62.         parent::populateState('a.date_time''desc');
  63.     }
  64.  
  65.     /**
  66.      * Method to get a store id based on model configuration state.
  67.      *
  68.      * This is necessary because the model is used by the component and
  69.      * different modules that might need different sets of data or different
  70.      * ordering requirements.
  71.      *
  72.      * @param   string    A prefix for the store id.
  73.      *
  74.      * @return  string    A store id.
  75.      */
  76.     protected function getStoreId($id '')
  77.     {
  78.         // Compile the store id.
  79.         $id .= ':' $this->getState('filter.search');
  80.         $id .= ':' $this->getState('filter.state');
  81.  
  82.         return parent::getStoreId($id);
  83.     }
  84.  
  85.     /**
  86.      * Build an SQL query to load the list data.
  87.      *
  88.      * @return  JDatabaseQuery 
  89.      */
  90.     protected function getListQuery()
  91.     {
  92.         // Create a new query object.
  93.         $db $this->getDbo();
  94.         $query $db->getQuery(true);
  95.         $user JFactory::getUser();
  96.  
  97.         // Select the required fields from the table.
  98.         $query->select(
  99.             $this->getState(
  100.                 'list.select',
  101.                 'a.*, ' .
  102.                     'u.name AS user_from'
  103.             )
  104.         );
  105.         $query->from('#__messages AS a');
  106.  
  107.         // Join over the users for message owner.
  108.         $query->join('INNER''#__users AS u ON u.id = a.user_id_from')
  109.             ->where('a.user_id_to = ' . (int) $user->get('id'));
  110.  
  111.         // Filter by published state.
  112.         $state $this->getState('filter.state');
  113.         if (is_numeric($state))
  114.         {
  115.             $query->where('a.state = ' . (int) $state);
  116.         }
  117.         elseif ($state === '')
  118.         {
  119.             $query->where('(a.state IN (0, 1))');
  120.         }
  121.  
  122.         // Filter by search in subject or message.
  123.         $search $this->getState('filter.search');
  124.  
  125.         if (!empty($search))
  126.         {
  127.             $search $db->quote('%' $db->escape($searchtrue'%'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. }

Documentation generated on Tue, 19 Nov 2013 15:08:09 +0100 by phpDocumentor 1.4.3