<?php
namespace Modules\Orders\Amadeus\ServicesList;

class Controller extends \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract
{
	/**
	 * The list of columns which support ordering.
	 * @var array
	 */
	protected $listOrderingColumns= ['id'];

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract::optionDefineParams()
	 */
	protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection)
	{
		switch($option->getId()){
			case 'orderTicketDetails':
				foreach ($selection as $selectedItem) {
					if (!\Entity\AmadeusService::select($selectedItem)->importedServiceId && !\Entity\AmadeusService::select($selectedItem)->refundedService->importedServiceId) {
						$option->setDisabled();
						break;
					}
				}
			break;

			default:
				return false;
		}

		return true;
	}


	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract::optionGetEntityName()
	 */
	protected function optionGetEntityName($id)
	{
		$service = \Entity\AmadeusService::select($id);
		return ($service->docNumber?sprintf("%s/%s", $service->docNumber, $service->docDate):$service->transactionCode);
	}

}
