<?php
/**
 * @package    RSForm! Pro
 * @copyright  (c) 2007 - 2016 RSJoomla!
 * @link       https://www.rsjoomla.com
 * @license    GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html
 */

defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;

class TableRSForm_VerticalResponse extends Table
{
	/**
	 * Primary Key
	 *
	 * @var int
	 */
	public $form_id = null;
	public $enable_verticalresponse = 0;
	public $verticalresponse_update = 1;
	public $verticalresponse_list = '';
	public $vars = '';

	/**
	 * Constructor
	 *
	 * @param object Database connector object
	 */
	public function __construct(& $db)
	{
		parent::__construct('#__rsform_verticalresponse', '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;
	}
}