Files
conservatorio-tomadini/administrator/components/com_jem/tables/jem_register.php
2024-12-17 17:34:10 +01:00

124 lines
3.1 KiB
PHP

<?php
/**
* @package JEM
* @copyright (C) 2013-2024 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license https://www.gnu.org/licenses/gpl-3.0 GNU/GPL
*/
defined('_JEXEC') or die;
use Joomla\CMS\Table\Table;
/**
* Table: Register
*/
class jem_register extends Table
{
/**
* Primary Key
* @var int
*/
public $id = null;
/** @var int */
public $event = null;
/** @var int */
public $uid = null;
/** @var date */
public $uregdate = null;
/** @var string */
public $uip = null;
/** @var int */
public $waiting = 0;
/** @var int */
public $status = 0;
public function __construct(& $db)
{
parent::__construct('#__jem_register', 'id', $db);
}
/**
* Method to store a row in the database from the Table instance properties.
* If a primary key value is set the row with that primary key value will be
* updated with the instance property values. If no primary key value is set
* a new row will be inserted into the database with the properties from the
* Table instance.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @link https://docs.joomla.org/Table/store
* @since 11.1
*/
public function store($updateNulls = false)
{
if (isset($this->status)) {
if ($this->status == 2) {
$this->waiting = 1;
$this->status = 1;
}
}
return parent::store($updateNulls);
}
/**
* try to insert first, update if fails
*
* Can be overloaded/supplemented by the child class
*
* @access public
* @param boolean If false, null object variables are not updated
* @return null|string null if successful otherwise returns and error message
*/
public function insertIgnore($updateNulls = false)
{
try {
$ret = $this->_insertIgnoreObject($this->_tbl, $this, $this->_tbl_key);
} catch (RuntimeException $e){
$this->setError(get_class($this).'::store failed - '.$e->getMessage());
return false;
}
return true;
}
/**
* Inserts a row into a table based on an objects properties, ignore if already exists
*
* @access protected
* @param string The name of the table
* @param object An object whose properties match table fields
* @param string The name of the primary key. If provided the object property is updated.
* @return int number of affected row
*/
protected function _insertIgnoreObject($table, &$object, $keyName = NULL)
{
$fmtsql = 'INSERT IGNORE INTO '.$this->_db->quoteName($table).' (%s) VALUES (%s) ';
$fields = array();
foreach (get_object_vars($object) as $k => $v) {
if (is_array($v) or is_object($v) or $v === NULL) {
continue;
}
if ($k[0] == '_') { // internal field
continue;
}
$fields[] = $this->_db->quoteName($k);
$values[] = $this->_db->quote($v);
}
$this->_db->setQuery(sprintf($fmtsql, implode(",", $fields), implode(",", $values)));
if ($this->_db->execute() === false) {
return false;
}
$id = $this->_db->insertid();
if ($keyName && $id) {
$object->$keyName = $id;
}
return $this->_db->getAffectedRows();
}
}
?>