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

defined('_JEXEC') or die;

use Joomla\CMS\Table\Table;

class TableRSForm_ZohoCrm extends Table
{
	public $form_id 			= null;	
	public $zh_wf_trigger 		= 1;
	public $zh_duplicate_check  = 1;
	public $zh_is_approval 		= 0;
	public $zh_format 			= 1;
	public $zh_layout_id        = '';
	public $zh_merge_vars 		= '';
	public $zh_track_ga			= 0;
	public $zh_lar_id			= '';
	public $zh_debug 			= 0;
	public $zh_published 		= 0;
	public $zh_action 		    = 1;
	public $zh_action_field 	= '';

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

	public function check()
	{
		if (is_array($this->zh_merge_vars))
		{
			$this->zh_merge_vars = serialize($this->zh_merge_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;
	}
}