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/RoomsTable.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\Table\Table;
use JExtstore\Component\JChat\Administrator\Framework\Exception\Exceptions; 

/**
 * ORM Table for rooms entities
 *
 * @package JCHAT::FORM::components::com_jchat
 * @subpackage tables
 * @since 1.0
 */
class RoomsTable extends Table {
	use Exceptions;
	
	/**
	 *
	 * @var int
	 */
	public $id = 0;
	
	/**
	 *
	 * @var string
	 */
	public $name = '';
	
	/**
	 *
	 * @var string
	 */
	public $description = null;
	
	/**
	 *
	 * @var int
	 */
	public $checked_out = null;
	
	/**
	 *
	 * @var datetime
	 */
	public $checked_out_time = null;
	
	/**
	 *
	 * @var int
	 */
	public $published = 1;
	
	/**
	 *
	 * @var int
	 */
	public $ordering = 0;
	
	/**
	 *
	 * @var int
	 */
	public $access = 1;
	
	/**
	 *
	 * @var string
	 */
	public $menuitems = null;
	
	/**
	 * Check Table override
	 * @override
	 *
	 * @see Table::check()
	 */
	public function check() {
		// Name required
		if (! $this->name) {
			$this->setException ( Text::_ ( 'COM_JCHAT_VALIDATION_ERROR' ) );
			return false;
		}
		
		return true;
	}
	
	/**
	 * Bind Table override
	 * @override
	 *
	 * @see Table::bind()
	 */
	public function bind($fromArray, $ignore = array(), $saveTask = false, $sessionTask = false) {
		parent::bind ( $fromArray, $ignore);
	
		// MySql strict mode primary key auto increment compliance
		if(!$this->id) {
			$this->id = 0;
		}
		
		// Serialize comma separated
		if (is_array ( $this->menuitems ) && $saveTask) {
			$this->menuitems = implode(',', $this->menuitems);
		}

		return true;
	}
	
	/**
	 * 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 comma separated
		if ($this->menuitems) {
			$this->menuitems = explode(',', $this->menuitems );
		} else {
			// Init qui
			$this->menuitems = array ();
		}
	
		return true;
	}
	
	/**
	 * Store Table override
	 * @override
	 *
	 * @see JTable::store()
	 */
	public function store($updateNulls = false) {
		// Force 0 to NULL and update nulls
		if($this->menuitems == '0' || !$this->menuitems) {
			$this->menuitems = null;
			$updateNulls = true;
		}

		$result = parent::store($updateNulls);

		return $result;
	}
	
	/**
	 * 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_rooms', 'id', $db, $dispatcher );
		
		// Support null values for datetime field
		$this->_supportNullValue = true;
	}
}