From c233c481b6cfd9e82ce1549b2cabb76a399e3d78 Mon Sep 17 00:00:00 2001 From: Jean-Francois Monfort Date: Thu, 15 Apr 2021 17:33:41 +0200 Subject: [PATCH] WIP Activity Model --- .../AdminActivityPresenceController.php | 23 ++ .../ChillActivityExtension.php | 23 +- .../ChillActivityBundle/Entity/Activity.php | 245 +++++++++++------- .../Entity/ActivityPresence.php | 103 ++++++++ .../Entity/ActivityType.php | 2 - .../Entity/ActivityTypeCategory.php | 19 +- .../Form/ActivityPresenceType.php | 33 +++ .../views/ActivityPresence/edit.html.twig | 12 + .../views/ActivityPresence/index.html.twig | 44 ++++ .../views/ActivityPresence/new.html.twig | 11 + .../ChillActivityBundle/config/routes.yaml | 9 + 11 files changed, 407 insertions(+), 117 deletions(-) create mode 100644 src/Bundle/ChillActivityBundle/Controller/AdminActivityPresenceController.php create mode 100644 src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php create mode 100644 src/Bundle/ChillActivityBundle/Form/ActivityPresenceType.php create mode 100644 src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/edit.html.twig create mode 100644 src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/index.html.twig create mode 100644 src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/new.html.twig diff --git a/src/Bundle/ChillActivityBundle/Controller/AdminActivityPresenceController.php b/src/Bundle/ChillActivityBundle/Controller/AdminActivityPresenceController.php new file mode 100644 index 000000000..a100c3f5d --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Controller/AdminActivityPresenceController.php @@ -0,0 +1,23 @@ +orderBy('e.id', 'ASC'); + } +} diff --git a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php index 3fdf4a726..d459da0e3 100644 --- a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php +++ b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php @@ -137,7 +137,28 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf 'template' => '@ChillActivity/ActivityTypeCategory/edit.html.twig', ] ] - ] + ], + [ + 'class' => \Chill\ActivityBundle\Entity\ActivityPresence::class, + 'name' => 'activity_presence', + 'base_path' => '/admin/activity/presence', + 'form_class' => \Chill\ActivityBundle\Form\ActivityPresenceType::class, + 'controller' => \Chill\ActivityBundle\Controller\AdminActivityPresenceController::class, + 'actions' => [ + 'index' => [ + 'template' => '@ChillActivity/ActivityPresence/index.html.twig', + 'role' => 'ROLE_ADMIN' + ], + 'new' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillActivity/ActivityPresence/new.html.twig', + ], + 'edit' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillActivity/ActivityPresence/edit.html.twig', + ] + ] + ], ] ]); } diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index e96db03db..e1341787f 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -20,13 +20,13 @@ namespace Chill\ActivityBundle\Entity; +use Chill\DocStoreBundle\Entity\Document; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; +use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\ORM\Mapping as ORM; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Center; -use Chill\ActivityBundle\Entity\ActivityReason; -use Chill\ActivityBundle\Entity\ActivityType; use Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\HasScopeInterface; @@ -49,93 +49,98 @@ use Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency; class Activity implements HasCenterInterface, HasScopeInterface { /** - * @var integer - * * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ - private $id; + private ?int $id; /** - * @var User * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") */ - private $user; + private User $user; /** - * @var \DateTime * @ORM\Column(type="datetime") */ - private $date; + private \DateTime $date; /** - * @var \DateTime * @ORM\Column(type="time") */ - private $durationTime; + private \DateTime $durationTime; /** - * @var boolean * @ORM\Column(type="boolean") */ - private $attendee; + private bool $attendee; /** - * @var ActivityReason * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") */ - private $reasons; + private Collection $reasons; /** - * @var ActivityType * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType") */ - private $type; + private ActivityType $type; /** - * @var Scope * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope") */ - private $scope; + private Scope $scope; /** - * @var Person * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person") */ - private $person; + private Person $person; /** * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") */ - private $comment; + private CommentEmbeddable $comment; /** - * Activity constructor. + * @ORM\OneToMany(targetEntity="Chill\PersonBundle\Entity\Person", mappedBy="person") */ + private ArrayCollection $persons; + + /** + * @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="thirdParty") + */ + private ArrayCollection $thirdParties; + + /** + * @ORM\OneToMany(targetEntity="Chill\DocStoreBundle\Entity\Document", mappedBy="document") + */ + private ArrayCollection $documents; + + /** + * @ORM\Column(type="boolean") + */ + private bool $emergency = false; + public function __construct() { $this->reasons = new ArrayCollection(); $this->comment = new CommentEmbeddable(); + $this->persons = new ArrayCollection(); + $this->thirdParties = new ArrayCollection(); + $this->documents = new ArrayCollection(); } /** * Get id - * - * @return integer */ - public function getId() + public function getId(): int { return $this->id; } /** * Set user - * - * @param User $user - * @return Activity */ - public function setUser(User $user) + public function setUser(User $user): self { $this->user = $user; @@ -144,21 +149,16 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get user - * - * @return User */ - public function getUser() + public function getUser(): User { return $this->user; } /** * Set date - * - * @param \DateTime $date - * @return Activity */ - public function setDate($date) + public function setDate(\DateTime $date): self { $this->date = $date; @@ -167,21 +167,16 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get date - * - * @return \DateTime */ - public function getDate() + public function getDate(): \DateTime { return $this->date; } /** * Set durationTime - * - * @param \DateTime $durationTime - * @return Activity */ - public function setDurationTime($durationTime) + public function setDurationTime(\DateTime $durationTime): self { $this->durationTime = $durationTime; @@ -190,21 +185,16 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get durationTime - * - * @return \DateTime */ - public function getDurationTime() + public function getDurationTime(): \DateTime { return $this->durationTime; } /** * Set attendee - * - * @param boolean $attendee - * @return Activity */ - public function setAttendee($attendee) + public function setAttendee(bool $attendee): self { $this->attendee = $attendee; @@ -213,52 +203,39 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get attendee - * - * @return boolean */ - public function getAttendee() + public function getAttendee(): bool { return $this->attendee; } /** * Add a reason - * - * @param ActivityReason $reason - * @return Activity */ - public function addReason(ActivityReason $reason) + public function addReason(ActivityReason $reason): self { $this->reasons[] = $reason; return $this; } - /** - * @param ActivityReason $reason - */ - public function removeReason(ActivityReason $reason) + public function removeReason(ActivityReason $reason): void { $this->reasons->removeElement($reason); } /** * Get reasons - * - * @return Collection */ - public function getReasons() + public function getReasons(): ArrayCollection { return $this->reasons; } /** * Set type - * - * @param ActivityType $type - * @return Activity */ - public function setType(ActivityType $type) + public function setType(ActivityType $type): self { $this->type = $type; @@ -267,21 +244,16 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get type - * - * @return ActivityType */ - public function getType() + public function getType(): ActivityType { return $this->type; } /** * Set scope - * - * @param Scope $scope - * @return Activity */ - public function setScope(Scope $scope) + public function setScope(Scope $scope): self { $this->scope = $scope; @@ -290,21 +262,16 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get scope - * - * @return Scope */ - public function getScope() + public function getScope(): Scope { return $this->scope; } /** * Set person - * - * @param Person $person - * @return Activity */ - public function setPerson(Person $person) + public function setPerson(Person $person): self { $this->person = $person; @@ -313,10 +280,8 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * Get person - * - * @return Person */ - public function getPerson() + public function getPerson(): Person { return $this->person; } @@ -324,28 +289,114 @@ class Activity implements HasCenterInterface, HasScopeInterface /** * get the center * center is extracted from person - * - * @return Center */ - public function getCenter() + public function getCenter(): Center { return $this->person->getCenter(); } - /** - * @return \Chill\MainBundle\Entity\Embeddalbe\CommentEmbeddable - */ - public function getComment() + public function getComment(): CommentEmbeddable { return $this->comment; } - /** - * @param \Chill\MainBundle\Entity\Embeddalbe\CommentEmbeddable $comment - */ - public function setComment($comment) + public function setComment(CommentEmbeddable $comment): self { $this->comment = $comment; + + return $this; + } + + /** + * Add a person to the person list + */ + public function addPerson(Person $person): self + { + $this->persons[] = $person; + + return $this; + } + + public function removePerson(Person $person): void + { + $this->persons->removeElement($person); + } + + public function getPersons(): ArrayCollection + { + return $this->persons; + } + + public function setPersons(ArrayCollection $persons): self + { + $this->persons = $persons; + + return $this; + } + + public function addThirdParty(ThirdParty $thirdParty): self + { + $this->thirdParties[] = $thirdParty; + + return $this; + } + + public function removeThirdParty(ThirdParty $thirdParty): void + { + $this->thirdParties->removeElement($thirdParty); + } + + public function getThirdParties(): ArrayCollection + { + return $this->thirdParties; + } + + public function setThirdParties(ArrayCollection $thirdParties): self + { + $this->thirdParties = $thirdParties; + + return $this; + } + + public function addDocument(Document $document): self + { + $this->documents[] = $document; + + return $this; + } + + public function removeDocument(Document $document): void + { + $this->documents->removeElement($document); + } + + public function getDocuments(): ArrayCollection + { + return $this->documents; + } + + public function setDocuments(ArrayCollection $documents): self + { + $this->documents = $documents; + + return $this; + } + + public function isEmergency(): bool + { + return $this->getEmergency(); + } + + public function getEmergency(): bool + { + return $this->emergency; + } + + public function setEmergency(bool $emergency): self + { + $this->emergency = $emergency; + + return $this; } } diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php new file mode 100644 index 000000000..bfae78878 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php @@ -0,0 +1,103 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\ActivityBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * Class ActivityPresence + * + * @package Chill\ActivityBundle\Entity + * @ORM\Entity() + * @ORM\Table(name="activitytpresence") + * @ORM\HasLifecycleCallbacks() + */ +class ActivityPresence +{ + /** + * @ORM\Id + * @ORM\Column(name="id", type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + */ + private ?int $id; + + /** + * @ORM\Column(type="json") + */ + private array $name = []; + + /** + * @ORM\Column(type="boolean") + */ + private bool $active = true; + + /** + * Get id + */ + public function getId(): int + { + return $this->id; + } + + /** + * Set name + */ + public function setName(array $name): self + { + $this->name = $name; + + return $this; + } + + public function getName(): array + { + return $this->name; + } + + /** + * Get active + * return true if the category type is active. + */ + public function getActive(): bool + { + return $this->active; + } + + /** + * Is active + * return true if the category type is active + */ + public function isActive(): bool + { + return $this->getActive(); + } + + /** + * Set active + * set to true if the category type is active + */ + public function setActive(bool $active): self + { + $this->active = $active; + + return $this; + } +} diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 7f909db3f..1d02f09a0 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -37,8 +37,6 @@ class ActivityType const FIELD_REQUIRED = 2; /** - * @var integer - * * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php index eaf347cb4..4ee84edba 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php @@ -69,25 +69,10 @@ class ActivityTypeCategory /** * Get name - * - * @return array | string */ - public function getName(?string $locale = null) + public function getName(): array { - if ($locale) { - if (isset($this->name[$locale])) { - return $this->name[$locale]; - } else { - foreach ($this->name as $name) { - if (!empty($name)) { - return $name; - } - } - } - return ''; - } else { - return $this->name; - } + return $this->name; } /** diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityPresenceType.php b/src/Bundle/ChillActivityBundle/Form/ActivityPresenceType.php new file mode 100644 index 000000000..42894cc25 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Form/ActivityPresenceType.php @@ -0,0 +1,33 @@ +add('name', TranslatableStringFormType::class) + ->add('active', ChoiceType::class, array( + 'choices' => array( + 'Yes' => true, + 'No' => false + ), + 'expanded' => true + )); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults(array( + 'data_class' => ActivityPresence::class + )); + } +} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/edit.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/edit.html.twig new file mode 100644 index 000000000..16cf893e8 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/edit.html.twig @@ -0,0 +1,12 @@ +{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} + +{% block title %} +{% include('@ChillMain/CRUD/_edit_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} +{% embed '@ChillMain/CRUD/_edit_content.html.twig' %} + {% block content_form_actions_view %}{% endblock %} + {% block content_form_actions_save_and_show %}{% endblock %} +{% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/index.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/index.html.twig new file mode 100644 index 000000000..04f0f5dec --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/index.html.twig @@ -0,0 +1,44 @@ +{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} + +{% block admin_content %} +

{{ 'ActivityPresence list'|trans }}

+ + + + + + + + + + + {% for entity in entities %} + + + + + + {% endfor %} + +
{{ 'Name'|trans }}{{ 'Active'|trans }}{{ 'Actions'|trans }}
{{ entity.name|localize_translatable_string }} + {%- if entity.active -%} + + {%- else -%} + + {%- endif -%} + +
    +
  • + +
  • +
+
+ + +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/new.html.twig new file mode 100644 index 000000000..c95711529 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityPresence/new.html.twig @@ -0,0 +1,11 @@ +{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} + +{% block title %} +{% include('@ChillMain/CRUD/_new_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} +{% embed '@ChillMain/CRUD/_new_content.html.twig' %} + {% block content_form_actions_save_and_show %}{% endblock %} +{% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/config/routes.yaml b/src/Bundle/ChillActivityBundle/config/routes.yaml index 3e1766adf..5403529ae 100644 --- a/src/Bundle/ChillActivityBundle/config/routes.yaml +++ b/src/Bundle/ChillActivityBundle/config/routes.yaml @@ -46,3 +46,12 @@ chill_activity_type_category_admin: admin_activity: order: 2999 label: 'Activity Types Categories' + +chill_activity_presence_admin: + path: /{_locale}/admin/activity/presence + controller: cscrud_activity_presence_controller:index + options: + menus: + admin_activity: + order: 2021 + label: 'Activity Presences'