WIP Activity Model

This commit is contained in:
Jean-Francois Monfort 2021-04-15 17:33:41 +02:00
parent 8acd852070
commit c233c481b6
11 changed files with 407 additions and 117 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace Chill\ActivityBundle\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Chill\MainBundle\Pagination\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
class AdminActivityPresenceController extends CRUDController
{
/**
* @param string $action
* @param \Doctrine\ORM\QueryBuilder|mixed $query
* @param Request $request
* @param PaginatorInterface $paginator
* @return \Doctrine\ORM\QueryBuilder|mixed
*/
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
{
/** @var \Doctrine\ORM\QueryBuilder $query */
return $query->orderBy('e.id', 'ASC');
}
}

View File

@ -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',
]
]
],
]
]);
}

View File

@ -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;
}
}

View File

@ -0,0 +1,103 @@
<?php
/*
*
* Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -37,8 +37,6 @@ class ActivityType
const FIELD_REQUIRED = 2;
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")

View File

@ -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;
}
/**

View File

@ -0,0 +1,33 @@
<?php
namespace Chill\ActivityBundle\Form;
use Chill\ActivityBundle\Entity\ActivityPresence;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class ActivityPresenceType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->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
));
}
}

View File

@ -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 %}

View File

@ -0,0 +1,44 @@
{% extends "@ChillActivity/Admin/layout_activity.html.twig" %}
{% block admin_content %}
<h1>{{ 'ActivityPresence list'|trans }}</h1>
<table class="records_list">
<thead>
<tr>
<th>{{ 'Name'|trans }}</th>
<th>{{ 'Active'|trans }}</th>
<th>{{ 'Actions'|trans }}</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>{{ entity.name|localize_translatable_string }}</td>
<td style="text-align:center;">
{%- if entity.active -%}
<i class="fa fa-check-square-o"></i>
{%- else -%}
<i class="fa fa-square-o"></i>
{%- endif -%}
</td>
<td>
<ul class="record_actions">
<li>
<a href="{{ path('chill_crud_activity_presence_edit', { 'id': entity.id }) }}" class="sc-button bt-edit" title="{{ 'edit'|trans }}"></a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('chill_crud_activity_presence_new') }}" class="sc-button bt-create">
{{ 'Create a new activity presence'|trans }}
</a>
</li>
</ul>
{% endblock %}

View File

@ -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 %}

View File

@ -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'