<?php
/**
 * @package			RSForm! Pro
 * @copyright		(C) 2007-2019 www.rsjoomla.com
 * @license       	GPL, http://www.gnu.org/copyleft/gpl.html
 */

defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;

class TableRSForm_GetResponse extends Table
{
	/**
	 * Primary Key
	 *
	 * @var int
	 */
	public $form_id = null;
	public $enable_getresponse = 1;
	public $getresponse_update = 1;
	public $getresponse_list = '';
	public $vars = '';

	/**
	 * Constructor
	 *
	 * @param object Database connector object
	 */
	public function __construct(& $db)
	{
		parent::__construct('#__rsform_getresponse', 'form_id', $db);
	}

	// Validate data before save
	public function check()
	{
		if (is_array($this->vars))
		{
			$this->vars = serialize($this->vars);
		}

		return true;
	}

	public function hasPrimaryKey()
	{
		$db 	= $this->getDbo();
		$key 	= $this->getKeyName();
		$table	= $this->getTableName();

		$query = $db->getQuery(true)
			->select($db->qn($key))
			->from($db->qn($table))
			->where($db->qn($key) . ' = ' . $db->q($this->{$key}));

		return $db->setQuery($query)->loadResult() !== null;
	}

}