<?php

namespace Modules\RemoteData\InfoBox;


class View_AutoProcessRule 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['autoProcessRule']['title'], $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['autoProcessRule']['fields']['id'], $entity->getId()) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['general']['fields']['name'], $entity->name) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['cron'], $this->lang['autoProcessRule']['active'][$entity->cronProcess]) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['type'], $this->lang['autoProcessRule']['type'][$entity->type]) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['clientType'], $this->lang['autoProcessRule']['clientType'][$entity->clientType]) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['active'], $this->lang['autoProcessRule']['active'][$entity->active]) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['startTime'], $entity->startTime) );
		$cont1->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['endTime'], $entity->endTime) );


		// RESPONSIBE USERS -----------------------------------------------------------------------
		$cont2 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['autoProcessRule']['cont']['responsible'])->setHidden(true);
		$output->addContainer($cont2);

		$responsibleList = $entity->responsibleUsersList;
		foreach ($responsibleList as $responsible) {
			$respName = null;
			$respName = \Entity\User::select($responsible)->name;
			if ($respName) {
				$cont2->addField( \App\RemoteData\InfoBox\Field_EntityInfoBox::create(null, $respName)->setEntity('user', $responsible) );
			}
		}

		// READABLE DESCRIPTION -------------------------------------------------------------------
		$cont3 = \Engine\RemoteData\InfoBox\Container_Simple::create($this->lang['autoProcessRule']['cont']['description'])->setHidden(true);
		$output->addContainer($cont3);

		$filtersDescr = $entity->object->getDescriptionFilters();
		if ($filtersDescr) {
			$cont3->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['filters'], $filtersDescr) );
		}
		$fieldsDescr = $entity->object->getDescriptionFields();
		if ($fieldsDescr) {
			$cont3->addField( \Engine\RemoteData\InfoBox\Field_String::create($this->lang['autoProcessRule']['fields']['fields'], $fieldsDescr) );
		}

		// 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::createFromIsoDatetime($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::createFromIsoDatetime($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;

	}

}
