[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/libraries/joomla/database/table/ -> extension.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Platform
   4   * @subpackage  Database
   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('JPATH_PLATFORM') or die;
  11  
  12  jimport('joomla.database.table');
  13  
  14  /**
  15   * Extension table
  16   * Replaces plugins table
  17   *
  18   * @package     Joomla.Platform
  19   * @subpackage  Table
  20   * @since       11.1
  21   */
  22  class JTableExtension extends JTable
  23  {
  24      /**
  25       * Constructor
  26       *
  27       * @param   JDatabase  &$db  A database connector object
  28       *
  29       * @since   11.1
  30       */
  31  	public function __construct(&$db)
  32      {
  33          parent::__construct('#__extensions', 'extension_id', $db);
  34      }
  35  
  36      /**
  37       * Overloaded check function
  38       *
  39       * @return  boolean  True if the object is ok
  40       *
  41       * @see     JTable::check
  42       * @since   11.1
  43       */
  44  	public function check()
  45      {
  46          // Check for valid name
  47          if (trim($this->name) == '' || trim($this->element) == '')
  48          {
  49              $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_EXTENSION'));
  50              return false;
  51          }
  52          return true;
  53      }
  54  
  55      /**
  56       * Overloaded bind function
  57       *
  58       * @param   array  $array   Named array
  59       * @param   mixed  $ignore  An optional array or space separated list of properties
  60       * to ignore while binding.
  61       *
  62       * @return  mixed  Null if operation was satisfactory, otherwise returns an error
  63       *
  64       * @see     JTable::bind
  65       * @since   11.1
  66       */
  67  	public function bind($array, $ignore = '')
  68      {
  69          if (isset($array['params']) && is_array($array['params']))
  70          {
  71              $registry = new JRegistry;
  72              $registry->loadArray($array['params']);
  73              $array['params'] = (string) $registry;
  74          }
  75  
  76          if (isset($array['control']) && is_array($array['control']))
  77          {
  78              $registry = new JRegistry;
  79              $registry->loadArray($array['control']);
  80              $array['control'] = (string) $registry;
  81          }
  82  
  83          return parent::bind($array, $ignore);
  84      }
  85  
  86      /**
  87       * Method to create and execute a SELECT WHERE query.
  88       *
  89       * @param   array  $options  Array of options
  90       *
  91       * @return  JDatabase  The database query result
  92       *
  93       * @since   11.1
  94       */
  95  	public function find($options = array())
  96      {
  97          // Get the JDatabaseQuery object
  98          $query = $this->_db->getQuery(true);
  99  
 100          foreach ($options as $col => $val)
 101          {
 102              $query->where($col . ' = ' . $this->_db->quote($val));
 103          }
 104  
 105          $query->select($this->_db->quoteName('extension_id'));
 106          $query->from($this->_db->quoteName('#__extensions'));
 107          $this->_db->setQuery($query);
 108          return $this->_db->loadResult();
 109      }
 110  
 111      /**
 112       * Method to set the publishing state for a row or list of rows in the database
 113       * table.  The method respects checked out rows by other users and will attempt
 114       * to checkin rows that it can after adjustments are made.
 115       *
 116       * @param   mixed    $pks     An optional array of primary key values to update.  If not
 117       * set the instance property value is used.
 118       * @param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published]
 119       * @param   integer  $userId  The user id of the user performing the operation.
 120       *
 121       * @return  boolean  True on success.
 122       *
 123       * @since   11.1
 124       */
 125  	public function publish($pks = null, $state = 1, $userId = 0)
 126      {
 127          // Initialise variables.
 128          $k = $this->_tbl_key;
 129  
 130          // Sanitize input.
 131          JArrayHelper::toInteger($pks);
 132          $userId = (int) $userId;
 133          $state = (int) $state;
 134  
 135          // If there are no primary keys set check to see if the instance key is set.
 136          if (empty($pks))
 137          {
 138              if ($this->$k)
 139              {
 140                  $pks = array($this->$k);
 141              }
 142              // Nothing to set publishing state on, return false.
 143              else
 144              {
 145                  $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
 146                  return false;
 147              }
 148          }
 149  
 150          // Build the WHERE clause for the primary keys.
 151          $where = $k . '=' . implode(' OR ' . $k . '=', $pks);
 152  
 153          // Determine if there is checkin support for the table.
 154          if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time'))
 155          {
 156              $checkin = '';
 157          }
 158          else
 159          {
 160              $checkin = ' AND (checked_out = 0 OR checked_out = ' . (int) $userId . ')';
 161          }
 162  
 163          // Get the JDatabaseQuery object
 164          $query = $this->_db->getQuery(true);
 165  
 166          // Update the publishing state for rows with the given primary keys.
 167          $query->update($this->_db->quoteName($this->_tbl));
 168          $query->set($this->_db->quoteName('enabled') . ' = ' . (int) $state);
 169          $query->where('(' . $where . ')' . $checkin);
 170          $this->_db->setQuery($query);
 171          $this->_db->query();
 172  
 173          // Check for a database error.
 174          if ($this->_db->getErrorNum())
 175          {
 176              $this->setError($this->_db->getErrorMsg());
 177              return false;
 178          }
 179  
 180          // If checkin is supported and all rows were adjusted, check them in.
 181          if ($checkin && (count($pks) == $this->_db->getAffectedRows()))
 182          {
 183              // Checkin the rows.
 184              foreach ($pks as $pk)
 185              {
 186                  $this->checkin($pk);
 187              }
 188          }
 189  
 190          // If the JTable instance value is in the list of primary keys that were set, set the instance.
 191          if (in_array($this->$k, $pks))
 192          {
 193              $this->enabled = $state;
 194          }
 195  
 196          $this->setError('');
 197          return true;
 198      }
 199  }


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