src/Presentation/ProjectPresentation.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Presentation;
  3. use Oberon\Bundle\PresentationBundle\Presentation\BasePresentation;
  4. use Oberon\Presentation\Scope\Scope;
  5. use App\Entity\Project;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Symfony\Component\Validator\Constraints\DateTime;
  8. class ProjectPresentation extends BasePresentation
  9. {
  10. protected $project;
  11. public function __construct(Project $project, $scope = null, array $data = null, ContainerInterface $container = null)
  12. {
  13. $this->project = $project;
  14. parent::__construct($scope, $data, $container);
  15. }
  16. public function getPresentation()
  17. {
  18. $toolContent = $this->project->getToolContent();
  19. if ($this->scope === Scope::ID) {
  20. return ['id' => (int)$this->project->getId()];
  21. }
  22. if ($this->scope === Scope::BASIC) {
  23. return [
  24. 'id' => (int)$this->project->getId(),
  25. 'title' => $this->project->getTitle(),
  26. 'date' => $this->project->getDate() ? $this->project->getDate()->format(\DateTime::ATOM):null,
  27. 'acronym' => $this->project->getAcronym(),
  28. 'toolContent' => $toolContent ? [
  29. 'id' => $toolContent->getId(),
  30. 'versionLabel' => $toolContent->getName(),
  31. 'version' => $toolContent->getVersion(),
  32. 'versionMinor' => $toolContent->getVersionMinor(),
  33. 'versionPatch' => $toolContent->getVersionPatch(),
  34. ] : null,
  35. ];
  36. }
  37. if ($this->scope === Scope::COMPLETE) {
  38. return [
  39. 'id' => (int)$this->project->getId(),
  40. 'title' => $this->project->getTitle(),
  41. 'date' => $this->project->getDate() ? $this->project->getDate()->format(\DateTime::ATOM):null,
  42. 'content' => $this->project->getContent(),
  43. 'acronym' => $this->project->getAcronym(),
  44. 'identifier' => $this->project->getIdentifier(),
  45. 'protocol_version_number' => $this->project->getProtocolVersionNumber(),
  46. 'hypothesis' => $this->project->getHypothesis(),
  47. 'prerequisites' => $this->project->getPrerequisites(),
  48. 'sponsor' => $this->project->getSponsor(),
  49. 'name_contact_person' => $this->project->getNameContactPerson(),
  50. 'email_contact_person' => $this->project->getEmailContactPerson(),
  51. 'team_members' => $this->project->getTeamMembers(),
  52. 'hideTutorial' => $this->project->isHideTutorial(),
  53. 'toolContent' => $toolContent ? [ // keep in sync with projectscontroller latestToolContent()
  54. 'id' => $toolContent->getId(),
  55. 'versionLabel' => $toolContent->getName(),
  56. 'version' => $toolContent->getVersion(),
  57. 'versionMinor' => $toolContent->getVersionMinor(),
  58. 'versionPatch' => $toolContent->getVersionPatch(),
  59. 'data' => json_decode($toolContent->getData(), true),
  60. ] : null,
  61. ];
  62. }
  63. return [];
  64. }
  65. }