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

// no direct access
defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;

class TableRSForm_vTiger extends Table
{
	// Form ID
	public $form_id;
	
	// Auth information
	public $vt_accesskey = '';
    public $vt_username = '';
    public $vt_hostname = '';
	public $vt_debug = 1;

	// All setup fields
	public $vt_fields = '';

	// Published
	public $vt_published = 0;
	
	public function __construct(& $db)
	{
		parent::__construct('#__rsform_vtiger', 'form_id', $db);
	}

	public function check()
	{
		if (is_array($this->vt_fields))
		{
			$this->vt_fields = serialize($this->vt_fields);
		}

		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;
	}
}