<?php
namespace App\Presentation;
use Oberon\Bundle\PresentationBundle\Presentation\BasePresentation;
use Oberon\Presentation\Scope\Scope;
use App\Entity\Project;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraints\DateTime;
class ProjectPresentation extends BasePresentation
{
protected $project;
public function __construct(Project $project, $scope = null, array $data = null, ContainerInterface $container = null)
{
$this->project = $project;
parent::__construct($scope, $data, $container);
}
public function getPresentation()
{
$toolContent = $this->project->getToolContent();
if ($this->scope === Scope::ID) {
return ['id' => (int)$this->project->getId()];
}
if ($this->scope === Scope::BASIC) {
return [
'id' => (int)$this->project->getId(),
'title' => $this->project->getTitle(),
'date' => $this->project->getDate() ? $this->project->getDate()->format(\DateTime::ATOM):null,
'acronym' => $this->project->getAcronym(),
'toolContent' => $toolContent ? [
'id' => $toolContent->getId(),
'versionLabel' => $toolContent->getName(),
'version' => $toolContent->getVersion(),
'versionMinor' => $toolContent->getVersionMinor(),
'versionPatch' => $toolContent->getVersionPatch(),
] : null,
];
}
if ($this->scope === Scope::COMPLETE) {
return [
'id' => (int)$this->project->getId(),
'title' => $this->project->getTitle(),
'date' => $this->project->getDate() ? $this->project->getDate()->format(\DateTime::ATOM):null,
'content' => $this->project->getContent(),
'acronym' => $this->project->getAcronym(),
'identifier' => $this->project->getIdentifier(),
'protocol_version_number' => $this->project->getProtocolVersionNumber(),
'hypothesis' => $this->project->getHypothesis(),
'prerequisites' => $this->project->getPrerequisites(),
'sponsor' => $this->project->getSponsor(),
'name_contact_person' => $this->project->getNameContactPerson(),
'email_contact_person' => $this->project->getEmailContactPerson(),
'team_members' => $this->project->getTeamMembers(),
'hideTutorial' => $this->project->isHideTutorial(),
'toolContent' => $toolContent ? [ // keep in sync with projectscontroller latestToolContent()
'id' => $toolContent->getId(),
'versionLabel' => $toolContent->getName(),
'version' => $toolContent->getVersion(),
'versionMinor' => $toolContent->getVersionMinor(),
'versionPatch' => $toolContent->getVersionPatch(),
'data' => json_decode($toolContent->getData(), true),
] : null,
];
}
return [];
}
}