<?php
namespace Modules\RemoteData\InfoBox;

class View_ExtResSystem 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->name.' ('.$entity->code.')' )
			->setShortTitle(sprintf("%s (%s)", $entity->name, $entity->code))
			->setId(sprintf("%s.%s", __CLASS__, $entity->getId()));


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

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

		// NAME
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['name'], $entity->name) );

		// CODE
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['code'], $entity->code) );

		// ACTIVE
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_Boolean::create($this->lang['extResSystem']['fields']['active'], (bool)$entity->active) );

		// TYPE
		if ($entity->type) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['extResSystem']['fields']['type'], $entity->type) );
		}

		// URL
		if ($entity->url) {
			$cont1->addField( \Engine\RemoteData\InfoBox\Field_Url::create($this->lang['extResSystem']['fields']['url'], ['label' => $entity->url, 'value'=>$entity->url]));
		}

		// MANAGE ACCOUNT
		$cont2 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['extResSystem']['titles']['manageAccount']);
		$output->addContainer($cont2);

		// username
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['extResSystem']['fields']['username'], $entity->username) );

		// token
		$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['extResSystem']['fields']['token'], $entity->token) );

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

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


		return $output;
	}

}


