Source for file filter.php

Documentation is available at filter.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_finder
  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
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Filter table class for the Finder package.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_finder
  17.  * @since       2.5
  18.  */
  19. class FinderTableFilter extends JTable
  20. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param   JDatabaseDriver  &$db  JDatabaseDriver connector object.
  25.      *
  26.      * @since   2.5
  27.      */
  28.     public function __construct(&$db)
  29.     {
  30.         parent::__construct('#__finder_filters''filter_id'$db);
  31.     }
  32.  
  33.     /**
  34.      * Method to bind an associative array or object to the JTable instance.  This
  35.      * method only binds properties that are publicly accessible and optionally
  36.      * takes an array of properties to ignore when binding.
  37.      *
  38.      * @param   array  $array   Named array
  39.      * @param   mixed  $ignore  An optional array or space separated list of properties
  40.      *                           to ignore while binding. [optional]
  41.      *
  42.      * @return  mixed  Null if operation was satisfactory, otherwise returns an error string
  43.      *
  44.      * @since   2.5
  45.      */
  46.     public function bind($array$ignore '')
  47.     {
  48.         if (isset($array['params']&& is_array($array['params']))
  49.         {
  50.             $registry new JRegistry;
  51.             $registry->loadArray($array['params']);
  52.             $array['params'= (string) $registry;
  53.         }
  54.  
  55.         return parent::bind($array$ignore);
  56.     }
  57.  
  58.     /**
  59.      * Method to perform sanity checks on the JTable instance properties to ensure
  60.      * they are safe to store in the database.  Child classes should override this
  61.      * method to make sure the data they are storing in the database is safe and
  62.      * as expected before storage.
  63.      *
  64.      * @return  boolean  True if the instance is sane and able to be stored in the database.
  65.      *
  66.      * @since   2.5
  67.      */
  68.     public function check()
  69.     {
  70.         if (trim($this->alias== '')
  71.         {
  72.             $this->alias $this->title;
  73.         }
  74.  
  75.         $this->alias JApplication::stringURLSafe($this->alias);
  76.  
  77.         if (trim(str_replace('-'''$this->alias)) == '')
  78.         {
  79.             $this->alias JFactory::getDate()->format('Y-m-d-H-i-s');
  80.         }
  81.  
  82.         // Check the end date is not earlier than start up.
  83.         if ($this->d2 $this->_db->getNullDate(&& $this->d2 $this->d1)
  84.         {
  85.             // Swap the dates.
  86.             $temp $this->d1;
  87.             $this->d1 $this->d2;
  88.             $this->d2 $temp;
  89.         }
  90.  
  91.         return true;
  92.     }
  93.  
  94.     /**
  95.      * Method to set the publishing state for a row or list of rows in the database
  96.      * table. The method respects checked out rows by other users and will attempt
  97.      * to checkin rows that it can after adjustments are made.
  98.      *
  99.      * @param   mixed    $pks     An array of primary key values to update.  If not
  100.      *                             set the instance property value is used. [optional]
  101.      * @param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published] [optional]
  102.      * @param   integer  $userId  The user id of the user performing the operation. [optional]
  103.      *
  104.      * @return  boolean  True on success.
  105.      *
  106.      * @since   2.5
  107.      */
  108.     public function publish($pks null$state 1$userId 0)
  109.     {
  110.         $k $this->_tbl_key;
  111.  
  112.         // Sanitize input.
  113.         JArrayHelper::toInteger($pks);
  114.         $userId = (int) $userId;
  115.         $state = (int) $state;
  116.  
  117.         // If there are no primary keys set check to see if the instance key is set.
  118.         if (empty($pks))
  119.         {
  120.             if ($this->$k)
  121.             {
  122.                 $pks array($this->$k);
  123.             }
  124.             // Nothing to set publishing state on, return false.
  125.             else
  126.             {
  127.                 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
  128.                 return false;
  129.             }
  130.         }
  131.  
  132.         // Build the WHERE clause for the primary keys.
  133.         $where $k '=' implode(' OR ' $k '='$pks);
  134.  
  135.         // Determine if there is checkin support for the table.
  136.         if (!property_exists($this'checked_out'|| !property_exists($this'checked_out_time'))
  137.         {
  138.             $checkin '';
  139.         }
  140.         else
  141.         {
  142.             $checkin ' AND (checked_out = 0 OR checked_out = ' . (int) $userId ')';
  143.         }
  144.  
  145.         // Update the publishing state for rows with the given primary keys.
  146.         $query $this->_db->getQuery(true)
  147.             ->update($this->_db->quoteName($this->_tbl))
  148.             ->set($this->_db->quoteName('state'' = ' . (int) $state)
  149.             ->where($where);
  150.         $this->_db->setQuery($query $checkin);
  151.  
  152.         try
  153.         {
  154.             $this->_db->execute();
  155.         }
  156.         catch (RuntimeException $e)
  157.         {
  158.             $this->setError($e->getMessage());
  159.             return false;
  160.         }
  161.  
  162.         // If checkin is supported and all rows were adjusted, check them in.
  163.         if ($checkin && (count($pks== $this->_db->getAffectedRows()))
  164.         {
  165.             // Checkin the rows.
  166.             foreach ($pks as $pk)
  167.             {
  168.                 $this->checkin($pk);
  169.             }
  170.         }
  171.  
  172.         // If the JTable instance value is in the list of primary keys that were set, set the instance.
  173.         if (in_array($this->$k$pks))
  174.         {
  175.             $this->state $state;
  176.         }
  177.  
  178.         $this->setError('');
  179.  
  180.         return true;
  181.     }
  182.  
  183.     /**
  184.      * Method to store a row in the database from the JTable instance properties.
  185.      * If a primary key value is set the row with that primary key value will be
  186.      * updated with the instance property values.  If no primary key value is set
  187.      * a new row will be inserted into the database with the properties from the
  188.      * JTable instance.
  189.      *
  190.      * @param   boolean  $updateNulls  True to update fields even if they are null. [optional]
  191.      *
  192.      * @return  boolean  True on success.
  193.      *
  194.      * @since   2.5
  195.      */
  196.     public function store($updateNulls false)
  197.     {
  198.         $date JFactory::getDate();
  199.         $user JFactory::getUser();
  200.  
  201.         if ($this->filter_id)
  202.         {
  203.             // Existing item
  204.             $this->modified $date->toSql();
  205.             $this->modified_by $user->get('id');
  206.         }
  207.         else
  208.         {
  209.             // New item. A filter's created field can be set by the user,
  210.             // so we don't touch it if it is set.
  211.             if (!(int) $this->created)
  212.             {
  213.                 $this->created $date->toSql();
  214.             }
  215.             if (empty($this->created_by))
  216.             {
  217.                 $this->created_by $user->get('id');
  218.             }
  219.         }
  220.  
  221.         if (is_array($this->data))
  222.         {
  223.             $this->map_count count($this->data);
  224.             $this->data implode(','$this->data);
  225.         }
  226.         else
  227.         {
  228.             $this->map_count 0;
  229.             $this->data implode(','array());
  230.         }
  231.  
  232.         // Verify that the alias is unique
  233.         $table JTable::getInstance('Filter''FinderTable');
  234.         if ($table->load(array('alias' => $this->alias)) && ($table->filter_id != $this->filter_id || $this->filter_id == 0))
  235.         {
  236.             $this->setError(JText::_('JLIB_DATABASE_ERROR_ARTICLE_UNIQUE_ALIAS'));
  237.             return false;
  238.         }
  239.         return parent::store($updateNulls);
  240.     }
  241. }

Documentation generated on Tue, 19 Nov 2013 15:03:16 +0100 by phpDocumentor 1.4.3