<?php

namespace Modules\RemoteData\InfoBox;


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


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

		$cont2 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['documentTemplate']['titles']['access'])->setHidden(true);
		$output->addContainer($cont2);

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


		// BASIC INFO -----------------------------------------------------------------------------
		$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['documentTemplate']['fields']['name'], $entity->name));
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['documentTemplate']['fields']['status'], $this->lang['documentTemplate']['status'][$entity->active]));
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['documentTemplate']['fields']['docType'], \App\Config\IssueDocuments::getInstance()->getDocTypeName($entity->docType)));
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['documentTemplate']['fields']['format'], strtoupper($entity->format)));
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['documentTemplate']['fields']['fileName'], $entity->fileName));
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['documentTemplate']['fields']['extension'], $entity->extension));

		// ACCESS
		if ($entity->allUsers == 1) {
			$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create(null, $this->lang['documentTemplate']['fields']['allUsers']));
		}
		elseif ($entity->validUsersList) {
			foreach ($entity->validUsersList as $user) {
				$cont2->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create(null,\Entity\User::select($user)->name)->setEntity('user', $user) );
			}
		}
		else {
			$cont2->addField( \Engine\RemoteData\InfoBox\Field_String::create(null, $this->lang['documentTemplate']['fields']['noUsers']));
		}

		// UPDATE INFO ----------------------------------------------------------------------------
		$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;
	}

}