Source for file message.php

Documentation is available at message.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_messages
  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.  * Message Table class
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_messages
  17.  * @since       1.5
  18.  */
  19. class MessagesTableMessage extends JTable
  20. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param database A database connector object
  25.      */
  26.     public function __construct($db)
  27.     {
  28.         parent::__construct('#__messages''message_id'$db);
  29.     }
  30.  
  31.     /**
  32.      * Validation and filtering.
  33.      *
  34.      * @return  boolean 
  35.      */
  36.     public function check()
  37.     {
  38.         // Check the to and from users.
  39.         $user new JUser($this->user_id_from);
  40.         if (empty($user->id))
  41.         {
  42.             $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_FROM_USER'));
  43.             return false;
  44.         }
  45.  
  46.         $user new JUser($this->user_id_to);
  47.         if (empty($user->id))
  48.         {
  49.             $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_TO_USER'));
  50.             return false;
  51.         }
  52.  
  53.         if (empty($this->subject))
  54.         {
  55.             $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_SUBJECT'));
  56.             return false;
  57.         }
  58.  
  59.         if (empty($this->message))
  60.         {
  61.             $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_MESSAGE'));
  62.             return false;
  63.         }
  64.  
  65.         return true;
  66.     }
  67.  
  68.     /**
  69.      * Method to set the publishing state for a row or list of rows in the database
  70.      * table.  The method respects checked out rows by other users and will attempt
  71.      * to checkin rows that it can after adjustments are made.
  72.      *
  73.      * @param   mixed    An optional array of primary key values to update.  If not
  74.      *                     set the instance property value is used.
  75.      * @param   integer The publishing state. eg. [0 = unpublished, 1 = published]
  76.      * @param   integer The user id of the user performing the operation.
  77.      * @return  boolean  True on success.
  78.      * @since   1.6
  79.      */
  80.     public function publish($pks null$state 1$userId 0)
  81.     {
  82.         $k $this->_tbl_key;
  83.  
  84.         // Sanitize input.
  85.         JArrayHelper::toInteger($pks);
  86.         $state  = (int) $state;
  87.  
  88.         // If there are no primary keys set check to see if the instance key is set.
  89.         if (empty($pks))
  90.         {
  91.             if ($this->$k)
  92.             {
  93.                 $pks array($this->$k);
  94.             }
  95.             // Nothing to set publishing state on, return false.
  96.             else {
  97.                 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
  98.                 return false;
  99.             }
  100.         }
  101.  
  102.         // Build the WHERE clause for the primary keys.
  103.         $where $k.' IN ('.implode(','$pks).')';
  104.  
  105.         // Update the publishing state for rows with the given primary keys.
  106.         $this->_db->setQuery(
  107.             'UPDATE '.$this->_db->quoteName($this->_tbl).
  108.             ' SET '.$this->_db->quoteName('state').' = '.(int) $state .
  109.             ' WHERE ('.$where.')'
  110.         );
  111.  
  112.         try
  113.         {
  114.             $this->_db->execute();
  115.         }
  116.         catch (RuntimeException $e)
  117.         {
  118.             $this->setError($e->getMessage());
  119.             return false;
  120.         }
  121.  
  122.         // If the JTable instance value is in the list of primary keys that were set, set the instance.
  123.         if (in_array($this->$k$pks))
  124.         {
  125.             $this->state $state;
  126.         }
  127.  
  128.         $this->setError('');
  129.         return true;
  130.     }
  131. }

Documentation generated on Tue, 19 Nov 2013 15:08:05 +0100 by phpDocumentor 1.4.3