Source for file message.php
Documentation is available at message.php
* @package Joomla.Administrator
* @subpackage com_messages
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla.Administrator
* @subpackage com_messages
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
$this->setState('user.id', $user->get('id'));
$messageId = (int)
$input->getInt('message_id');
$this->setState('message.id', $messageId);
$replyId = (int)
$input->getInt('reply_id');
* Check that recipient user is the one trying to delete and then call parent delete method
* @param array &$pks An array of record primary keys.
* @return boolean True if successful, false if an error occurs.
// Iterate the items to delete each one.
foreach ($pks as $i =>
$pk)
if ($table->user_id_to !==
$user->id)
// Prune items that you can't change.
JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
return parent::delete($pks);
* Returns a Table object, always creating it.
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
public function getTable($type =
'Message', $prefix =
'MessagesTable', $config =
array())
* Method to get a single record.
* @param integer The id of the primary key.
* @return mixed Object on success, false on failure.
public function getItem($pk =
null)
if ($this->item =
parent::getItem($pk))
// Prime required properties.
if (empty($this->item->message_id))
// Prepare data for a new record.
if ($replyId =
$this->getState('reply.id'))
// If replying to a message, preload some data.
$query =
$db->getQuery(true)
->select('subject, user_id_from')
->where('message_id = '.(int)
$replyId);
$message =
$db->setQuery($query)->loadObject();
catch
(RuntimeException $e)
$this->item->set('user_id_to', $message->user_id_from);
$re =
JText::_('COM_MESSAGES_RE');
if (stripos($message->subject, $re) !==
0)
$this->item->set('subject', $re.
$message->subject);
$query =
$db->getQuery(true)
->where('message_id = '.
$this->item->message_id);
$db->setQuery($query)->execute();
// Get the user name for an existing messasge.
if ($this->item->user_id_from &&
$fromUser =
new JUser($this->item->user_id_from))
$this->item->set('from_user_name', $fromUser->name);
* Method to get the record form.
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
public function getForm($data =
array(), $loadData =
true)
$form =
$this->loadForm('com_messages.message', 'message', array('control' =>
'jform', 'load_data' =>
$loadData));
* Method to get the data that should be injected in the form.
* @return mixed The data for the form.
// Check the session for previously entered form data.
* Checks that the current user matches the message recipient and calls the parent publish method
* @param array &$pks A list of the primary keys to change.
* @param integer $value The value of the published state.
* @return boolean True on success.
public function publish(&$pks, $value =
1)
// Check that the recipient matches the current user
foreach ($pks as $i =>
$pk)
if ($table->user_id_to !==
$user->id)
// Prune items that you can't change.
JLog::add(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
return parent::publish($pks, $value);
* Method to save the form data.
* @param array The form data.
* @return boolean True on success.
public function save($data)
if (!$table->bind($data))
if (empty($table->user_id_from))
if ((int)
$table->date_time ==
0)
// Load the recipient user configuration.
$model->setState('user.id', $table->user_id_to);
$config =
$model->getItem();
if ($config->get('locked', false))
if ($config->get('mail_on_new', true))
// Load the user details (already valid from table check).
$default_language =
JComponentHelper::getParams('com_languages')->get('administrator');
$siteURL =
JUri::root() .
'administrator/index.php?option=com_messages&view=message&message_id='.
$table->message_id;
$subject =
sprintf($lang->_('COM_MESSAGES_NEW_MESSAGE_ARRIVED'), $sitename);
$msg =
sprintf($lang->_('COM_MESSAGES_PLEASE_LOGIN'), $siteURL);
JFactory::getMailer()->sendMail($fromUser->email, $fromUser->name, $toUser->email, $subject, $msg);
Documentation generated on Tue, 19 Nov 2013 15:08:04 +0100 by phpDocumentor 1.4.3