]> Raphaël G. Git Repositories - airbundle/blobdiff - Entity/User.php
Fix dance user add/remove from inverse side
[airbundle] / Entity / User.php
index 22bf46da496d7298ff95163b1258a6e10567bdd4..387b1964e33963ef4356d1d838add7238ce3890e 100644 (file)
@@ -1,44 +1,81 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * this file is part of the rapsys packbundle package.
+ *
+ * (c) raphaël gertz <symfony@rapsys.eu>
+ *
+ * for the full copyright and license information, please view the license
+ * file that was distributed with this source code.
+ */
 
-// src/Rapsys/AirBundle/Entity/User.php
 namespace Rapsys\AirBundle\Entity;
 
-use Rapsys\AirBundle\Entity\Application;
-use Rapsys\AirBundle\Entity\Group;
-use Rapsys\AirBundle\Entity\Link;
-use Rapsys\AirBundle\Entity\Snippet;
+use Doctrine\Common\Collections\Collection;
+use Doctrine\Common\Collections\ArrayCollection;
+
 use Rapsys\UserBundle\Entity\User as BaseUser;
 
 class User extends BaseUser {
        /**
-        * @var string
+        * @var ?string
+        */
+       private ?string $city;
+
+       /**
+        * @var ?string
+        */
+       private ?string $phone;
+
+       /**
+        * @var Country
+        */
+       private ?Country $country;
+
+       /**
+        * @var ?string
+        */
+       private ?string $pseudonym;
+
+       /**
+        * @var ?string
         */
-       protected $phone;
+       private ?string $zipcode;
 
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private $applications;
+       private Collection $applications;
 
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private $locations;
+       private Collection $dances;
 
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private $snippets;
+       private Collection $locations;
 
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private $subscribers;
+       private Collection $snippets;
 
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
-       private $subscriptions;
+       private Collection $subscribers;
+
+       /**
+        * @var \Doctrine\Common\Collections\Collection
+        */
+       private Collection $subscriptions;
+
+       /**
+        * @var \Doctrine\Common\Collections\Collection
+        */
+       private Collection $googleTokens;
 
        /**
         * Constructor
@@ -49,12 +86,65 @@ class User extends BaseUser {
                //Call parent constructor
                parent::__construct($mail);
 
+               //Set defaults
+               $this->city = null;
+               $this->country = null;
+               $this->phone = null;
+               $this->pseudonym = null;
+               $this->zipcode = null;
+
                //Set collections
-               $this->applications = new \Doctrine\Common\Collections\ArrayCollection();
-               $this->locations = new \Doctrine\Common\Collections\ArrayCollection();
-               $this->snippets = new \Doctrine\Common\Collections\ArrayCollection();
-               $this->subscribers = new \Doctrine\Common\Collections\ArrayCollection();
-               $this->subscriptions = new \Doctrine\Common\Collections\ArrayCollection();
+               $this->applications = new ArrayCollection();
+               $this->dances = new ArrayCollection();
+               $this->locations = new ArrayCollection();
+               $this->snippets = new ArrayCollection();
+               $this->subscribers = new ArrayCollection();
+               $this->subscriptions = new ArrayCollection();
+               $this->googleTokens = new ArrayCollection();
+       }
+
+       /**
+        * Set city
+        *
+        * @param string $city
+        *
+        * @return User
+        */
+       public function setCity(?string $city): User {
+               $this->city = $city;
+
+               return $this;
+       }
+
+       /**
+        * Get city
+        *
+        * @return string
+        */
+       public function getCity(): ?string {
+               return $this->city;
+       }
+
+       /**
+        * Set country
+        *
+        * @param Country $country
+        *
+        * @return User
+        */
+       public function setCountry(?Country $country): User {
+               $this->country = $country;
+
+               return $this;
+       }
+
+       /**
+        * Get country
+        *
+        * @return Country
+        */
+       public function getCountry(): ?Country {
+               return $this->country;
        }
 
        /**
@@ -64,7 +154,7 @@ class User extends BaseUser {
         *
         * @return User
         */
-       public function setPhone($phone) {
+       public function setPhone(?string $phone): User {
                $this->phone = $phone;
 
                return $this;
@@ -75,62 +165,62 @@ class User extends BaseUser {
         *
         * @return string
         */
-       public function getPhone() {
+       public function getPhone(): ?string {
                return $this->phone;
        }
 
        /**
-        * Set donation
+        * Set pseudonym
         *
-        * @param string $donation
+        * @param string $pseudonym
         *
         * @return User
         */
-       public function setDonation($donation) {
-               $this->donation = $donation;
+       public function setPseudonym(?string $pseudonym): User {
+               $this->pseudonym = $pseudonym;
 
                return $this;
        }
 
        /**
-        * Get donation
+        * Get pseudonym
         *
         * @return string
         */
-       public function getDonation() {
-               return $this->donation;
+       public function getPseudonym(): ?string {
+               return $this->pseudonym;
        }
 
        /**
-        * Set site
+        * Set zipcode
         *
-        * @param string $site
+        * @param string $zipcode
         *
         * @return User
         */
-       public function setSite($site) {
-               $this->site = $site;
+       public function setZipcode(?string $zipcode): User {
+               $this->zipcode = $zipcode;
 
                return $this;
        }
 
        /**
-        * Get site
+        * Get zipcode
         *
         * @return string
         */
-       public function getSite() {
-               return $this->site;
+       public function getZipcode(): ?string {
+               return $this->zipcode;
        }
 
        /**
         * Add application
         *
-        * @param \Rapsys\AirBundle\Entity\Application $application
+        * @param Application $application
         *
         * @return User
         */
-       public function addApplication(Application $application) {
+       public function addApplication(Application $application): User {
                $this->applications[] = $application;
 
                return $this;
@@ -139,10 +229,10 @@ class User extends BaseUser {
        /**
         * Remove application
         *
-        * @param \Rapsys\AirBundle\Entity\Application $application
+        * @param Application $application
         */
-       public function removeApplication(Application $application) {
-               $this->applications->removeElement($application);
+       public function removeApplication(Application $application): bool {
+               return $this->applications->removeElement($application);
        }
 
        /**
@@ -150,49 +240,51 @@ class User extends BaseUser {
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getApplications() {
+       public function getApplications(): Collection {
                return $this->applications;
        }
 
        /**
-        * Add snippet
+        * Add dance
         *
-        * @param \Rapsys\AirBundle\Entity\Snippet $snippet
+        * @param Dance $dance
         *
         * @return User
         */
-       public function addSnippet(Snippet $snippet) {
-               $this->snippets[] = $snippet;
+       public function addDance(Dance $dance): User {
+               $this->dances[] = $dance;
 
                return $this;
        }
 
        /**
-        * Remove snippet
+        * Remove dance
         *
-        * @param \Rapsys\AirBundle\Entity\Snippet $snippet
+        * @param Dance $dance
+        *
+        * @return bool
         */
-       public function removeSnippet(Snippet $snippet) {
-               $this->snippets->removeElement($snippet);
+       public function removeDance(Dance $dance): bool {
+               return $this->dances->removeElement($dance);
        }
 
        /**
-        * Get snippets
+        * Get dances
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getSnippets() {
-               return $this->snippets;
+       public function getDances(): Collection {
+               return $this->dances;
        }
 
        /**
         * Add location
         *
-        * @param \Rapsys\AirBundle\Entity\Location $location
+        * @param Location $location
         *
         * @return User
         */
-       public function addLocation(Location $location) {
+       public function addLocation(Location $location): User {
                $this->locations[] = $location;
 
                return $this;
@@ -201,10 +293,10 @@ class User extends BaseUser {
        /**
         * Remove location
         *
-        * @param \Rapsys\AirBundle\Entity\Location $location
+        * @param Location $location
         */
-       public function removeLocation(Location $location) {
-               $this->locations->removeElement($location);
+       public function removeLocation(Location $location): bool {
+               return $this->locations->removeElement($location);
        }
 
        /**
@@ -212,18 +304,49 @@ class User extends BaseUser {
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getLocations() {
+       public function getLocations(): Collection {
                return $this->locations;
        }
 
+       /**
+        * Add snippet
+        *
+        * @param Snippet $snippet
+        *
+        * @return User
+        */
+       public function addSnippet(Snippet $snippet): User {
+               $this->snippets[] = $snippet;
+
+               return $this;
+       }
+
+       /**
+        * Remove snippet
+        *
+        * @param Snippet $snippet
+        */
+       public function removeSnippet(Snippet $snippet): bool {
+               return $this->snippets->removeElement($snippet);
+       }
+
+       /**
+        * Get snippets
+        *
+        * @return \Doctrine\Common\Collections\Collection
+        */
+       public function getSnippets(): Collection {
+               return $this->snippets;
+       }
+
        /**
         * Add subscriber
         *
-        * @param \Rapsys\AirBundle\Entity\User $subscriber
+        * @param User $subscriber
         *
         * @return User
         */
-       public function addSubscriber(User $subscriber) {
+       public function addSubscriber(User $subscriber): User {
                $this->subscribers[] = $subscriber;
 
                return $this;
@@ -232,10 +355,10 @@ class User extends BaseUser {
        /**
         * Remove subscriber
         *
-        * @param \Rapsys\AirBundle\Entity\User $subscriber
+        * @param User $subscriber
         */
-       public function removeSubscriber(User $subscriber) {
-               $this->subscribers->removeElement($subscriber);
+       public function removeSubscriber(User $subscriber): bool {
+               return $this->subscribers->removeElement($subscriber);
        }
 
        /**
@@ -243,18 +366,21 @@ class User extends BaseUser {
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getSubscribers() {
+       public function getSubscribers(): Collection {
                return $this->subscribers;
        }
 
        /**
         * Add subscription
         *
-        * @param \Rapsys\AirBundle\Entity\User $subscription
+        * @param User $subscription
         *
         * @return User
         */
-       public function addSubscription(User $subscription) {
+       public function addSubscription(User $subscription): User {
+               //Add from owning side
+               $subscription->addSubscriber($this);
+
                $this->subscriptions[] = $subscription;
 
                return $this;
@@ -263,10 +389,17 @@ class User extends BaseUser {
        /**
         * Remove subscription
         *
-        * @param \Rapsys\AirBundle\Entity\User $subscription
+        * @param User $subscription
         */
-       public function removeSubscription(User $subscription) {
-               $this->subscriptions->removeElement($subscription);
+       public function removeSubscription(User $subscription): bool {
+               if (!$this->users->contains($user)) {
+                       return true;
+               }
+
+               //Remove from owning side
+               $subscription->removeSubscriber($this);
+
+               return $this->subscriptions->removeElement($subscription);
        }
 
        /**
@@ -274,7 +407,38 @@ class User extends BaseUser {
         *
         * @return \Doctrine\Common\Collections\Collection
         */
-       public function getSubscriptions() {
+       public function getSubscriptions(): Collection {
                return $this->subscriptions;
        }
+
+       /**
+        * Add google token
+        *
+        * @param GoogleToken $googleToken
+        *
+        * @return User
+        */
+       public function addGoogleToken(GoogleToken $googleToken): User {
+               $this->googleTokens[] = $googleToken;
+
+               return $this;
+       }
+
+       /**
+        * Remove google token
+        *
+        * @param GoogleToken $googleToken
+        */
+       public function removeGoogleToken(GoogleToken $googleToken): bool {
+               return $this->googleTokens->removeElement($googleToken);
+       }
+
+       /**
+        * Get googleTokens
+        *
+        * @return \Doctrine\Common\Collections\Collection
+        */
+       public function getGoogleTokens(): Collection {
+               return $this->googleTokens;
+       }
 }