mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-04 03:08:25 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			558 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			558 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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 Chill\DocStoreBundle\Entity\Document;
 | 
						|
use Chill\DocStoreBundle\Entity\StoredObject;
 | 
						|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
 | 
						|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
 | 
						|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
 | 
						|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
 | 
						|
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\PersonBundle\Entity\Person;
 | 
						|
use Chill\MainBundle\Entity\HasCenterInterface;
 | 
						|
use Chill\MainBundle\Entity\HasScopeInterface;
 | 
						|
use Doctrine\Common\Collections\Collection;
 | 
						|
use Doctrine\Common\Collections\ArrayCollection;
 | 
						|
use Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency;
 | 
						|
use Symfony\Component\Serializer\Annotation\Groups;
 | 
						|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
 | 
						|
 | 
						|
/**
 | 
						|
 * Class Activity
 | 
						|
 *
 | 
						|
 * @package Chill\ActivityBundle\Entity
 | 
						|
 * @ORM\Entity(repositoryClass="Chill\ActivityBundle\Repository\ActivityRepository")
 | 
						|
 * @ORM\Table(name="activity")
 | 
						|
 * @ORM\HasLifecycleCallbacks()
 | 
						|
 * @DiscriminatorMap(typeProperty="type", mapping={
 | 
						|
 *  "activity"=Activity::class
 | 
						|
 *  })
 | 
						|
 */
 | 
						|
 | 
						|
/*
 | 
						|
 * TODO : revoir
 | 
						|
 * @UserCircleConsistency(
 | 
						|
 *      "CHILL_ACTIVITY_SEE_DETAILS",
 | 
						|
 *      getUserFunction="getUser",
 | 
						|
 *      path="scope")
 | 
						|
 */
 | 
						|
 | 
						|
