<?php
namespace Modules\RemoteData\InfoBox;


class View_CalendarEvent extends \App\Mvc\View_RemoteDataInfoBoxEntityAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_RemoteDataInfoBoxEntityAbstract::getEntityRemoteDetails()
	 */
	protected function getEntityRemoteDetails(\App\Entity\SelectAbstract $entity)
	{

		// the output object
		$output = \Engine\RemoteData\InfoBox\Container_Main::create( $entity->title )
			->setShortTitle($entity->title)
			->setId(sprintf("%s.%s", __CLASS__, $entity->getId()));


		// BASIC INFO -----------------------------------------------------------------------------
		$cont1 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['general']['titles']['general']);
		$output->addContainer($cont1);

		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['id'], $entity->getId()) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['title'], $entity->title) );

		if ($entity->description) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['description'], $entity->description) );
		}
		if ($entity->location) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['location'], $entity->location) );
		}
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['access'], $this->lang['calendarEvent']['fields']['accessVals'][$entity->access]) );

		if ($entity->allDay) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_Date::create($this->lang['calendarEvent']['fields']['startDate'], \Engine\DateTime::createFromIsoDateTime($entity->startDateTime)) );
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_Date::create($this->lang['calendarEvent']['fields']['endDate'], \Engine\DateTime::createFromIsoDateTime($entity->endDateTime)) );
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_Boolean::create($this->lang['calendarEvent']['fields']['allDay'], (bool)$entity->allDay) );
		}
		else {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['calendarEvent']['fields']['startDate'], \Engine\DateTime::createFromIsoDateTime($entity->startDateTime)) );
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['calendarEvent']['fields']['endDate'], \Engine\DateTime::createFromIsoDateTime($entity->endDateTime)) );
		}

		if ($entity->alertDateTime) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['calendarEvent']['fields']['alertDate'], \Engine\DateTime::createFromIsoDateTime($entity->alertDateTime)) );
		}

		if ($entity->dismissDateTime) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['calendarEvent']['fields']['dismissDate'], \Engine\DateTime::createFromIsoDateTime($entity->dismissDateTime)) );
		}

		if ($entity->mailStatus) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['emailSts'], $this->lang['calendarEvent']['fields']['emailStsVals'][$entity->mailStatus]) );
		}

		if ($entity->entities) {
			foreach ($entity->entities as $ent) {
				if ($ent['id']) {
					switch ($ent['type']) {
						case 'order':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], \Entity\Order::select($ent['id'])->convertedId)->setEntity('order', $ent['id']) );
						break;
						case 'service':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], '#'.$ent['id'])->setEntity('service', $ent['id']) );
						break;
						case 'invoice':
							$invoiceEnt = \Entity\Invoice::select($ent['id']);
							if ($invoiceEnt->issueTime) {
								$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], $invoiceEnt->invoiceNumber."/".\Engine\DateTime::isoToStd($invoiceEnt->invoiceDate))->setEntity('invoice', $ent['id']) );
							}
							else {
								$cont1->addField( \Engine\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], '#'.$ent['id'])->setEntity('invoice', $ent['id']) );
							}
						break;
						case 'corporate':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], \Entity\Corporate::select($ent['id'])->alias)->setEntity('corporate', $ent['id']) );
						break;
						case 'importedService':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], \Entity\ImportedService::select($ent['id'])->idServiceExtSys)->setEntity('importedService', $ent['id']) );
							break;
						case 'corporateContact':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['reference'], '#'.$ent['id'])->setEntity('corporateContact', $ent['id']) );
							break;
						default:
							$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['reference'], $this->lang['calendarEvent']['fields']['entityTypeList'][$ent['type']] . " - #" . $ent['id'] ) );
					}
				}
			}
		}

		// UPDATE INFO
		$cont6 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['general']['titles']['updates'])->setHidden(true);
		$output->addContainer($cont6);

		$cont6->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['addTime'], \Engine\DateTime::createFromTimestamp($entity->addTime)) );
		$cont6->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['addUser'], $entity->addUser->name)->setEntity('user', $entity->idAddUser) );
		$cont6->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['general']['fields']['updateTime'], \Engine\DateTime::createFromTimestamp($entity->lastUpdateTime)) );
		$cont6->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['general']['fields']['updateUser'], $entity->updateUser->name)->setEntity('user', $entity->idUpdateUser) );
		if ($entity->updatesCount) {
			$cont6->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['updatesCount'], $entity->updatesCount) );
		}
		return $output;
	}
}
