[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_users/tables/ -> note.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Administrator
   4   * @subpackage  com_users
   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  /**
  13   * User notes table class
  14   *
  15   * @package     Joomla.Administrator
  16   * @subpackage  com_users
  17   * @since       2.5
  18   */
  19  class UsersTableNote extends JTable
  20  {
  21      /**
  22       * Constructor
  23       *
  24       * @param  JDatabase  &$db  Database object
  25       *
  26       * @since  2.5
  27       */
  28  	public function __construct(&$db)
  29      {
  30          parent::__construct('#__user_notes', 'id', $db);
  31      }
  32  
  33      /**
  34       * Overloaded store method for the notes table.
  35       *
  36       * @param   boolean  $updateNulls  Toggle whether null values should be updated.
  37       *
  38       * @return  boolean  True on success, false on failure.
  39       *
  40       * @since   2.5
  41       */
  42  	public function store($updateNulls = false)
  43      {
  44          // Initialise variables.
  45          $date = JFactory::getDate()->toMySQL();
  46          $userId = JFactory::getUser()->get('id');
  47  
  48          if (empty($this->id))
  49          {
  50              // New record.
  51              $this->created_time = $date;
  52              $this->created_user_id = $userId;
  53          }
  54          else
  55          {
  56              // Existing record.
  57              $this->modified_time = $date;
  58              $this->modified_user_id = $userId;
  59          }
  60  
  61          // Attempt to store the data.
  62          return parent::store($updateNulls);
  63      }
  64  
  65      /**
  66       * Method to set the publishing state for a row or list of rows in the database
  67       * table.  The method respects checked out rows by other users and will attempt
  68       * to check-in rows that it can after adjustments are made.
  69       *
  70       * @param   mixed    $pks     An optional array of primary key values to update.  If not set the instance property value is used.
  71       * @param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published]
  72       * @param   integer  $userId  The user id of the user performing the operation.
  73       *
  74       * @return  boolean  True on success.
  75       *
  76       * @link    http://docs.joomla.org/JTable/publish
  77       * @since   2.5
  78       */
  79  	public function publish($pks = null, $state = 1, $userId = 0)
  80      {
  81          // Initialise variables.
  82          $k = $this->_tbl_key;
  83  
  84          // Sanitize input.
  85          JArrayHelper::toInteger($pks);
  86          $userId = (int) $userId;
  87          $state  = (int) $state;
  88  
  89          // If there are no primary keys set check to see if the instance key is set.
  90          if (empty($pks))
  91          {
  92              if ($this->$k)
  93              {
  94                  $pks = array($this->$k);
  95              }
  96              // Nothing to set publishing state on, return false.
  97              else
  98              {
  99                  $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
 100                  return false;
 101              }
 102          }
 103  
 104          $query = $this->_db->getQuery(true);
 105          $query->update($this->_db->quoteName($this->_tbl));
 106          $query->set($this->_db->quoteName('state') . ' = ' . (int) $state);
 107  
 108          // Build the WHERE clause for the primary keys.
 109          $query->where($k . '=' . implode(' OR ' . $k . '=', $pks));
 110  
 111          // Determine if there is checkin support for the table.
 112          if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time'))
 113          {
 114              $checkin = false;
 115          }
 116          else
 117          {
 118              $query->where('(checked_out = 0 OR checked_out = ' . (int) $userId . ')');
 119              $checkin = true;
 120          }
 121  
 122          // Update the publishing state for rows with the given primary keys.
 123          $this->_db->setQuery($query);
 124          $this->_db->query();
 125  
 126          // Check for a database error.
 127          if ($this->_db->getErrorNum())
 128          {
 129              $this->setError($this->_db->getErrorMsg());
 130              return false;
 131          }
 132  
 133          // If checkin is supported and all rows were adjusted, check them in.
 134          if ($checkin && (count($pks) == $this->_db->getAffectedRows()))
 135          {
 136              // Checkin the rows.
 137              foreach($pks as $pk)
 138              {
 139                  $this->checkin($pk);
 140              }
 141          }
 142  
 143          // If the JTable instance value is in the list of primary keys that were set, set the instance.
 144          if (in_array($this->$k, $pks))
 145          {
 146              $this->state = $state;
 147          }
 148  
 149          $this->setError('');
 150          return true;
 151      }
 152  }


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