<?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->alertDateTimestamp) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['calendarEvent']['fields']['alertDate'], \Engine\DateTime::createFromIsoDateTime($entity->alertDateTime)) );
		}

		if ($entity->dismissDateTimestamp) {
			$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']['entity'], $this->lang['calendarEvent']['fields']['entityTypeList'][$ent['type']])->setEntity('order', $ent['id']) );
						break;
						case 'service':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['entity'], $this->lang['calendarEvent']['fields']['entityTypeList'][$ent['type']])->setEntity('service', $ent['id']) );
						break;
						case 'invoice':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['entity'],$this->lang['calendarEvent']['fields']['entityTypeList'][$ent['type']])->setEntity('invoice', $ent['id']) );
						break;
						case 'corporate':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['entity'], $this->lang['calendarEvent']['fields']['entityTypeList'][$ent['type']])->setEntity('corporate', $ent['id']) );
						break;
						case 'corporateContact':
							$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['calendarEvent']['fields']['entity'], $this->lang['calendarEvent']['fields']['entityTypeList'][$ent['type']])->setEntity('corporateContact', $ent['id']) );
						break;
						default:
							$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['calendarEvent']['fields']['entity'], $ent['type']) );
					}
				}
			}
		}

		// 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;
	}
}
