Prestataire.php 17.6 KB
Newer Older
Julien Jorry committed
1 2 3 4 5 6
<?php

namespace App\Entity;

use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\HasCompteEntity;
7
use App\Entity\EntityTrait\HasEcompteEntity;
Julien Jorry committed
8
use App\Entity\Groupeprestataire;
Julien Jorry committed
9
use Doctrine\Common\Collections\ArrayCollection;
Julien Jorry committed
10
use Doctrine\Common\Collections\Collection;
Julien Jorry committed
11 12
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
13
use Gedmo\Mapping\Annotation\Slug;
14
use Gedmo\Timestampable\Traits\TimestampableEntity;
Julien Jorry committed
15
use Symfony\Component\Validator\Constraints as Assert;
16 17
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
Julien Jorry committed
18 19

/**
20
 * @ApiResource(
21 22 23 24 25 26 27 28 29
 *     attributes={"security"="is_granted('ROLE_ADMIN_PRESTATAIRE_GERER_VIEW') or is_granted('ROLE_API')"},
 *     collectionOperations={
 *         "get"={"security"="is_granted('ROLE_ADMIN_PRESTATAIRE_GERER_LIST') or is_granted('ROLE_API')"},
 *         "post"={"security"="is_granted('ROLE_ADMIN_PRESTATAIRE_GERER_EDIT')"}
 *     },
 *     itemOperations={
 *         "get"={"security"="is_granted('ROLE_ADMIN_PRESTATAIRE_GERER_VIEW') or is_granted('ROLE_API')"},
 *         "put"={"security"="is_granted('ROLE_ADMIN_PRESTATAIRE_GERER_EDIT')"},
 *     },
30 31 32
 *     normalizationContext={"groups"={"read"}},
 *     denormalizationContext={"groups"={"write"}}
 * )
33
 * @ORM\Entity(repositoryClass="App\Repository\PrestataireRepository")
Julien Jorry committed
34 35 36 37 38
 * @ORM\Table(name="prestataire")
 */
class Prestataire
{
    use EnablableEntityTrait,
39
        TimestampableEntity,
40 41
        HasCompteEntity,
        HasEcompteEntity;
Julien Jorry committed
42 43 44 45 46 47 48

    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\Column(name="id", type="integer")
     * @ORM\GeneratedValue
49
     * @Groups({"read"})
Julien Jorry committed
50 51 52 53 54 55 56
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(name="raison", type="string", length=100)
57
     * @Groups({"read", "write"})
Julien Jorry committed
58 59 60
     */
    private $raison;

61 62 63 64
    /**
     * @var string|null
     *
     * @ORM\Column(type="text", nullable=true)
65
     * @Groups({"read", "write"})
66 67 68
     */
    private $description;

69 70 71 72 73
    /**
     * @var string|null
     *
     * @Gedmo\Slug(fields={"raison"})
     * @ORM\Column(length=100, unique=true)
74
     * @Groups({"read"})
75 76 77
     */
    protected $slug;

Julien Jorry committed
78 79 80
    /**
     * @var string
     *
81
     * @ORM\Column(name="metier", type="string", length=100, nullable=true)
82
     * @Groups({"read", "write"})
Julien Jorry committed
83 84 85 86 87 88 89
     */
    private $metier;

    /**
     * @var null|string
     *
     * @ORM\Column(name="statut", type="string", length=50, nullable=true)
90
     * @Groups({"read", "write"})
Julien Jorry committed
91 92 93 94 95 96 97
     */
    private $statut;

    /**
     * @var null|string
     *
     * @ORM\Column(name="responsable", type="string", length=200, nullable=true)
98
     * @Groups({"read", "write"})
Julien Jorry committed
99 100 101 102
     */
    private $responsable;

    /**
Julien Jorry committed
103
     * @ORM\Column(name="iban", type="string", length=100, nullable=true)
Julien Jorry committed
104
     * Assert\Iban(message="L'IBAN(International Bank Account Number) est invalide.")
105
     * @Groups({"read", "write"})
Julien Jorry committed
106 107 108 109 110 111 112
     */
    private $iban;

