<?php
/**
 * @package     CMGiftCard
 * @subpackage  com_cmgiftcard
 * @copyright   Copyright (C) 2016-2024 CMExension
 * @license     GNU General Public License version 2 or later
 */

defined('JPATH_BASE') or die();

require_once JPATH_ROOT . '/administrator/components/com_cmgiftcard/models/base_fields/radio.php';

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\RadioField;

/**
 * Form field for selecting gift card design.
 *
 * @package     CMGiftCard
 * @subpackage  com_cmgiftcard
 * @since       1.0.0
 */
class JFormFieldCMGCDesign extends CMGiftCardRadioField
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  1.0.0
	 */
	protected $type = 'CMGCDesign';

	/**
	 * Name of the layout being used to render the field.
	 *
	 * @var    string
	 * @since  1.0.0
	 */
	protected $layout = 'design';

	/**
	 * Method to get the field options.
	 *
	 * @return  array  The field option objects.
	 *
	 * @since   1.0.0
	 */
	public function getOptions()
	{
		$db = Factory::getDbo();

		$query = $db->getQuery(true)
			->select($db->qn(array('card_type', 'image')))
			->select($db->qn('id') . ' AS value')
			->select($db->qn('title') . ' AS text')
			->from($db->qn('#__cmgiftcard_designs'))
			->where($db->qn('card_type') . ' = ' . $db->q('electronic'))
			//->where($db->qn('published') . ' = ' . $db->q(1))
			->order($db->qn('ordering') . ' ASC');
		$options['electronic'] = $db->setQuery($query)->loadObjectList();

		$query->clear()
			->select($db->qn(array('card_type', 'image')))
			->select($db->qn('id') . ' AS value')
			->select($db->qn('title') . ' AS text')
			->from($db->qn('#__cmgiftcard_designs'))
			->where($db->qn('card_type') . ' = ' . $db->q('physical'))
			//->where($db->qn('published') . ' = ' . $db->q(1))
			->order($db->qn('ordering') . ' ASC');
		$options['physical'] = $db->setQuery($query)->loadObjectList();

		return $options;
	}
}
