<?php
use Joomla\CMS\Factory;
/**
 * @version        1.9.7
 * @package        Joomla
 * @subpackage     Edocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2024 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

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

class EdocmanModelTerms extends OSModelList
{
	/**
	 * Constructor.
	 *
	 * @param    array    An optional associative array of configuration settings.
	 *
	 * @see        OSModelList
	 */
	public function __construct($config = array())
	{
		$app     = Factory::getApplication();
		$config['table']         = '#__edocman_search_terms';
		parent::__construct($config);
		$context = $this->option . '.' . $this->name . '.';

		$this->state->insert('start_date','string','')
			->insert('end_date','string','');
	}

	/**
	 * Builds WHERE clauses for the query
	 *
	 * @param JDatabaseQuery $query
	 *
	 * @return $this
	 */
	protected function _buildQueryWhere(JDatabaseQuery $query)
	{
		//parent::_buildQueryWhere($query);

		if($this->state->filter_search != "")
		{
			
			$query->where(' tbl.keyword like "' . $this->state->filter_search . '"');
			
		}		

		if($this->state->start_date != "" && $this->state->start_date != "0000-00-00")
		{
			$query->where('tbl.searched_on >= "'.$this->state->start_date. '"');
		}

		if($this->state->end_date != "" && $this->state->end_date != "0000-00-00")
		{
			$query->where('tbl.searched_on <= "'.$this->state->end_date. '"');
		}
		//echo($query->__toString());die();
		return $this;
	}

	
}