    /**
     * @var string
     *
     * @ORM\Column(name="siret", type="string", length=50)
113
     * @Groups({"read", "write"})
Julien Jorry committed
114 115 116 117 118 119 120
     */
    private $siret;

    /**
     * @var null|string
     *
     * @ORM\Column(name="web", type="string", length=255, nullable=true)
Julien Jorry committed
121
     * @Assert\Url(message = "L'adresse : '{{ value }}' est invalide.")
122
     * @Groups({"read", "write"})
Julien Jorry committed
123 124 125 126
     */
    private $web;

    /**
Julien Jorry committed
127 128
     * Le prestataire peut recevoir des cotisations (En règle générale, l'association gérant la monnaie locale)
     * Ce prestataire est normalement crée à l'installation du kohinos
Julien Jorry committed
129 130
     * @var bool
     *
Julien Jorry committed
131
     * @ORM\Column(name="mlc", type="boolean", nullable=false, options={"default" : false})
132
     * @Groups({"read"})
Julien Jorry committed
133
     */
Julien Jorry committed
134
    private $mlc = false;
Julien Jorry committed
135

Julien Jorry committed
136 137 138 139
    /**
     * @var null|string (champ libre)
     *
     * @ORM\Column(name="horaires", type="string", length=255, nullable=true)
140
     * @Groups({"read", "write"})
Julien Jorry committed
141 142 143
     */
    private $horaires;

Julien Jorry committed
144 145 146 147
    /**
     * @var TypePrestataire
     *
     * @ORM\ManyToOne(targetEntity="TypePrestataire", cascade={"persist"}, inversedBy="prestataires")
148
     * @Groups({"read", "write"})
Julien Jorry committed
149 150 151 152
     */
    private $typeprestataire;

    /**
Julien Jorry committed
153 154
     * @var ArrayCollection|Rubrique[]
     * @ORM\ManyToMany(targetEntity="Rubrique", mappedBy="prestataires", cascade={"persist"}, fetch="EXTRA_LAZY")
155
     * @Groups({"read", "write"})
Julien Jorry committed
156
     */
Julien Jorry committed
157 158 159 160 161
    private $rubriques;

    /**
    * @var \Application\Sonata\MediaBundle\Entity\Media
    * @ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"}, fetch="LAZY")
162
    * @ORM\JoinColumn(name="media_id", referencedColumnName="id", nullable=true)
163
    * @Groups({"read", "write"})
Julien Jorry committed
164 165
    */
    protected $media;
Julien Jorry committed
166

Julien Jorry committed
167 168 169
    /**
     * @var ArrayCollection|GeolocPrestataire[]
     * @ORM\OneToMany(targetEntity="GeolocPrestataire", cascade={"persist"}, mappedBy="prestataire")
170
     * @Groups({"read", "write"})
Julien Jorry committed
171 172 173 174 175 176
     */
    private $geolocs;

    /**
     * @var ArrayCollection|ContactPrestataire[]
     * @ORM\OneToMany(targetEntity="ContactPrestataire", cascade={"persist"}, mappedBy="prestataire")
177
     * @Groups({"read", "write"})
Julien Jorry committed
178 179 180
     */
    private $contacts;

181
    /**
Julien Jorry committed
182 183 184
     * @var ArrayCollection|User[]
     *
     * @ORM\ManyToMany(targetEntity="User", inversedBy="prestataires", cascade={"persist"})
185
     * @Groups({"read", "write"})
Julien Jorry committed
186 187
     */
    protected $users;
Julien Jorry committed
188 189

    /**
190
     * @var Groupe $groupe
Julien Jorry committed
191
     *
Julien Jorry committed
192
     * @ORM\ManyToOne(targetEntity="Groupe", inversedBy="prestataires", cascade={"persist"})
193
     * @Assert\NotBlank
194
     * @Groups({"read", "write"})
Julien Jorry committed
195
     */
196
    private $groupe;
Julien Jorry committed
197 198

