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/SessionstatusTable.php

<?php
namespace JExtstore\Component\JChat\Administrator\Table;
/**
 *
 * @package JCHAT::FORM::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
 */
// no direct access
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\Factory;
use Joomla\CMS\Table\Table;
use JExtstore\Component\JChat\Administrator\Framework\Exception\Exceptions; 

/**
 * ORM Table for event entities
 *
 * @package JCHAT::FORM::components::com_jchat
 * @subpackage tables
 * @since 1.0
 */
class SessionstatusTable extends Table {
	use Exceptions;
	
	/**
	 * DatabaseInterface object.
	 * @protected DatabaseInterface Object
	 */
	protected $dbo;
	/**
	 *
	 * @var int
	 */
	public $sessionid = null;
	
	/**
	 *
	 * @var string
	 */
	public $status = null;
	
	/**
	 *
	 * @var string
	 */
	public $override_name = null;
	
	/**
	 *
	 * @var string
	 */
	public $email = null;
	
	/**
	 *
	 * @var string
	 */
	public $description = null;
	
	/**
	 *
	 * @var int
	 */
	public $skypeid = null;
	
	/**
	 *
	 * @var int
	 */
	public $roomid = null;
	
	/**
	 *
	 * @var int
	 */
	public $typing = null;
	
	/**
	 *
	 * @var int
	 */
	public $typing_to = null;
	
	/**
	 *
	 * @var int
	 */
	public $banstatus = null;
	
	/**
	 *
	 * @var string
	 */
	public $geoip = null;
	
	/**
	 *
	 * @var string
	 */
	public $meeting_hash = null;
	
	/**
	 *
	 * @var string
	 */
	public $livestreaming_hash = null;
	
	/**
	 *
	 * @var int
	 */
	public $livestreaming_watch = null;
	
	/**
	 * Check Table override
	 * @override
	 *
	 * @see Table::check()
	 */
	public function check() {
		$app = Factory::getApplication();
		$cparams = $app->getParams('com_jchat');
		
		// Name required
		if (! $this->override_name) {
			$this->setException ( Text::_ ( 'COM_JCHAT_VALIDATION_ERROR_OVERRIDENAME' ) );
			return false;
		}
		
		// Ensure that username does not exists, validation server side
		$userNameFound = false;
		$sessionNameFound = false;
		if($cparams->get('unique_usernames', false)) {
			$query = "SELECT " . $this->dbo->quoteName('sessionid') .
					 "\n FROM " . $this->dbo->quoteName('#__jchat_sessionstatus') .
					 "\n WHERE " . $this->dbo->quoteName('override_name') . " = " . $this->dbo->quote($this->override_name) .
					 "\n AND " . $this->dbo->quoteName('sessionid') . " != " . $this->dbo->quote(session_id());
			$sessionNameFound = $this->dbo->setQuery($query)->loadResult();
			
			$query = "SELECT " . $this->dbo->quoteName('id') .
					 "\n FROM " . $this->dbo->quoteName('#__users') .
					 "\n WHERE " . $this->dbo->quoteName('name') . " = " . $this->dbo->quote($this->override_name) .
					 "\n OR " . $this->dbo->quoteName('username') . " = " . $this->dbo->quote($this->override_name);
			$userNameFound = $this->dbo->setQuery($query)->loadResult();
		}
		
		if($sessionNameFound || $userNameFound) {
			$this->setException ( Text::_ ( 'COM_JCHAT_VALIDATION_ERROR_OVERRIDENAME_EXISTS' ) );
			return false;
		}
		
		if($cparams->get('validate_email', false) && !$this->email) {
			$this->setException ( Text::_ ( 'COM_JCHAT_VALIDATION_ERROR_EMAIL' ) );
			return false;
		}
		
		// Link url required and to be valid
		if ($this->email && !filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
			$this->setException ( Text::_('COM_JCHAT_VALIDATION_ERROR_EMAIL' ) );
			return false;
		}
		
		if($cparams->get('validate_description', false) && !$this->description) {
			$this->setException ( Text::_ ( 'COM_JCHAT_VALIDATION_ERROR_DESC' ) );
			return false;
		}
		
		// Validate antispam result
		if($cparams->get('show_antispam', false)) {
			// Get addendi and check operations
			$operand1 = $app->getInput()->post->getInt('validation_op1');
			$operand2 = $app->getInput()->post->getInt('validation_op2');
			$result = $app->getInput()->post->getInt('validation_result');
			if(($operand1 + $operand2) != $result) {
				$this->setException ( Text::_('COM_JCHAT_VALIDATION_ERROR_ANTISPAM' ) );
				return false;
			}
		}
		
		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) {
		$primaryKey = 'sessionid';
		
		// Check if the session id is not already present in sessionstatus and if so force an insert store by faking primary key
		$query = "SELECT COUNT(*)" .
				 "\n FROM " . $db->quoteName('#__jchat_sessionstatus') .
				 "\n WHERE " . $db->quoteName('sessionid') . " = " . $db->quote(session_id());
		$sessionRowExists = $db->setQuery($query)->loadResult();
		if(!$sessionRowExists) {
			$primaryKey = array('sessionid', 'status');
		}
		
		$this->dbo = $db;
		
		parent::__construct ( '#__jchat_sessionstatus', $primaryKey, $db, $dispatcher );
	}
}