[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_finder/tables/ -> filter.php (source)

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


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