    /**
Julien Jorry committed
199 200 201
     * AMAP / Marché
     * @var ArrayCollection|Groupeprestataire[]
     * @ORM\ManyToMany(targetEntity="Groupeprestataire", cascade={"persist"}, mappedBy="prestataires")
Julien Jorry committed
202
     * @ORM\JoinTable(name="groupes_prestataires")
203
     * @Groups({"read", "write"})
Julien Jorry committed
204 205
     */
    private $groupeprestataires;
Julien Jorry committed
206 207
    
    /**
208
     * EtatPrestataire $etats
Julien Jorry committed
209 210
     * @var ArrayCollection|EtatPrestataire[]
     * @ORM\ManyToMany(targetEntity="EtatPrestataire", cascade={"persist"}, mappedBy="prestataires", fetch="EXTRA_LAZY")
211
     * @Groups({"read", "write"})
Julien Jorry committed
212 213
     */
    private $etats;
Julien Jorry committed
214

215 216 217 218 219 220 221 222
    /**
     * Taux de reconversion propre au prestataire
     * @var float
     * @ORM\Column(name="tauxreconversion", type="decimal", precision=7, scale=2, nullable=true)
     * @Groups({"read", "write"})
     */
    protected $tauxreconversion;

Julien Jorry committed
223 224 225 226
    public function __construct()
    {
        $this->users = new ArrayCollection();
        $this->groupeprestataires = new ArrayCollection();
Julien Jorry committed
227 228
        $this->geolocs = new ArrayCollection();
        $this->etats = new ArrayCollection();
229
        $this->rubriques = new ArrayCollection();
Julien Jorry committed
230 231 232 233 234 235 236 237 238 239 240 241 242
    }

    /**
     * @return mixed
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @return string
     */
243
    public function getRaison(): ?string
Julien Jorry committed
244 245 246 247 248 249 250 251
    {
        return $this->raison;
    }

