<?php

namespace Modules\RemoteData\InfoBox;

class View_CorporateContact 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($this->lang['corporateContact']['title'])
			->setShortTitle($entity->getId())
			->setId(sprintf("%s.%s", __CLASS__, $entity->getId()));

		// corporate contact edit
		$icon = \Engine\RemoteData\InfoBox\Icon\Icon::create('edit');
		$icon->setTooltip($this->lang['corporateContact']['option']['update']);
		$icon->setJsCallback("corporateContactUpdate('{$entity->getId()}');return false;");
		$output->addIcon($icon);

		// 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( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['corporateContact']['fields']['idCorporate'], \Entity\Corporate::select($entity->idCorporate)->alias)->setEntity('corporate', $entity->idCorporate) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['corporateContact']['fields']['contactType'], $this->lang['corporateContact']['fields'][$entity->contactType]));

		if ($entity->idContactPerson) {
			$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['corporateContact']['fields']['contactPerson'], $entity->contactPerson->name)->setEntity('contactPerson', $entity->idContactPerson) );
		}
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_DateTime::create($this->lang['corporateContact']['fields']['contactDate'], \Engine\DateTime::createFromIsoDatetime($entity->contactDatetime)) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['corporateContact']['fields']['duration'], $entity->duration) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['corporateContact']['fields']['topics'], $entity->topics) );
		$cont1->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create($this->lang['corporateContact']['fields']['user'], $entity->user->name)->setEntity('user', $entity->idUser) );

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

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

		return $output;

	}

}
