Your IP : 216.73.216.224


Current Path : /var/www/html/administrator/components/com_jchat/Table/
Upload File :
Current File : /var/www/html/administrator/components/com_jchat/Table/LamessagesTable.php

<?php
namespace JExtstore\Component\JChat\Administrator\Table;
/**
 *
 * @package JCHAT::MESSAGES::administrator::components::com_jchat
 * @subpackage tables
 * @author Joomla! Extensions Store
 * @copyright (C) 2024 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\Database\DatabaseInterface;
use Joomla\Database\DatabaseDriver;
use Joomla\Event\DispatcherInterface;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Date\Date;
use JExtstore\Component\JChat\Administrator\Framework\Exception\Exceptions;

/**
 * Messages table
 *
 * @package JCHAT::LAMESSAGES::administrator::components::com_jchat
 * @subpackage tables
 * @since 1.0
 */
class LamessagesTable extends Table {
	use Exceptions;
	
	/**
	 *
	 * @var string
	 */
	private $_username_logged;
	/**
	 * DatabaseInterface object.
	 * @protected DatabaseInterface Object
	 */
	protected $dbo;
	/**
	 *
	 * @var int Primary key
	 */
	public $id = 0;
	/**
	 *
	 * @var string
	 */
	public $name = '';
	/**
	 *
	 * @var string
	 */
	public $email = '';
	/**
	 *
	 * @var string
	 */
	public $phonenumber = '';
	/**
	 *
	 * @var string
	 */
	public $message = '';
	/**
	 *
	 * @var string
	 */
	public $sentdate = '';
	/**
	 *
	 * @var int
	 */
	public $userid = null;
	/**
	 *
	 * @var int
	 */
	public $worked = null;
	/**
	 *
	 * @var string
	 */
	public $responses = array ();
	
	/**
	 *
	 * @var int
	 */
	public $checked_out = null;
	
	/**
	 *
	 * @var datetime
	 */
	public $checked_out_time = null;
	/**
	 *
	 * @var int
	 */
	public $closed_ticket = 0;
	
	/**
	 * Loads a row from the database and binds the fields to the object properties
	 *
	 * @override
	 *
	 * @access public
	 * @param
	 *        	mixed	Optional primary key. If not specifed, the value of current key is used
	 * @return boolean if successful
	 */
	public function load($keys = null, $reset = true) {
	// If not $idEntity set return empty object
		if($keys) {
			if(!parent::load ( $keys, $reset )) {
				return false;
			}
		}
		
		// Unserialize campo risposte/data
		if ($this->responses) {
			$this->responses = unserialize ( $this->responses );
		} else {
			// Init qui
			$this->responses = array ();
		}

		// Foreign key management
		$usersTable = new \Joomla\CMS\Table\User($this->dbo);
		
		// Foreign key mapping #__users
		if ($usersTable->load ( $this->userid )) {
			$this->_username_logged = $usersTable->name;
		}
		
		return true;
	}
	
	/**
	 * Check Table override
	 * @override
	 *
	 * @see Table::check()
	 */
	public function check() {
		// Name required
		if (! $this->name) {
			$this->setException ( Text::_ ( 'COM_JCHAT_VALIDATION_ERROR' ) );
			return false;
		}
		
		// Email required and in valid format
		if (!$this->email || !filter_var(trim($this->email), FILTER_VALIDATE_EMAIL)) {
			$this->setException ( Text::sprintf( 'COM_JCHAT_VALIDATION_ERROR_SUBJECT', $this->email ));
			return false;
		}
		
		// Email required and in valid format
		if (! $this->sentdate) {
			$this->setException ( Text::sprintf( 'COM_JCHAT_VALIDATION_ERROR_SUBJECT', $this->sentdate ));
			return false;
		}
		
		return true;
	}
	
	/**
	 * Binds a named array/hash to this object
	 *
	 * @override
	 *
	 * @access public
	 * @param
	 *        	mixed	Optional primary key. If not specifed, the value of current key is used
	 * @param boolean $storeResponse        	
	 * @return boolean if successful
	 */
	function bind($from, $ignore = array(), $saveTask = false, $sessionTask = false) {
		// Parent std load
		parent::bind ( $from, $ignore );
		
		// MySql strict mode primary key auto increment compliance
		if(!$this->id) {
			$this->id = 0;
		}
		
		// Unserialize campo risposte/data
		if (is_array ( $this->responses ) && $saveTask === 2) {
			$this->responses [] = array (
					Date::getInstance()->toSql(),
					$from ['response'],
					$from ['ticket_sender']
			);
			$this->responses = serialize ( $this->responses );
		}
		
		return true;
	}
	
	/**
	 * Class constructor
	 * @param DatabaseDriver $db DatabaseDriver object.
	 * @param DispatcherInterface  $dispatcher  Event dispatcher for this table
	 *
	 * return Object&
	 */
	public function __construct(DatabaseInterface $db, ?DispatcherInterface $dispatcher = null) {
		parent::__construct ( '#__jchat_lamessages', 'id', $db, $dispatcher );
		
		$this->dbo = $db;
		
		// Support null values for datetime field
		$this->_supportNullValue = true;
	}
}