    /**
     * @param string $raison
     * @return Prestataire
     */
Julien Jorry committed
252
    public function setRaison(string $raison): self
Julien Jorry committed
253 254 255 256 257
    {
        $this->raison = $raison;
        return $this;
    }

258 259 260 261 262
    public function getSlug(): ?string
    {
        return $this->slug;
    }

Julien Jorry committed
263
    public function setSlug(?string $slug): self
264 265 266 267 268
    {
        $this->slug = $slug;
        return $this;
    }

269 270 271 272 273 274 275 276 277 278 279
    public function setDescription(?string $description)
    {
        $this->description = $description;
        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

Julien Jorry committed
280 281 282
    /**
     * @return string
     */
283
    public function getMetier(): ?string
Julien Jorry committed
284 285 286 287 288 289 290 291
    {
        return $this->metier;
    }

    /**
     * @param string $metier
     * @return Prestataire
     */
Julien Jorry committed
292
    public function setMetier(string $metier): self
Julien Jorry committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
    {
        $this->metier = $metier;
        return $this;
    }

    /**
     * @return null|string
     */
    public function getStatut(): ?string
    {
        return $this->statut;
    }

    /**
     * @param null|string $statut
     * @return Prestataire
     */
Julien Jorry committed
310
    public function setStatut(?string $statut): self
Julien Jorry committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
    {
        $this->statut = $statut;
        return $this;
    }

    /**
     * @return null|string
     */
    public function getResponsable(): ?string
    {
        return $this->responsable;
    }

    /**
     * @param null|string $responsable
     * @return Prestataire
     */
Julien Jorry committed
328
    public function setResponsable(?string $responsable): self
Julien Jorry committed
329 330 331 332 333 334 335 336
    {
        $this->responsable = $responsable;
        return $this;
    }

    /**
     * @return string
     */
337
    public function getIban(): ?string
Julien Jorry committed
338 339 340 341 342 343 344 345
    {
        return $this->iban;
    }

    /**
     * @param string $iban
     * @return Prestataire
     */
Julien Jorry committed
346
    public function setIban(?string $iban): self
Julien Jorry committed
347 348 349 350 351 352 353 354
    {
        $this->iban = $iban;
        return $this;
    }

    /**
     * @return string
     */
355
    public function getSiret(): ?string
Julien Jorry committed
356 357 358 359 360 361 362 363
    {
        return $this->siret;
    }

    /**
     * @param string $siret
     * @return Prestataire
     */
Julien Jorry committed
364
    public function setSiret(?string $siret): self
Julien Jorry committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    {
        $this->siret = $siret;
        return $this;
    }

    /**
     * @return null|string
     */
    public function getWeb(): ?string
    {
        return $this->web;
    }

    /**
     * @param null|string $web
     * @return Prestataire
     */
Julien Jorry committed
382
    public function setWeb(?string $web): self
Julien Jorry committed
383 384 385 386 387 388 389 390
    {
        $this->web = $web;
        return $this;
    }

    /**
     * @return bool
     */
Julien Jorry committed
391
    public function isMlc(): bool
Julien Jorry committed
392
    {
Julien Jorry committed
393
        return $this->mlc;
Julien Jorry committed
394 395 396
    }

    /**
Julien Jorry committed
397
     * @param bool $mlc
Julien Jorry committed
398 399
     * @return Prestataire
     */
Julien Jorry committed
400
    public function setMlc(bool $mlc): self
Julien Jorry committed
401
    {
Julien Jorry committed
402
        $this->mlc = $mlc;
Julien Jorry committed
403 404 405
        return $this;
    }

Julien Jorry committed
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    /**
     * getgeolocs
     * @return ArrayCollection geoloc
     */
    public function getGeolocs()
    {
        return $this->geolocs;
    }

    /**
     * setGeolocs
     * @param [type] $geolocs [description]
     */
    public function setGeolocs($geolocs): self
    {
        $this->geolocs = $geolocs;
        return $this;
    }
    
    /**
426
     * @param GeolocPrestataire $geoloc
Julien Jorry committed
427 428
     * @return $this
     */
429
    public function addGeoloc(GeolocPrestataire $geoloc): self
Julien Jorry committed
430 431 432 433 434 435 436 437 438
    {
        if (!$this->geolocs->contains($geoloc)) {
            $this->geolocs[] = $geoloc;
            $geoloc->setPrestataire($this);
        }
        return $this;
    }

    /**
439
     * @param GeolocPrestataire $geoloc
Julien Jorry committed
440 441
     * @return $this
     */
442
    public function removeGeoloc(GeolocPrestataire $geoloc): self
Julien Jorry committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
    {
        if ($this->geolocs->contains($geoloc)) {
            $this->geolocs->removeElement($geoloc);
            $geoloc->setPrestataire(null);
        }
        return $this;
    }

    /**
     * getcontacts
     * @return ArrayCollection contact
     */
    public function getContacts()
    {
        return $this->contacts;
    }

    /**
     * setContacts
     * @param [type] $contacts [description]
     */
    public function setContacts($contacts): self
    {
        $this->contacts = $contacts;
        return $this;
    }
    
    /**
     * @param ContactPrestataire $contact
     * @return $this
     */
    public function addContact(ContactPrestataire $contact): self
    {
        if (!$this->contacts->contains($contact)) {
            $this->contacts[] = $contact;
            $contact->setPrestataire($this);
        }
        return $this;
    }

    /**
     * @param ContactPrestataire $contact
     * @return $this
     */
    public function removeContact(ContactPrestataire $contact): self
    {
        if ($this->contacts->contains($contact)) {
            $this->contacts->removeElement($contact);
            $contact->setPrestataire(null);
        }
        return $this;
    }

Julien Jorry committed
496
    /**
Julien Jorry committed
497
     * @return ArrayCollection[]|User
Julien Jorry committed
498
     */
Julien Jorry committed
499
    public function getUsers()
Julien Jorry committed
500
    {
Julien Jorry committed
501
        return $this->users;
Julien Jorry committed
502
    }
Julien Jorry committed
503 504 505 506 507 508 509
    
    public function getUsersString()
    {
        return join(' - ', array_map(function ($user) {
            return $user->getName().':'.$user->getEmail();
        }, $this->users->getValues()));
    }
Julien Jorry committed
510 511 512

    /**
     * @param User $user
Julien Jorry committed
513 514
     * @return $this
     */
Julien Jorry committed
515
    public function addUser(User $user): self
Julien Jorry committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
    {
        if (!$this->users->contains($user)) {
            $this->users[] = $user;
            $user->addPrestataire($this);
        }
        return $this;
    }

    /**
     * @param User $user
     * @return $this
     */
    public function removeUser(User $users)
    {
        if ($this->users->contains($user)) {
            $this->users->removeElement($user);
            $user->removePrestataire($this);
        }
        return $this;
    }

    /**
     * @param ArrayCollection[]|User $users
Julien Jorry committed
539 540
     * @return Prestataire
     */
Julien Jorry committed
541
    public function setUsers($users): self
Julien Jorry committed
542
    {
Julien Jorry committed
543
        $this->users = $users;
Julien Jorry committed
544 545 546 547
        return $this;
    }

    /**
548
     * @param null|Groupe $groupe
Julien Jorry committed
549 550
     * @return $this
     */
Julien Jorry committed
551
    public function setGroupe(?Groupe $groupe): self
Julien Jorry committed
552
    {
553
        $this->groupe = $groupe;
Julien Jorry committed
554 555 556 557 558 559
        return $this;
    }

    /**
     * @return null|Groupe
     */
560
    public function getGroupe(): ?Groupe
Julien Jorry committed
561
    {
562
        return $this->groupe;
Julien Jorry committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
    }

    /**
    * Get typeprestataire
    * @return
    */
    public function getTypeprestataire()
    {
        return $this->typeprestataire;
    }

    /**
    * Set typeprestataire
    * @return $this
    */
Julien Jorry committed
578
    public function setTypeprestataire($typeprestataire): self
Julien Jorry committed
579 580 581 582 583
    {
        $this->typeprestataire = $typeprestataire;
        return $this;
    }

Julien Jorry committed
584 585 586 587 588 589 590 591
    /**
     * @return Rubrique[]|ArrayCollection
     */
    public function getRubriques()
    {
        return $this->rubriques;
    }

Julien Jorry committed
592 593 594 595 596 597 598
    public function getRubriquesString(): ?string
    {
        return join(' - ', array_map(function ($rubrique) {
            return $rubrique->getName();
        }, $this->rubriques->getValues()));
    }

Julien Jorry committed
599 600 601 602
    /**
     * @param Rubrique $rubrique
     * @return $this
     */
Julien Jorry committed
603
    public function addRubrique(Rubrique $rubrique): self
Julien Jorry committed
604 605 606 607 608 609 610 611 612 613 614 615
    {
        if (!$this->rubriques->contains($rubrique)) {
            $this->rubriques[] = $rubrique;
            $rubrique->addPrestataire($this);
        }
        return $this;
    }

    /**
     * @param Rubrique $rubrique
     * @return $this
     */
Julien Jorry committed
616
    public function removeRubrique(Rubrique $rubrique): self
Julien Jorry committed
617 618 619 620 621 622 623 624
    {
        if ($this->rubriques->contains($rubrique)) {
            $this->rubriques->removeElement($rubrique);
            $rubrique->removePrestataire($this);
        }
        return $this;
    }

Julien Jorry committed
625 626 627 628 629 630 631 632
    /**
     * @return Amap[]|ArrayCollection
     */
    public function getGroupeprestataires()
    {
        return $this->groupeprestataires;
    }

Julien Jorry committed
633 634 635 636
    /**
     * @param Amap[]|ArrayCollection
     * @return this
     */
Julien Jorry committed
637
    public function setGroupeprestataires($groupeprestataires): self
Julien Jorry committed
638 639 640 641 642
    {
        $this->groupeprestataires = $groupeprestataires;
        return $this;
    }

Julien Jorry committed
643 644 645 646
    /**
     * @param Amap $amap
     * @return $this
     */
Julien Jorry committed
647
    public function addGroupeprestataire(Groupeprestataire $groupeprestataire): self
Julien Jorry committed
648 649 650 651 652 653 654 655 656 657 658 659
    {
        if (!$this->groupeprestataires->contains($groupeprestataire)) {
            $this->groupeprestataires[] = $groupeprestataire;
            $groupeprestataire->addPrestataire($this);
        }
        return $this;
    }

    /**
     * @param Amap $amap
     * @return $this
     */
Julien Jorry committed
660
    public function removeGroupeprestataire(Groupeprestataire $groupeprestataire): self
Julien Jorry committed
661 662 663 664 665 666 667
    {
        if ($this->groupeprestataires->contains($groupeprestataire)) {
            $this->groupeprestataires->removeElement($groupeprestataire);
            $groupeprestataire->removePrestataire($this);
        }
        return $this;
    }
Julien Jorry committed
668

Julien Jorry committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
    /**
     * @return EtatPrestataire[]|ArrayCollection
     */
    public function getEtats()
    {
        return $this->etats;
    }
    
    public function getEtatsString(): ?string
    {
        return join(' - ', array_map(function ($etat) {
            return $etat->getName();
        }, $this->etats->getValues()));
    }

    /**
     * @param EtatPrestataire[]|ArrayCollection
     * @return this
     */
    public function setEtats($etats): self
    {
        $this->etats = $etats;
        return $this;
    }

    /**
     * @param EtatPrestataire $etat
     * @return $this
     */
    public function addEtat(EtatPrestataire $etat): self
    {
        if (!$this->etats->contains($etat)) {
            $this->etats[] = $etat;
            $etat->addPrestataire($this);
        }
        return $this;
    }

    /**
     * @param Etat Prestataire $etat
     * @return $this
     */
    public function removeEtat(EtatPrestataire $etat): self
    {
        if ($this->etats->contains($etat)) {
            $this->etats->removeElement($etat);
            $etat->removePrestataire($this);
        }
        return $this;
    }

Julien Jorry committed
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
    /**
    * Get horaires
    * @return string Horaires
    */
    public function getHoraires(): ?string
    {
        return $this->horaires;
    }

    /**
    * Set horaires
    * @return $this
    */
    public function setHoraires($horaires): self
    {
        $this->horaires = $horaires;
        return $this;
    }

    /**
    * Get media
    * @return
    */
    public function getMedia()
    {
        return $this->media;
    }

    /**
    * Set media
    * @return $this
    */
Julien Jorry committed
752
    public function setMedia($media): self
Julien Jorry committed
753 754 755 756 757
    {
        $this->media = $media;
        return $this;
    }

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
    /**
    * Get tauxreconversion
    * @return
    */
    public function getTauxreconversion(): ?float
    {
        return $this->tauxreconversion;
    }
    
    /**
    * Set tauxreconversion
    * @return $this
    */
    public function setTauxreconversion(?float $tauxreconversion): self
    {
        $this->tauxreconversion = $tauxreconversion;
        return $this;
    }

Julien Jorry committed
777 778
    public function __toString(): string
    {
Julien Jorry committed
779 780 781 782 783 784
        return ($this->raison?$this->raison:'Prestataire '.$this->id);
    }

    public function getMapContent(): ?string
    {
        return 'mapcontentpresta';
Julien Jorry committed
785
    }
Julien Jorry committed
786
}