<?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_Articles
 */
class TableRSForm_Articles extends Table
{
	/**
	 * Primary Key
	 *
	 * @public int
	 */
	public $form_id = null;
	
	/**
	 * @public string
	 */
	public $ra_merge_vars = '';
	/**
	 * @public string
	 */
	public $ra_content = '';
	
	/**
	 * @public int
	 */
	public $ra_published = 0;

	/**
	 * @public int
	 */
	public $ra_show_front_messages = 0;

	/**
	 * @public int
	 */
	public $ra_trigger_plugins = 0;

	/**
	 * @public int
	 */
	public $ra_trigger_on_payment = 0;

	/**
	 * TableRSForm_Articles constructor.
	 *
	 * @param $db
	 */
	public function __construct(& $db)
	{
		parent::__construct('#__rsform_articles', 'form_id', $db);
	}

	public function check()
	{
		if (!is_string($this->ra_merge_vars))
		{
			$this->ra_merge_vars = serialize($this->ra_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;
	}
}