<?php
namespace App\Form\Input;

class Select_OrdersExternalSystem extends \Engine\Form\Input\Select
{
	/**
	 * new value added to this selector
	 */
	protected $manualValue = null;

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Select::getPossibleValues()
	 */
	protected function determinePossibleValues()
	{
 		// determine the systems list
		$sysListObj = new \App\EntityList\ImportedOrdersSystems();
		$sysListObj->setColumns(['name']);
		$sysListObj->setFilter('extResSys.active', '=', 1);
		$sysListObj->setOrderBy('extResSys.name', 'ASC');

		// equivalent of GetAssoc(), but using exportRecords()
		$assocSystems = [];
		if ($this->manualValue) {
			$assocSystems[$this->manualValue['value']] = $this->manualValue['title'];
		}
		foreach($sysListObj->exportRecords() as $rec) {
			$assocSystems[$rec['id']] = $rec['name'];
		}

		return $assocSystems;
 	}

 	/**
 	 * this function helps you to add a new value in selector
 	 * you must add the value and the title
 	 * @param string $value
 	 * @param string $title
 	 */
 	public function setManualValue($value, $title)
 	{
 		$this->manualValue = ['value'=>$value, 'title'=>$title];
 	}
}
