| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 5 * @license GNU General Public License version 2 or later; see LICENSE.txt 6 */ 7 8 // No direct access 9 defined('_JEXEC') or die; 10 11 jimport('joomla.database.table'); 12 13 /** 14 * Message Table class 15 * 16 * @package Joomla.Administrator 17 * @subpackage com_messages 18 * @since 1.5 19 */ 20 class MessagesTableMessage extends JTable 21 { 22 /** 23 * Constructor 24 * 25 * @param database A database connector object 26 */ 27 function __construct(& $db) 28 { 29 parent::__construct('#__messages', 'message_id', $db); 30 } 31 32 /** 33 * Validation and filtering. 34 * 35 * @return boolean 36 */ 37 function check() 38 { 39 // Check the to and from users. 40 $user = new JUser($this->user_id_from); 41 if (empty($user->id)) { 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 $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_TO_USER')); 49 return false; 50 } 51 52 if (empty($this->subject)) { 53 $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_SUBJECT')); 54 return false; 55 } 56 57 if (empty($this->message)) { 58 $this->setError(JText::_('COM_MESSAGES_ERROR_INVALID_MESSAGE')); 59 return false; 60 } 61 62 return true; 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 checkin rows that it can after adjustments are made. 69 * 70 * @param mixed An optional array of primary key values to update. If not 71 * set the instance property value is used. 72 * @param integer The publishing state. eg. [0 = unpublished, 1 = published] 73 * @param integer The user id of the user performing the operation. 74 * @return boolean True on success. 75 * @since 1.6 76 */ 77 public function publish($pks = null, $state = 1, $userId = 0) 78 { 79 // Initialise variables. 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 $pks = array($this->$k); 92 } 93 // Nothing to set publishing state on, return false. 94 else { 95 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); 96 return false; 97 } 98 } 99 100 // Build the WHERE clause for the primary keys. 101 $where = $k.' IN ('.implode(',', $pks).')'; 102 103 // Update the publishing state for rows with the given primary keys. 104 $this->_db->setQuery( 105 'UPDATE '.$this->_db->quoteName($this->_tbl). 106 ' SET '.$this->_db->quoteName('state').' = '.(int) $state . 107 ' WHERE ('.$where.')' 108 ); 109 $this->_db->query(); 110 111 // Check for a database error. 112 if ($this->_db->getErrorNum()) { 113 $this->setError($this->_db->getErrorMsg()); 114 return false; 115 } 116 117 // If the JTable instance value is in the list of primary keys that were set, set the instance. 118 if (in_array($this->$k, $pks)) { 119 $this->state = $state; 120 } 121 122 $this->setError(''); 123 return true; 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |