Source for file note.php

Documentation is available at note.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 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  JDatabaseDriver  &$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.         $date JFactory::getDate()->toSql();
  45.         $userId JFactory::getUser()->get('id');
  46.  
  47.         if (empty($this->id))
  48.         {
  49.             // New record.
  50.             $this->created_time $date;
  51.             $this->created_user_id $userId;
  52.         }
  53.         else
  54.         {
  55.             // Existing record.
  56.             $this->modified_time $date;
  57.             $this->modified_user_id $userId;
  58.         }
  59.  
  60.         // Attempt to store the data.
  61.         return parent::store($updateNulls);
  62.     }
  63.  
  64.     /**
  65.      * Method to set the publishing state for a row or list of rows in the database
  66.      * table.  The method respects checked out rows by other users and will attempt
  67.      * to check-in rows that it can after adjustments are made.
  68.      *
  69.      * @param   mixed    $pks     An optional array of primary key values to update.  If not set the instance property value is used.
  70.      * @param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published]
  71.      * @param   integer  $userId  The user id of the user performing the operation.
  72.      *
  73.      * @return  boolean  True on success.
  74.      *
  75.      * @link    http://docs.joomla.org/JTable/publish
  76.      * @since   2.5
  77.      */
  78.     public function publish($pks null$state 1$userId 0)
  79.     {
  80.         $k $this->_tbl_key;
  81.  
  82.         // Sanitize input.
  83.         JArrayHelper::toInteger($pks);
  84.         $userId = (int) $userId;
  85.         $state  = (int) $state;
  86.  
  87.         // If there are no primary keys set check to see if the instance key is set.
  88.         if (empty($pks))
  89.         {
  90.             if ($this->$k)
  91.             {
  92.                 $pks array($this->$k);
  93.             }
  94.             // Nothing to set publishing state on, return false.
  95.             else
  96.             {
  97.                 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
  98.                 return false;
  99.             }
  100.         }
  101.  
  102.         $query $this->_db->getQuery(true)
  103.             ->update($this->_db->quoteName($this->_tbl))
  104.             ->set($this->_db->quoteName('state'' = ' . (int) $state);
  105.  
  106.         // Build the WHERE clause for the primary keys.
  107.         $query->where($k '=' implode(' OR ' $k '='$pks));
  108.  
  109.         // Determine if there is checkin support for the table.
  110.         if (!property_exists($this'checked_out'|| !property_exists($this'checked_out_time'))
  111.         {
  112.             $checkin false;
  113.         }
  114.         else
  115.         {
  116.             $query->where('(checked_out = 0 OR checked_out = ' . (int) $userId ')');
  117.             $checkin true;
  118.         }
  119.  
  120.         // Update the publishing state for rows with the given primary keys.
  121.         $this->_db->setQuery($query);
  122.  
  123.         try
  124.         {
  125.             $this->_db->execute();
  126.         }
  127.         catch (RuntimeException $e)
  128.         {
  129.             $this->setError($this->_db->getMessage());
  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. }

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