<?php
/**
 * @version     1.3.3
 * @package     sellacious
 *
 * @copyright   Copyright (C) 2012-2017 Bhartiy Web Technologies. All rights reserved.
 * @license     SPL Sellacious Private License; see http://www.sellacious.com/spl.html
 * @author      Izhar Aazmi <info@bhartiy.com> - http://www.bhartiy.com
 */
// no direct access.
defined('_JEXEC') or die;

JFormHelper::loadFieldClass('list');

/**
 * Form Field class for order statuses
 *
 */
class JFormFieldOrderStatus extends JFormFieldList
{
	/**
	 * The field type.
	 *
	 * @var  string
	 */
	protected $type = 'OrderStatus';

	/**
	 * Method to get the field options.
	 *
	 * @return  array  The field option objects.
	 * @since   1.6
	 */
	protected function getOptions()
	{
		$this->value = is_object($this->value) ? get_object_vars($this->value) : $this->value;

		$db      = JFactory::getDbo();
		$context = (string) $this->element['context'];

		$options = array();
		$helper  = SellaciousHelper::getInstance();
		$filters = array(
			'list.select' => '*',
			'list.from'   => '#__sellacious_statuses',
			'list.where'  => array(
				// '(a.state = 1 OR a.state = 0)',
				'a.state = 1',
				'a.context = ' . $db->q($context)
			),
		);
		$items   = $helper->order->loadObjectList($filters);

		foreach ($items as $item)
		{
			$options[] = JHtml::_('select.option', $item->id, $item->title, 'value', 'text');
		}

		return array_merge(parent::getOptions(), $options);
	}
}
