Source for file notes.php

Documentation is available at notes.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_users
  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.  * User notes model class.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_users
  17.  * @since       2.5
  18.  */
  19. class UsersModelNotes extends JModelList
  20. {
  21.     /**
  22.      * Class constructor.
  23.      *
  24.      * @param  array  $config  An optional associative array of configuration settings.
  25.      *
  26.      * @since  2.5
  27.      */
  28.     public function __construct($config array())
  29.     {
  30.         // Set the list ordering fields.
  31.         if (empty($config['filter_fields']))
  32.         {
  33.             $config['filter_fields'array(
  34.                 'id',
  35.                 'a.id',
  36.                 'user_id',
  37.                 'a.user_id',
  38.                 'u.name',
  39.                 'subject',
  40.                 'a.subject',
  41.                 'catid',
  42.                 'a.catid',
  43.                 'state''a.state',
  44.                 'c.title',
  45.                 'review_time',
  46.                 'a.review_time',
  47.                 'publish_up''a.publish_up',
  48.                 'publish_down''a.publish_down',
  49.             );
  50.         }
  51.  
  52.         parent::__construct($config);
  53.     }
  54.  
  55.     /**
  56.      * Build an SQL query to load the list data.
  57.      *
  58.      * @return  JDatabaseQuery  A JDatabaseQuery object to retrieve the data set.
  59.      *
  60.      * @since   2.5
  61.      */
  62.     protected function getListQuery()
  63.     {
  64.         $db $this->getDbo();
  65.         $query $db->getQuery(true);
  66.         $section $this->getState('filter.category_id');
  67.  
  68.         // Select the required fields from the table.
  69.         $query->select(
  70.             $this->getState('list.select',
  71.                 'a.id, a.subject, a.checked_out, a.checked_out_time,' .
  72.                 'a.catid, a.created_time, a.review_time,' .
  73.                 'a.state, a.publish_up, a.publish_down'
  74.             )
  75.         );
  76.         $query->from('#__user_notes AS a');
  77.  
  78.         // Join over the category
  79.         $query->select('c.title AS category_title, c.params AS category_params')
  80.             ->join('LEFT''#__categories AS c ON c.id = a.catid');
  81.  
  82.         // Join over the users for the note user.
  83.         $query->select('u.name AS user_name')
  84.             ->join('LEFT''#__users AS u ON u.id = a.user_id');
  85.  
  86.         // Join over the users for the checked out user.
  87.         $query->select('uc.name AS editor')
  88.             ->join('LEFT''#__users AS uc ON uc.id = a.checked_out');
  89.  
  90.         // Filter by search in title
  91.         $search $this->getState('filter.search');
  92.         if (!empty($search))
  93.         {
  94.             if (stripos($search'id:'=== 0)
  95.             {
  96.                 $query->where('a.id = ' . (int) substr($search3));
  97.             }
  98.             elseif (stripos($search'uid:'=== 0)
  99.             {
  100.                 $query->where('a.user_id = ' . (int) substr($search4));
  101.             }
  102.             else
  103.             {
  104.                 $search $db->quote('%' $db->escape($searchtrue'%');
  105.                 $query->where('((a.subject LIKE ' $search ') OR (u.name LIKE ' $search ') OR (u.username LIKE ' $search '))');
  106.             }
  107.         }
  108.  
  109.         // Filter by published state
  110.         $published $this->getState('filter.state');
  111.         if (is_numeric($published))
  112.         {
  113.             $query->where('a.state = '.(int) $published);
  114.         elseif ($published === '')
  115.         {
  116.             $query->where('(a.state IN (0, 1))');
  117.         }
  118.  
  119.         // Filter by a single or group of categories.
  120.         $categoryId = (int) $this->getState('filter.category_id');
  121.         if ($categoryId)
  122.         {
  123.             if (is_scalar($section))
  124.             {
  125.                 $query->where('a.catid = ' $categoryId);
  126.             }
  127.         }
  128.  
  129.         // Filter by a single user.
  130.         $userId = (int) $this->getState('filter.user_id');
  131.         if ($userId)
  132.         {
  133.             // Add the body and where filter.
  134.             $query->select('a.body')
  135.                 ->where('a.user_id = ' $userId);
  136.         }
  137.  
  138.         // Add the list ordering clause.
  139.         $orderCol $this->state->get('list.ordering');
  140.         $orderDirn $this->state->get('list.direction');
  141.         $query->order($db->escape($orderCol ' ' $orderDirn));
  142.  
  143.         return $query;
  144.     }
  145.  
  146.     /**
  147.      * Method to get a store id based on model configuration state.
  148.      *
  149.      * This is necessary because the model is used by the component and
  150.      * different modules that might need different sets of data or different
  151.      * ordering requirements.
  152.      *
  153.      * @param   string  $id  A prefix for the store id.
  154.      *
  155.      * @return  string  A store id.
  156.      *
  157.      * @since   2.5
  158.      */
  159.     protected function getStoreId($id '')
  160.     {
  161.         // Compile the store id.
  162.         $id .= ':' $this->getState('filter.search');
  163.         $id .= ':' $this->getState('filter.state');
  164.         $id .= ':' $this->getState('filter.category_id');
  165.  
  166.         return parent::getStoreId($id);
  167.     }
  168.  
  169.     /**
  170.      * Gets a user object if the user filter is set.
  171.      *
  172.      * @return  JUser  The JUser object
  173.      *
  174.      * @since   2.5
  175.      */
  176.     public function getUser()
  177.     {
  178.         $user new JUser;
  179.  
  180.         // Filter by search in title
  181.         $search JFactory::getApplication()->input->get('u_id'0'int');
  182.         if ($search != 0)
  183.         {
  184.             $user->load((int) $search);
  185.         }
  186.  
  187.         return $user;
  188.     }
  189.  
  190.     /**
  191.      * Method to auto-populate the model state.
  192.      *
  193.      * Note. Calling getState in this method will result in recursion.
  194.      *
  195.      * @return  void 
  196.      *
  197.      * @since   1.6
  198.      */
  199.     protected function populateState($ordering null$direction null)
  200.     {
  201.         $app JFactory::getApplication();
  202.         $input $app->input;
  203.  
  204.         // Adjust the context to support modal layouts.
  205.         if ($layout $input->get('layout'))
  206.         {
  207.             $this->context .= '.' $layout;
  208.         }
  209.  
  210.         $value $app->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  211.         $this->setState('filter.search'$value);
  212.  
  213.         $published $this->getUserStateFromRequest($this->context.'.filter.state''filter_published''''string');
  214.         $this->setState('filter.state'$published);
  215.  
  216.         $section $app->getUserStateFromRequest($this->context . '.filter.category_id''filter_category_id');
  217.         $this->setState('filter.category_id'$section);
  218.  
  219.         $userId $input->get('u_id'0'int');
  220.         $this->setState('filter.user_id'$userId);
  221.  
  222.         parent::populateState('a.review_time''DESC');
  223.     }
  224. }

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