class Activity implements HasCenterInterface, HasScopeInterface
 | 
						|
{
 | 
						|
    const SENTRECEIVED_SENT = 'sent';
 | 
						|
    const SENTRECEIVED_RECEIVED = 'received';
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Id
 | 
						|
     * @ORM\Column(name="id", type="integer")
 | 
						|
     * @ORM\GeneratedValue(strategy="AUTO")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private ?int $id = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
 | 
						|
     */
 | 
						|
    private User $user;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Column(type="datetime")
 | 
						|
     */
 | 
						|
    private \DateTime $date;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Column(type="time", nullable=true)
 | 
						|
     */
 | 
						|
    private ?\DateTime $durationTime = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Column(type="time", nullable=true)
 | 
						|
     */
 | 
						|
    private ?\DateTime $travelTime = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence")
 | 
						|
     */
 | 
						|
    private ?ActivityPresence $attendee = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason")
 | 
						|
     */
 | 
						|
    private Collection $reasons;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialIssue")
 | 
						|
     * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private Collection $socialIssues;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction")
 | 
						|
     * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private Collection $socialActions;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType")
 | 
						|
     */
 | 
						|
    private ActivityType $type;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
 | 
						|
     */
 | 
						|
    private ?Scope $scope = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person")
 | 
						|
     */
 | 
						|
    private ?Person $person = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private ?AccompanyingPeriod $accompanyingPeriod = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
 | 
						|
     */
 | 
						|
    private CommentEmbeddable $comment;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\Person")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private ?Collection $persons = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private ?Collection $thirdParties = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\DocStoreBundle\Entity\StoredObject")
 | 
						|
     */
 | 
						|
    private Collection $documents;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User")
 | 
						|
     * @Groups({"read"})
 | 
						|
     */
 | 
						|
    private ?Collection $users = null;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Column(type="boolean", options={"default"=false})
 | 
						|
     */
 | 
						|
    private bool $emergency = false;
 | 
						|
 | 
						|
    /**
 | 
						|
     * @ORM\Column(type="string", options={"default"=""})
 | 
						|
     */
 | 
						|
    private string $sentReceived = '';
 | 
						|
 | 
						|
    public function __construct()
 | 
						|
    {
 | 
						|
        $this->reasons = new ArrayCollection();
 | 
						|
        $this->comment = new CommentEmbeddable();
 | 
						|
        $this->persons = new ArrayCollection();
 | 
						|
        $this->thirdParties = new ArrayCollection();
 | 
						|
        $this->documents = new ArrayCollection();
 | 
						|
        $this->users = new ArrayCollection();
 | 
						|
        $this->socialIssues = new ArrayCollection();
 | 
						|
        $this->socialActions = new ArrayCollection();
 | 
						|
    }
 | 
						|
 | 
						|
    public function getId(): ?int
 | 
						|
    {
 | 
						|
        return $this->id;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setUser(User $user): self
 | 
						|
    {
 | 
						|
        $this->user = $user;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getUser(): User
 | 
						|
    {
 | 
						|
        return $this->user;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setDate(\DateTime $date): self
 | 
						|
    {
 | 
						|
        $this->date = $date;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getDate(): \DateTime
 | 
						|
    {
 | 
						|
        return $this->date;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setDurationTime(?\DateTime $durationTime): self
 | 
						|
    {
 | 
						|
        $this->durationTime = $durationTime;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getDurationTime(): ?\DateTime
 | 
						|
    {
 | 
						|
        return $this->durationTime;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setTravelTime(\DateTime $travelTime): self
 | 
						|
    {
 | 
						|
        $this->travelTime = $travelTime;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getTravelTime(): ?\DateTime
 | 
						|
    {
 | 
						|
        return $this->travelTime;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setAttendee(ActivityPresence $attendee): self
 | 
						|
    {
 | 
						|
        $this->attendee = $attendee;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getAttendee(): ?ActivityPresence
 | 
						|
    {
 | 
						|
        return $this->attendee;
 | 
						|
    }
 | 
						|
 | 
						|
    public function addReason(ActivityReason $reason): self
 | 
						|
    {
 | 
						|
        $this->reasons->add($reason);
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function removeReason(ActivityReason $reason): void
 | 
						|
    {
 | 
						|
        $this->reasons->removeElement($reason);
 | 
						|
    }
 | 
						|
 | 
						|
    public function getReasons(): Collection
 | 
						|
    {
 | 
						|
        return $this->reasons;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setReasons(?ArrayCollection $reasons): self
 | 
						|
    {
 | 
						|
        $this->reasons = $reasons;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getSocialIssues(): Collection
 | 
						|
    {
 | 
						|
        return $this->socialIssues;
 | 
						|
    }
 | 
						|
 | 
						|
    public function addSocialIssue(SocialIssue $socialIssue): self
 | 
						|
    {
 | 
						|
        if (!$this->socialIssues->contains($socialIssue)) {
 | 
						|
            $this->socialIssues[] = $socialIssue;
 | 
						|
        }
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function removeSocialIssue(SocialIssue $socialIssue): self
 | 
						|
    {
 | 
						|
        $this->socialIssues->removeElement($socialIssue);
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getSocialActions(): Collection
 | 
						|
    {
 | 
						|
        return $this->socialActions;
 | 
						|
    }
 | 
						|
 | 
						|
    public function addSocialAction(SocialAction $socialAction): self
 | 
						|
    {
 | 
						|
        if (!$this->socialActions->contains($socialAction)) {
 | 
						|
            $this->socialActions[] = $socialAction;
 | 
						|
        }
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function removeSocialAction(SocialAction $socialAction): self
 | 
						|
    {
 | 
						|
        $this->socialActions->removeElement($socialAction);
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
    public function setType(ActivityType $type): self
 | 
						|
    {
 | 
						|
        $this->type = $type;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getType(): ActivityType
 | 
						|
    {
 | 
						|
        return $this->type;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setScope(Scope $scope): self
 | 
						|
    {
 | 
						|
        $this->scope = $scope;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getScope(): ?Scope
 | 
						|
    {
 | 
						|
        return $this->scope;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setPerson(?Person $person): self
 | 
						|
    {
 | 
						|
        $this->person = $person;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getPerson(): ?Person
 | 
						|
    {
 | 
						|
        return $this->person;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getAccompanyingPeriod(): ?AccompanyingPeriod
 | 
						|
    {
 | 
						|
        return $this->accompanyingPeriod;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
 | 
						|
    {
 | 
						|
        $this->accompanyingPeriod = $accompanyingPeriod;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * get the center
 | 
						|
     * center is extracted from person
 | 
						|
     */
 | 
						|
    public function getCenter(): ?Center
 | 
						|
    {
 | 
						|
        if ($this->person instanceof Person) {
 | 
						|
            return $this->person->getCenter();
 | 
						|
        }
 | 
						|
 | 
						|
        return null;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getComment(): CommentEmbeddable
 | 
						|
    {
 | 
						|
        return $this->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
 | 
						|
    {
 | 
						|
        if (null !== $person) {
 | 
						|
            $this->persons[] = $person;
 | 
						|
        }
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function removePerson(Person $person): void
 | 
						|
    {
 | 
						|
        $this->persons->removeElement($person);
 | 
						|
    }
 | 
						|
 | 
						|
    public function getPersons(): Collection
 | 
						|
    {
 | 
						|
        return $this->persons;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getPersonsAssociated(): array 
 | 
						|
    {
 | 
						|
        if (null !== $this->accompanyingPeriod) {
 | 
						|
            $personsAssociated = [];
 | 
						|
            foreach ($this->accompanyingPeriod->getParticipations() as $participation) {
 | 
						|
                if ($this->persons->contains($participation->getPerson())) {
 | 
						|
                    $personsAssociated[] = $participation->getPerson();
 | 
						|
                }
 | 
						|
            }
 | 
						|
            return $personsAssociated; 
 | 
						|
        }
 | 
						|
        return [];
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getPersonsNotAssociated(): array
 | 
						|
    {
 | 
						|
        if (null !== $this->accompanyingPeriod) {
 | 
						|
            $personsNotAssociated = [];
 | 
						|
            foreach ($this->persons as $person) {
 | 
						|
                if (!in_array($person, $this->getPersonsAssociated())) {
 | 
						|
                     $personsNotAssociated[] = $person;
 | 
						|
                }
 | 
						|
            }
 | 
						|
            return $personsNotAssociated;
 | 
						|
        }
 | 
						|
        return [];
 | 
						|
    }    
 | 
						|
 | 
						|
    public function setPersons(?Collection $persons): self
 | 
						|
    {
 | 
						|
        $this->persons = $persons;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function addThirdParty(?ThirdParty $thirdParty): self
 | 
						|
    {
 | 
						|
        if (null !== $thirdParty) {
 | 
						|
           $this->thirdParties[] = $thirdParty;
 | 
						|
        }
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function removeThirdParty(ThirdParty $thirdParty): void
 | 
						|
    {
 | 
						|
        $this->thirdParties->removeElement($thirdParty);
 | 
						|
    }
 | 
						|
 | 
						|
    public function getThirdParties(): Collection
 | 
						|
    {
 | 
						|
        return $this->thirdParties;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setThirdParties(?Collection $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(): Collection
 | 
						|
    {
 | 
						|
        return $this->documents;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setDocuments(Collection $documents): self
 | 
						|
    {
 | 
						|
        $this->documents = $documents;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function addUser(?User $user): self
 | 
						|
    {
 | 
						|
        if (null !== $user) {
 | 
						|
            $this->users[] = $user;
 | 
						|
        }
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    public function removeUser(User $user): void
 | 
						|
    {
 | 
						|
        $this->users->removeElement($user);
 | 
						|
    }
 | 
						|
 | 
						|
    public function getUsers(): Collection
 | 
						|
    {
 | 
						|
        return $this->users;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setUsers(?Collection $users): self
 | 
						|
    {
 | 
						|
        $this->users = $users;
 | 
						|
 | 
						|
        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;
 | 
						|
    }
 | 
						|
 | 
						|
    public function getSentReceived(): string
 | 
						|
    {
 | 
						|
        return $this->sentReceived;
 | 
						|
    }
 | 
						|
 | 
						|
    public function setSentReceived(?string $sentReceived): self
 | 
						|
    {
 | 
						|
        $this->sentReceived = (string) $sentReceived;
 | 
						|
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
}
 |