src/Entity/Core/AbstractInstitution.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core;
  3. use App\Entity\Term\Domain;
  4. use App\Form\Type\BaseInstitutionType;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use App\Entity\PersonTrait\CoordinatesTrait;
  9. use App\Entity\Core\AbstractOrganization;
  10. use App\AccessRight\SerializedAccessRights;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\Validator\Mapping\ClassMetadata;
  13. use App\Form\Type\BaseInstitutionType as FormType;
  14. /**
  15.  * Institution.
  16.  *
  17.  * @ORM\Table(name="institution")
  18.  * @ORM\Entity
  19.  * @ORM\InheritanceType("SINGLE_TABLE")
  20.  * @ORM\DiscriminatorColumn(name="type", type="string")
  21.  */
  22. abstract class AbstractInstitution implements SerializedAccessRights
  23. {
  24.     // Hook timestampable behavior : updates createdAt, updatedAt fields
  25.     use TimestampableTrait;
  26.     use CoordinatesTrait;
  27.     /**
  28.      * @var int
  29.      *
  30.      * @ORM\Column(name="id", type="integer")
  31.      * @ORM\Id
  32.      * @ORM\GeneratedValue(strategy="AUTO")
  33.      * @Serializer\Groups({"Default", "api"})
  34.      */
  35.     protected $id;
  36.     /**
  37.      * @var string name
  38.      * @ORM\Column(name="name", type="string", length=512)
  39.      * @Assert\NotBlank(message="Vous devez renseigner un nom d'établissement.")
  40.      * @Serializer\Groups({"Default", "api"})
  41.      */
  42.     protected $name;
  43.     /**
  44.      * @var string idp
  45.      * @ORM\Column(name="idp", type="string", length=512, nullable=true)
  46.      * @Serializer\Groups({"Default", "api"})
  47.      */
  48.     protected $idp;
  49.     /**
  50.      * @var string address_from_ldap
  51.      * @ORM\Column(name="address_from_ldap", type="string", length=512, nullable=true)
  52.      * @Serializer\Groups({"Default", "api"})
  53.      */
  54.     protected $ldapAddress;
  55.     /**
  56.      * @var ArrayCollection
  57.      * @ORM\ManyToMany(targetEntity="App\Entity\Term\Domain")
  58.      * @ORM\JoinTable(name="institution__institution_domain",
  59.      *      joinColumns={@ORM\JoinColumn(name="institution_id", referencedColumnName="id", onDelete="cascade")},
  60.      *      inverseJoinColumns={@ORM\JoinColumn(name="domain_id", referencedColumnName="id", onDelete="cascade")}
  61.      * )
  62.      * @Serializer\Groups({"Default", "api"})
  63.      */
  64.     protected $domains;
  65.     /**
  66.      * @var ArrayCollection
  67.      * @ORM\ManyToMany(targetEntity="App\Entity\Core\AbstractInstitution")
  68.      * @ORM\JoinTable(name="institution__visuinstitutions",
  69.      *      joinColumns={@ORM\JoinColumn(name="institution_id", referencedColumnName="id", onDelete="cascade")},
  70.      *      inverseJoinColumns={@ORM\JoinColumn(name="visu_institution_id", referencedColumnName="id", onDelete="cascade")}
  71.      * )
  72.      * @Serializer\Groups({"Default", "api"})
  73.      */
  74.     protected $visuinstitutions;
  75.     public function __construct()
  76.     {
  77.         $this->domains = new ArrayCollection();
  78.         $this->visuinstitutions = new ArrayCollection();
  79.     }
  80.     /**
  81.      * @return int
  82.      */
  83.     public function getId()
  84.     {
  85.         return $this->id;
  86.     }
  87.     /**
  88.      * @return string
  89.      */
  90.     public function getName()
  91.     {
  92.         return $this->name;
  93.     }
  94.     /**
  95.      * @param string $name
  96.      */
  97.     public function setName($name)
  98.     {
  99.         $this->name $name;
  100.     }
  101.     /**
  102.      * @return string
  103.      */
  104.     public function getIdp()
  105.     {
  106.         return $this->idp;
  107.     }
  108.     /**
  109.      * @param string $idp
  110.      */
  111.     public function setIdp($idp)
  112.     {
  113.         $this->idp $idp;
  114.     }
  115.     /**
  116.      * @return string
  117.      */
  118.     public function getLdapAddress()
  119.     {
  120.         return $this->ldapAddress;
  121.     }
  122.     /**
  123.      * @param string $ldapAddress
  124.      */
  125.     public function setLdapAddress(string $ldapAddress)
  126.     {
  127.         $this->ldapAddress $ldapAddress;
  128.     }
  129.     /**
  130.      * @return mixed
  131.      */
  132.     public function getDomains()
  133.     {
  134.         return $this->domains;
  135.     }
  136.     /**
  137.      * @param mixed $domains
  138.      */
  139.     public function setDomains($domains)
  140.     {
  141.         $this->domains $domains;
  142.     }
  143.     /**
  144.      * @param Domain $domain
  145.      *
  146.      * @return bool
  147.      */
  148.     public function addDomain($domain)
  149.     {
  150.         if (!$this->domains->contains($domain)) {
  151.             $this->domains->add($domain);
  152.             return true;
  153.         }
  154.         return false;
  155.     }
  156.     /**
  157.      * @param Domain $domain
  158.      *
  159.      * @return bool
  160.      */
  161.     public function removeDomain($domain)
  162.     {
  163.         if ($this->domains->contains($domain)) {
  164.             $this->domains->removeElement($domain);
  165.             return true;
  166.         }
  167.         return false;
  168.     }
  169.     /**
  170.      * @return mixed
  171.      */
  172.     public function getVisuinstitutions()
  173.     {
  174.         return $this->visuinstitutions;
  175.     }
  176.     /**
  177.      * @param mixed $visuinstitutions
  178.      */
  179.     public function setVisuinstitutions($visuinstitutions)
  180.     {
  181.         $this->visuinstitutions $visuinstitutions;
  182.     }
  183.     /**
  184.      * @param AbstractInstitution $institution
  185.      *
  186.      * @return bool
  187.      */
  188.     public function addVisuinstitution($institution)
  189.     {
  190.         if (!$this->visuinstitutions->contains($institution)) {
  191.             $this->visuinstitutions->add($institution);
  192.             return true;
  193.         }
  194.         return false;
  195.     }
  196.     /**
  197.      * @param AbstractInstitution $institution
  198.      *
  199.      * @return bool
  200.      */
  201.     public function removeVisuinstitution($institution)
  202.     {
  203.         if ($this->visuinstitutions->contains($institution)) {
  204.             $this->visuinstitutions->removeElement($institution);
  205.             return true;
  206.         }
  207.         return false;
  208.     }
  209.     function __toString()
  210.     {
  211.         return $this->getName();
  212.     }
  213.     public static function getFormType()
  214.     {
  215.         return BaseInstitutionType::class;
  216.     }
  217.     public static function getType()
  218.     {
  219.         return 'institution';
  220.     }
  221. }