<?php
namespace Modules\Admin\Config\ImportedOrders\Services;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for filters
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

		$form=\Engine\Form\Filters::create();
		$form->setColumns(2);

		$sysListObj = new \App\EntityList\ImportedOrdersSystems();
		$sysListObj->setColumns(['name']);
		$sysListObj->setOrderBy('extResSys.name', 'ASC');

		// equivalent of GetAssoc(), but using exportRecords()
		$systemsList = ['' => '-'];
		foreach($sysListObj->exportRecords() as $rec) {
			$systemsList[$rec['id']] = $rec['name'];
		}

		natcasesort($systemsList);

		// System id filter
		$systemFld= new \Engine\Form\Input\Select($this->lang['index']['filters']['idSystem'], 'filters[idSystem]', $fieldsValues['idSystem']);
		$systemFld->setPossibleValues($systemsList);
		$form->addElement($systemFld);

		// Service type id filter
		$servicesFld = new \App\Form\Input\Select_Service($this->lang['index']['filters']['idService'], 'filters[idService]', $fieldsValues['idService']);
		$form->addElement($servicesFld);

		// External service code filter
		$serviceCodeFld= new \Engine\Form\Input\Text($this->lang['index']['filters']['externalServiceCode'], 'filters[externalServiceCode]', $fieldsValues['externalServiceCode']);
		$form->addElement($serviceCodeFld);

		$form->setJsCallback('MVC.listing.installedHandlers["listing"].reloadAndResetListing');
		$form->loadMissingDefaultValues($this->values['listingParams']->getDefaultFilters());
		return $form;
	}

}