<?php

namespace App\Form\Input;

/**
 * Office autocomplete field
 *
 */
class Autocomplete_OfficeAndIataCode extends Autocomplete_GeneralAbstract
{
	protected $class = "autocomplete";

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete::getUrl()
	 */
	public function getUrl()
	{
		return ($this->url?:\Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/RemoteData/AutocompleteFieldData', '', ['class'=>'OfficeAndIataCode']));
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete::determineDisplayValue()
	 */
	public function determineDisplayValue($displayId) :string
	{
		if ($displayId) {
			list($id, $iataCode) = explode(":", $displayId);
			return sprintf("%s(%s)", \Entity\Office::select($id)->name, $iataCode);
		}
		return '';
	}
}
