src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Symfony\Component\HttpFoundation\File\File as HttpFile;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. //use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  * @Vich\Uploadable
  13.  */
  14. class User implements UserInterface/*AdvancedUserInterface,*/ \Serializable
  15. {
  16.     
  17.     const ROLE_NONE 0;
  18.     const ROLE_USER 1;
  19.     const ROLE_MANAGER 4;
  20.     const ROLE_ADMIN 8;
  21.     const ROLE_SOCIAL_ADMIN 10;
  22.     const ROLE_SUPER_ADMIN 16;
  23.     
  24.     const STATUS_ACTIVE 1;
  25.     const STATUS_INACTIVE 0;
  26.     const STATUS_BANNED = -3;
  27.     const STATUS_SPAM = -4;
  28.     
  29.     const MEMBERSHIP_NONE 0;
  30.     const MEMBERSHIP_INDIVIDUAL 1;
  31.     const MEMBERSHIP_COMPANY 2;
  32.     const MEMBERSHIP_PREMIUM 3;
  33.     
  34.     /**
  35.      * @ORM\Id()
  36.      * @ORM\GeneratedValue()
  37.      * @ORM\Column(type="bigint")
  38.      */
  39.     private $id;
  40.     
  41.     /**
  42.      * @ORM\Version @ORM\Column(type="integer")
  43.      */
  44.     private $version;
  45.     
  46.     
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      * @var string
  50.      */
  51.     protected $image;
  52.     
  53.     /**
  54.      * @Vich\UploadableField(mapping="user_images", fileNameProperty="image")
  55.      * @var File
  56.      */
  57.     protected $imageFile;
  58.     
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity="App\Entity\Media", cascade={"persist"})
  61.      * @ORM\JoinColumn(nullable=true)
  62.      */
  63.     private $media;
  64.     /**
  65.      * @ORM\Column(type="string", length=64, unique=true)
  66.      */
  67.     private $username;
  68.     /**
  69.      * @ORM\Column(type="string", length=255)
  70.      */
  71.     private $password;
  72.     /**
  73.      * @ORM\Column(type="string", length=191, unique=true)
  74.      */
  75.     private $email;
  76.     /**
  77.      * @ORM\Column(type="string", length=64)
  78.      */
  79.     private $firstname;
  80.     /**
  81.      * @ORM\Column(type="string", length=64)
  82.      */
  83.     private $lastname;
  84.     /**
  85.      * @ORM\Column(type="string", length=128)
  86.      */
  87.     private $displayname;
  88.     /**
  89.      * @ORM\Column(type="integer")
  90.      */
  91.     private $role;
  92.     /**
  93.      * @ORM\Column(type="integer")
  94.      */
  95.     private $type;
  96.     /**
  97.      * @ORM\Column(type="integer")
  98.      */
  99.     private $status;
  100.     
  101.     /**
  102.      * @ORM\Column(type="integer")
  103.      */
  104.     private $member;
  105.     
  106.     /**
  107.      * @ORM\Column(type="datetime", nullable=true)
  108.      */
  109.     private $member_expires;
  110.     
  111.     /**
  112.      * @ORM\OneToMany(targetEntity="App\Entity\UserMeta", mappedBy="user", orphanRemoval=true, cascade={"persist"})
  113.      */
  114.     private $usermeta;
  115.     /**
  116.      * @ORM\OneToMany(targetEntity="App\Entity\Content", mappedBy="author")
  117.      * @ORM\OrderBy({"id" = "DESC"})
  118.      */
  119.     private $content;
  120.     /**
  121.      * @ORM\OneToMany(targetEntity="App\Entity\Quiz", mappedBy="author")
  122.      */
  123.     private $quizzes;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\QuizResponse", mappedBy="user")
  126.      */
  127.     private $quizResponses;
  128.     
  129.     /**
  130.      * @ORM\OneToMany(targetEntity="App\Entity\Lead", mappedBy="user", orphanRemoval=true, cascade={"persist", "remove"})
  131.      * @ORM\OrderBy({"id" = "DESC"})
  132.      */
  133.     private $leads;
  134.     /**
  135.      * @ORM\Column(type="datetime")
  136.      */
  137.     private $created_at;
  138.     /**
  139.      * @ORM\Column(type="datetime")
  140.      */
  141.     private $modified_at;
  142.     /**
  143.      * @ORM\OneToMany(targetEntity="App\Entity\PurchaseNote", mappedBy="author")
  144.      */
  145.     private $purchaseNotes;
  146.     
  147.     /**
  148.      * @ORM\OneToMany(targetEntity="App\Entity\ContactNote", mappedBy="author")
  149.      */
  150.     private $contactNotes;
  151.     
  152.     /**
  153.      * @ORM\Column(type="string", length=255, nullable=true)
  154.      */
  155.     private $activation_token;
  156.     /**
  157.      * @ORM\Column(type="datetime", nullable=true)
  158.      */
  159.     private $activation_expires;
  160.     /**
  161.      * @ORM\Column(type="string", length=255, nullable=true)
  162.      */
  163.     private $reset_pw_token;
  164.     /**
  165.      * @ORM\Column(type="datetime", nullable=true)
  166.      */
  167.     private $reset_pw_expires;
  168.     /**
  169.      * @ORM\Column(type="string", length=255, nullable=true)
  170.      */
  171.     private $mfa_token;
  172.     /**
  173.      * @ORM\Column(type="string", length=255, nullable=true)
  174.      */
  175.     private $mfa_code;
  176.     /**
  177.      * @ORM\Column(type="datetime", nullable=true)
  178.      */
  179.     private $mfa_token_expires;
  180.     /**
  181.      * @ORM\ManyToMany(targetEntity="App\Entity\Customer", mappedBy="members")
  182.      */
  183.     private $companies;
  184.     
  185.     /**
  186.      * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="user")
  187.      */
  188.     private $comments;
  189.     /**
  190.      * @ORM\OneToMany(targetEntity="App\Entity\Purchase", mappedBy="user")
  191.      * @ORM\OrderBy({"purchased_at" = "DESC"})
  192.      */
  193.     private $purchases;
  194.     
  195.     /**
  196.      * @ORM\OneToMany(targetEntity="App\Entity\Traffic", mappedBy="user", orphanRemoval=true, cascade={"persist", "remove"})
  197.      */
  198.     private $traffic;
  199.     
  200.     /**
  201.      * @ORM\ManyToOne(targetEntity="App\Entity\Contact", inversedBy="users", cascade={"persist"})
  202.      * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", nullable=true)
  203.      */
  204.     private $contact;
  205.     
  206.     /**
  207.      * @ORM\OneToMany(targetEntity="App\Entity\PollResponse", mappedBy="user", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  208.      */
  209.     private $pollResponses;
  210.     /**
  211.      * @ORM\Column(type="integer")
  212.      */
  213.     private $site_signed_up_on;
  214.     /**
  215.      * @ORM\Column(type="text")
  216.      */
  217.     private $author_bio;
  218.     
  219.     public function __construct()
  220.     {        
  221.         
  222.         // $this->isActive = false;
  223.         
  224.         $this->firstname "";
  225.         $this->lastname "";
  226.         $this->displayname "";
  227.         $this->site_signed_up_on 0;
  228.         
  229.         $this->type 1;
  230.         $this->role self::ROLE_USER;
  231.         $this->status SELF::STATUS_INACTIVE;
  232.         $this->member SELF::MEMBERSHIP_NONE;
  233.         
  234.         // email tokens
  235.         $this->activation_token "";
  236.         $this->reset_pw_token "";
  237.         $this->mfa_token "";
  238.         $this->mfa_code "";
  239.         
  240.         $this->usermeta = new ArrayCollection();
  241.         $this->content = new ArrayCollection();
  242.         $this->leads = new ArrayCollection();
  243.         
  244.         // can we give them a default avatar if not set? - probably should pull from the getter...
  245.         // $this->setImageFile("")
  246.         
  247.         $this->modified_at = new \DateTime();
  248.         $this->created_at = new \DateTime();
  249.         
  250.         $this->quizzes = new ArrayCollection();
  251.         $this->quizResponses = new ArrayCollection();
  252.         $this->purchaseNotes = new ArrayCollection();
  253.         $this->contactNotes = new ArrayCollection();
  254.         $this->companies = new ArrayCollection();
  255.         $this->comments = new ArrayCollection();
  256.         $this->purchases = new ArrayCollection();
  257.         $this->author_bio "";
  258.     }
  259.     public function getId()
  260.     {
  261.         return $this->id;
  262.     }
  263.     
  264.     public function getVersion() {
  265.         return $this->version;
  266.     }
  267.     
  268.     public function setUsername(string $username null): self
  269.     {
  270.         $this->username $username $username "";
  271.         return $this;
  272.     }
  273.     /*
  274.     public function getPasshash(): ?string
  275.     {
  276.         return $this->passhash;
  277.     }
  278.     public function setPasshash(string $passhash): self
  279.     {
  280.         $this->passhash = $passhash;
  281.         return $this;
  282.     }
  283.     */
  284.     public function getEmail(): ?string
  285.     {
  286.         return $this->email;
  287.     }
  288.     public function setEmail(string $email null): self
  289.     {
  290.         $this->email $email $email "";
  291.         return $this;
  292.     }
  293.     public function getFirstname(): ?string
  294.     {
  295.         return $this->firstname;
  296.     }
  297.     public function setFirstname(string $firstname null): self
  298.     {
  299.         $this->firstname $firstname $firstname "";
  300.         return $this;
  301.     }
  302.     public function getLastname(): ?string
  303.     {
  304.         return $this->lastname;
  305.     }
  306.     public function setLastname(string $lastname null): self
  307.     {
  308.         $this->lastname $lastname $lastname "";
  309.         return $this;
  310.     }
  311.     public function getDisplayname(): ?string
  312.     {
  313.         return $this->displayname $this->displayname $this->getUsername();
  314.     }
  315.     public function setDisplayname(string $displayname null): self
  316.     {
  317.         $this->displayname $displayname $displayname "";
  318.         return $this;
  319.     }
  320.     public function getByline()
  321.     {
  322.         if ($this->firstname && $this->lastname) {
  323.             return "By {$this->firstname} {$this->lastname}.";
  324.         }
  325.         
  326.         if ($this->displayname) {
  327.             return "By {$this->displayname}.";
  328.         }
  329.         $return "";
  330.     }
  331.     public function getRole(): ?int
  332.     {
  333.         return $this->role;
  334.     }
  335.     public function setRole(?int $role): self
  336.     {
  337.         $role = (int) $role;
  338.         
  339.         $this->role $role;
  340.         return $this;
  341.     }
  342.     public function isAdmin()
  343.     {
  344.         return $this->role >= self::ROLE_ADMIN;
  345.     }
  346.     public function isSocialAdmin()
  347.     {
  348.         return $this->role >= self::ROLE_SOCIAL_ADMIN;
  349.     }
  350.     public function isSuperAdmin()
  351.     {
  352.         return $this->role == self::ROLE_SUPER_ADMIN;
  353.     }
  354.     public function getType(): ?int
  355.     {
  356.         return $this->type;
  357.     }
  358.     public function setType(int $type): self
  359.     {
  360.         $this->type $type;
  361.         return $this;
  362.     }
  363.     public function getStatus(): ?int
  364.     {
  365.         return $this->status;
  366.     }
  367.     public function setStatus(int $status): self
  368.     {
  369.         $this->status $status;
  370.         
  371.         return $this;
  372.     }
  373.     
  374.     public function getMember(): ?int
  375.     {
  376.         return $this->member;
  377.     }
  378.     
  379.     public function setMember(int $member): self
  380.     {
  381.         $this->member $member;
  382.         
  383.         return $this;
  384.     }
  385.     
  386.     /*
  387.     public function getMember(): ?bool
  388.     {
  389.         return $this->member == 1;
  390.     }
  391.     
  392.     public function setMember(bool $value): self
  393.     {
  394.         $this->member = $value ? 1 : 0;
  395.         return $this;
  396.     }
  397.     */
  398.     public function isMember(): ?bool
  399.     {
  400.         return ($this->getMember() > 0) ? true false;
  401.     }
  402.     
  403.     public function getMemberExpires(): ?\DateTimeInterface
  404.     {
  405.         return $this->member_expires;
  406.     }
  407.     public function setMemberExpires(\DateTimeInterface $member_expires null): self
  408.     {
  409.         $this->member_expires $member_expires;
  410.         return $this;
  411.     }
  412.     /**
  413.      * @return Collection|UserMeta[]
  414.      */
  415.     public function getUsermeta(): Collection
  416.     {
  417.         return $this->usermeta;
  418.     }
  419.     
  420.     public function getUserMetaByKey ($key "")
  421.     {
  422.         foreach ($this->usermeta as $meta) {
  423.             if ($meta->getMetakey() == $key) {
  424.                 return $meta;
  425.             }
  426.         }
  427.         return null;
  428.     }
  429.     
  430.     public function getUserMetaValueByKey ($key "")
  431.     {
  432.         $meta $this->getUserMetaByKey($key);
  433.         if ($meta) {
  434.             return $meta->getMetaValue();
  435.         }
  436.         return "";
  437.     }
  438.     // sets the content meta with the provided certain key / value, or changes it if one with that key already exists
  439.     public function setUsermetum($key ""$value "")
  440.     {
  441.         $meta $this->getUserMetaByKey($key);
  442.         if ($meta) {
  443.             $meta->setMetavalue($value);
  444.         }
  445.         else {
  446.             $meta = new UserMeta();
  447.             $meta->setMetakey($key);
  448.             $meta->setMetavalue($value);
  449.             $this->addUsermetum($meta);
  450.         }
  451.         
  452.     }
  453.     // adds content meta, even if one with that key already exists
  454.     public function addUsermetum(UserMeta $usermetum): self
  455.     {
  456.         if (!$this->usermeta->contains($usermetum)) {
  457.             $this->usermeta[] = $usermetum;
  458.             $usermetum->setUser($this);
  459.         }
  460.         return $this;
  461.     }
  462.     public function removeUsermetum(UserMeta $usermetum): self
  463.     {
  464.         if ($this->usermeta->contains($usermetum)) {
  465.             $this->usermeta->removeElement($usermetum);
  466.             // set the owning side to null (unless already changed)
  467.             if ($usermetum->getUser() === $this) {
  468.                 $usermetum->setUser(null);
  469.             }
  470.         }
  471.         return $this;
  472.     }
  473.     /**
  474.      * @return Collection|Content[]
  475.      */
  476.     public function getContent(): Collection
  477.     {
  478.         return $this->content;
  479.     }
  480.     public function addContent(Content $content): self
  481.     {
  482.         if (!$this->content->contains($content)) {
  483.             $this->content[] = $content;
  484.             $content->setAuthor($this);
  485.         }
  486.         return $this;
  487.     }
  488.     public function removeContent(Content $content): self
  489.     {
  490.         if ($this->content->contains($content)) {
  491.             $this->content->removeElement($content);
  492.             // set the owning side to null (unless already changed)
  493.             if ($content->getAuthor() === $this) {
  494.                 $content->setAuthor(null);
  495.             }
  496.         }
  497.         return $this;
  498.     }
  499.     
  500.     public function getForumTopics ()
  501.     {
  502.         $content $this->getContent();
  503.         $return = [];
  504.         foreach ($content as $c) {
  505.             if ($c->getType() == Content::FORUM_TOPIC) {
  506.                 $return[] = $c;
  507.             }
  508.         }
  509.         return new ArrayCollection($return);
  510.     }
  511.     
  512.     public function getForumReplies ()
  513.     {
  514.         $content $this->getContent();
  515.         $return = [];
  516.         foreach ($content as $c) {
  517.             if ($c->getType() == Content::FORUM_REPLY) {
  518.                 $return[] = $c;
  519.             }
  520.         }
  521.         return new ArrayCollection($return);
  522.     }
  523.     
  524.     public function markAsSpam (): self
  525.     {
  526.         $this->setStatus(User::STATUS_SPAM);
  527.         $content $this->getContent();
  528.         foreach ($content as $c) {
  529.             if($c->getStatus() == Content::STATUS_ACTIVE) {
  530.                 $c->setStatus(Content::STATUS_SPAM);
  531.             }
  532.         }
  533.         //should we set child content status too?
  534.         return $this;
  535.     }
  536.     
  537.     public function unmarkAsSpam (): self
  538.     {
  539.         $this->setStatus(User::STATUS_ACTIVE);
  540.         $content $this->getContent();
  541.         foreach ($content as $c) {
  542.             if($c->getStatus() == Content::STATUS_SPAM) {
  543.                 $c->setStatus(Content::STATUS_ACTIVE);
  544.             }
  545.         }
  546.         //should we set child content status too?
  547.         return $this;
  548.     }
  549.     
  550.     /**
  551.      * @return Collection|Lead[]
  552.      */
  553.     public function getLeads(): Collection
  554.     {
  555.         return $this->leads;
  556.     }
  557.     public function addLead(Lead $lead): self
  558.     {
  559.         if (!$this->leads->contains($lead)) {
  560.             $this->leads[] = $lead;
  561.             $lead->setUser($this);
  562.         }
  563.         
  564.         return $this;
  565.     }
  566.     public function removeLead(Lead $lead): self
  567.     {
  568.         if ($this->leads->contains($lead)) {
  569.             $this->leads->removeElement($lead);
  570.             // set the owning side to null (unless already changed)
  571.             if ($lead->getUser() === $this) {
  572.                 $lead->setUser(null);
  573.             }
  574.         }
  575.         return $this;
  576.     }
  577.     
  578.     public function __toString ()
  579.     {
  580.         return $this->username $this->username '';
  581.     }
  582.     public function getCreatedAt(): ?\DateTimeInterface
  583.     {
  584.         return $this->created_at;
  585.     }
  586.     public function setCreatedAt(\DateTimeInterface $created_at): self
  587.     {
  588.         $this->created_at $created_at;
  589.         return $this;
  590.     }
  591.     public function getModifiedAt(): ?\DateTimeInterface
  592.     {
  593.         return $this->modified_at;
  594.     }
  595.     public function setModifiedAt(\DateTimeInterface $modified_at): self
  596.     {
  597.         $this->modified_at $modified_at;
  598.         return $this;
  599.     }
  600.     
  601.     // image getters / setters
  602.     // public function setImageFile(File $image = null)
  603.     public function setImageFile(HttpFile $image null)
  604.     {
  605.         $this->imageFile $image;
  606.         // VERY IMPORTANT:
  607.         // It is required that at least one field changes if you are using Doctrine,
  608.         // otherwise the event listeners won't be called and the file is lost
  609.         if ($image) {
  610.             
  611.             // if 'updatedAt' is not defined in your entity, use another property
  612.             $this->modified_at = new \DateTime("now");
  613.         }
  614.     }
  615.     public function getImageFile()
  616.     {
  617.         return $this->imageFile;
  618.     }
  619.     public function setImage($image)
  620.     {
  621.         $this->image $image;
  622.         return $this;
  623.     }
  624.     public function getImage()
  625.     {
  626.         return $this->image;
  627.     }
  628.     
  629.     public function removeAvatar ()
  630.     {
  631.         if ($this->image) {
  632.             $file dirname(dirname(dirname(__FILE__)))."/public/uploads/users/{$this->image}";
  633.             if (is_file($file)) {
  634.                 unlink($file);
  635.             }
  636.             $this->imageFile null;
  637.             $this->image "";
  638.             $this->modified_at = new \DateTime("now");
  639.         }
  640.     }
  641.     
  642.     public function getAvatarURL()
  643.     {
  644.         if($this->media) {
  645.             return $this->media->getURL();
  646.         }
  647.         elseif ($this->image) {
  648.             return "/uploads/users/{$this->image}";
  649.         } else {
  650.             return "/assets/img/default-user.jpg";
  651.         }
  652.         
  653.     }
  654.     
  655.     public function getMedia (): ?Media
  656.     {
  657.         return $this->media;
  658.     }
  659.     
  660.     public function setMedia (Media $media null): self
  661.     {
  662.         $this->media $media;
  663.         
  664.         return $this;
  665.     }
  666.     /**
  667.      * @return Collection|Quiz[]
  668.      */
  669.     public function getquizzes(): Collection
  670.     {
  671.         return $this->quizzes;
  672.     }
  673.     public function addQuiz(Quiz $quiz): self
  674.     {
  675.         if (!$this->quizzes->contains($quiz)) {
  676.             $this->quizzes[] = $quiz;
  677.             $quiz->setAuthor($this);
  678.         }
  679.     }
  680.     
  681.     public function removeQuiz(Quiz $quiz): self
  682.     {
  683.         if ($this->quizzes->contains($quiz)) {
  684.             $this->quizzes->removeElement($quiz);
  685.             // set the owning side to null (unless already changed)
  686.             if ($quiz->getAuthor() === $this) {
  687.                 $quiz->setAuthor(null);
  688.             }
  689.         }
  690.     }
  691.     /**
  692.      * @return Collection|QuizResponse[]
  693.      */
  694.     public function getQuizResponses(): Collection
  695.     {
  696.         return $this->quizResponses;
  697.     }
  698.     public function addQuizResponse(QuizResponse $quizResponse): self
  699.     {
  700.         if (!$this->quizResponses->contains($quizResponse)) {
  701.             $this->quizResponses[] = $quizResponse;
  702.             $quizResponse->setUser($this);
  703.         }
  704.     }
  705.     
  706.     public function removeQuizResponse(QuizResponse $quizResponse): self
  707.     {
  708.         if ($this->quizResponses->contains($quizResponse)) {
  709.             $this->quizResponses->removeElement($quizResponse);
  710.             // set the owning side to null (unless already changed)
  711.             if ($quizResponse->getUser() === $this) {
  712.                 $quizResponse->setUser(null);
  713.             }
  714.         }
  715.     }
  716.     /**
  717.      * @return Collection|PurchaseNote[]
  718.      */
  719.     public function getPurchaseNotes(): Collection
  720.     {
  721.         return $this->purchaseNotes;
  722.     }
  723.     public function addPurchaseNote(PurchaseNote $orderNote): self
  724.     {
  725.         if (!$this->purchaseNotes->contains($orderNote)) {
  726.             $this->purchaseNotes[] = $orderNote;
  727.             $orderNote->setAuthorId($this);
  728.         }
  729.     }
  730.     
  731.     public function removeOrderNote(PurchaseNote $orderNote): self
  732.     {
  733.         if ($this->purchaseNotes->contains($orderNote)) {
  734.             $this->purchaseNotes->removeElement($orderNote);
  735.             // set the owning side to null (unless already changed)
  736.             if ($orderNote->getAuthorId() === $this) {
  737.                 $orderNote->setAuthorId(null);
  738.             }
  739.         }
  740.     }
  741.     
  742.     /**
  743.      * @return Collection|ContactNote[]
  744.      */
  745.     public function getContactNotes(): Collection
  746.     {
  747.         return $this->contactNotes;
  748.     }
  749.     public function addContactNote(ContactNote $contactNote): self
  750.     {
  751.         if (!$this->contactNotes->contains($contactNote)) {
  752.             $this->contactNotes[] = $contactNote;
  753.             $contactNote->setAuthorId($this);
  754.         }
  755.     }
  756.     
  757.     public function removeContactNote(ContactNote $contactNote): self
  758.     {
  759.         if ($this->contactNotes->contains($contactNote)) {
  760.             $this->contactNotes->removeElement($contactNote);
  761.             // set the owning side to null (unless already changed)
  762.             if ($contactNote->getAuthorId() === $this) {
  763.                 $contactNote->setAuthorId(null);
  764.             }
  765.         }
  766.     }
  767.     
  768.     public function getActivationToken(): ?string
  769.     {
  770.         return $this->activation_token;
  771.     }
  772.     public function setActivationToken(string $activation_token null): self
  773.     {
  774.         $this->activation_token $activation_token;
  775.         return $this;
  776.     }
  777.     
  778.     public function getActivationExpires(): ?\DateTimeInterface
  779.     {
  780.         return $this->activation_expires;
  781.     }
  782.     public function setActivationExpires(\DateTimeInterface $activation_expires null): self
  783.     {
  784.         $this->activation_expires $activation_expires;
  785.         return $this;
  786.     }
  787.     public function getResetPwToken(): ?string
  788.     {
  789.         return $this->reset_pw_token;
  790.     }
  791.     public function setResetPwToken(string $reset_pw_token null): self
  792.     {
  793.         $this->reset_pw_token $reset_pw_token;
  794.         return $this;
  795.     }
  796.     public function getResetPwExpires(): ?\DateTimeInterface
  797.     {
  798.         return $this->reset_pw_expires;
  799.     }
  800.     public function setResetPwExpires(\DateTimeInterface $reset_pw_expires null): self
  801.     {
  802.         $this->reset_pw_expires $reset_pw_expires;
  803.         return $this;
  804.     }
  805.         
  806.     public function getMfaToken(): ?string
  807.     {
  808.         return $this->mfa_token;
  809.     }
  810.     public function setMfaToken(string $mfa_token null): self
  811.     {
  812.         $this->mfa_token $mfa_token;
  813.         return $this;
  814.     }
  815.     public function getMfaCode(): ?string
  816.     {
  817.         return $this->mfa_code;
  818.     }
  819.     public function setMfaCode(string $mfa_code null): self
  820.     {
  821.         $this->mfa_code $mfa_code;
  822.         return $this;
  823.     }
  824.     
  825.     public function getMfaTokenExpires(): ?\DateTimeInterface
  826.     {
  827.         return $this->mfa_token_expires;
  828.     }
  829.     public function setMfaTokenExpires(\DateTimeInterface $mfa_token_expires null): self
  830.     {
  831.         $this->mfa_token_expires $mfa_token_expires;
  832.         return $this;
  833.     }
  834.     /**
  835.      * @return Collection|Customer[]
  836.      */
  837.     public function getCompanies(): Collection
  838.     {
  839.         return $this->companies;
  840.     }
  841.     
  842.     public function inCompany(Customer $company): ?bool
  843.     {
  844.         return $this->companies->contains($company);
  845.     }
  846.     public function addCompany(Customer $company): self
  847.     {
  848.         if (!$this->companies->contains($company)) {
  849.             $this->companies[] = $company;
  850.             $company->addMember($this);
  851.         }
  852.         return $this;
  853.     }
  854.     public function removeCompany(Customer $company): self
  855.     {
  856.         if ($this->companies->contains($company)) {
  857.             $this->companies->removeElement($company);
  858.             $company->removeMember($this);
  859.         }
  860.         return $this;
  861.     }
  862.     
  863.     public function getFullName ()
  864.     {
  865.         if ($this->firstname && $this->lastname) {
  866.             return "{$this->firstname} {$this->lastname}";
  867.         }
  868.         
  869.         if ($this->displayname) {
  870.             return $this->displayname;
  871.         }
  872.         
  873.         // if nothing else - return username
  874.         return $this->username;
  875.     }
  876.     
  877.     // UserInterface
  878.     // ===================
  879.     
  880.     public function getRoles ()
  881.     {
  882.         $roles = array ();
  883.         if ($this->role == 1) {
  884.             $roles[] = "ROLE_USER";
  885.         }
  886.         
  887.         if ($this->role == 4) {
  888.             $roles[] = "ROLE_USER";
  889.             $roles[] = "ROLE_MANAGER";
  890.         }
  891.         
  892.         if ($this->role == 8) {
  893.             $roles[] = "ROLE_USER";
  894.             $roles[] = "ROLE_MANAGER";
  895.             $roles[] = "ROLE_ADMIN";
  896.             $roles[] = "ROLE_ALLOWED_TO_SWITCH";
  897.         }
  898.         
  899.         if ($this->role == 10) {
  900.             $roles[] = "ROLE_USER";
  901.             $roles[] = "ROLE_MANAGER";
  902.             $roles[] = "ROLE_ADMIN";
  903.             $roles[] = "ROLE_SOCIAL_ADMIN";
  904.             $roles[] = "ROLE_ALLOWED_TO_SWITCH";
  905.         }
  906.         
  907.         if ($this->role == 16) {
  908.             $roles[] = "ROLE_USER";
  909.             $roles[] = "ROLE_MANAGER";
  910.             $roles[] = "ROLE_ADMIN";
  911.             $roles[] = "ROLE_ALLOWED_TO_SWITCH";
  912.             $roles[] = "ROLE_SUPER_ADMIN";
  913.         }
  914.         
  915.         /*
  916.         var_dump($roles);
  917.         exit;
  918.         */
  919.         
  920.         return $roles;
  921.     }
  922.     
  923.     public function getUsername(): ?string
  924.     {
  925.         return $this->username $this->username "";
  926.     }
  927.     
  928.     public function getPassword ()
  929.     {
  930.         return $this->password;
  931.     }
  932.     
  933.     public function setPassword ($password "")
  934.     {
  935.         $this->password $password;
  936.         return $this;
  937.     }
  938.     
  939.     public function getSalt ()
  940.     {
  941.         // bcrypt generates its own salt
  942.         
  943.         return null;
  944.     }
  945.     
  946.     public function eraseCredentials ()
  947.     {
  948.         
  949.     }
  950.     
  951.     // AdvancedUserInterface
  952.     // =======================
  953.     
  954.     public function isAccountNonExpired ()
  955.     {
  956.         return true;
  957.     }
  958.     
  959.     public function isAccountNonLocked ()
  960.     {
  961.         return true;
  962.     }
  963.     
  964.     public function isCredentialsNonExpired ()
  965.     {
  966.         return true;
  967.     }
  968.     
  969.     public function isEnabled ()
  970.     {
  971.         // return ($this->isActive && (0 < $this->status));
  972.         return ($this->status);
  973.     }
  974.     
  975.     // Serializable
  976.     // ==================
  977.     
  978.     public function serialize ()
  979.     {
  980.         return serialize(array(
  981.             $this->id,
  982.             $this->username,
  983.             $this->password,
  984.             $this->role,
  985.             $this->status,
  986.             // $this->isActive
  987.         ));
  988.     }
  989.     
  990.     public function unserialize ($serialized)
  991.     {
  992.         list (
  993.             $this->id,
  994.             $this->username,
  995.             $this->password,
  996.             $this->role,
  997.             $this->status,
  998.             // $this->isActive
  999.         
  1000.         ) = unserialize($serialized, array ("allowed_classes" => false));
  1001.     }
  1002.     /**
  1003.      * @return Collection|Order[]
  1004.      */
  1005.     public function getPurchases(): Collection
  1006.     {
  1007.         return $this->purchases;
  1008.     }
  1009.     
  1010.     public function getActivePurchase(): ?Purchase
  1011.     {
  1012.         for ($i 0$i count($this->purchases); $i++) {
  1013.             if ($this->purchases[$i]->getStatus() == Purchase::STATUS_ACTIVE) {
  1014.                 return $this->purchases[$i];
  1015.             }
  1016.         }
  1017.         
  1018.         return null;
  1019.     }
  1020.     public function addPurchase(Purchase $order): self
  1021.     {
  1022.         if (!$this->purchases->contains($order)) {
  1023.             $this->purchases[] = $order;
  1024.             $order->setUser($this);
  1025.         }
  1026.         return $this;
  1027.     }
  1028.     public function removePurchase(Purchase $order): self
  1029.     {
  1030.         if ($this->purchases->contains($order)) {
  1031.             $this->purchases->removeElement($order);
  1032.             // set the owning side to null (unless already changed)
  1033.             if ($order->getUser() === $this) {
  1034.                 $order->setUser(null);
  1035.             }
  1036.         }
  1037.         return $this;
  1038.     }
  1039.     
  1040.     public function countCouponUses(Coupon $coupon): int
  1041.     {
  1042.         $count 0;
  1043.         $purchases $this->getPurchases();
  1044.         foreach($purchases as $purchase) {
  1045.             $p_coupons $purchase->getCoupons();
  1046.             if($p_coupons && $p_coupons->contains($coupon)) {
  1047.                 $count++;
  1048.             }
  1049.         }
  1050.         return $count;
  1051.     }
  1052.     
  1053.     /*
  1054.     public function isEqualTo (UserInterface $user) 
  1055.     {
  1056.         if ($this->password !== $user->getPassword()) {
  1057.             return false;
  1058.         }
  1059.         if ($this->salt !== $user->getSalt()) {
  1060.             return false;
  1061.         }
  1062.         if ($this->username !== $user->getUsername()) {
  1063.             return false;
  1064.         }
  1065.         return true;
  1066.     }
  1067.     */
  1068.     
  1069.     /**
  1070.      * @return Collection|Comment[]
  1071.      */
  1072.     public function getComments(): Collection
  1073.     {
  1074.         return $this->comments;
  1075.     }
  1076.     public function addComment(Comment $comment): self
  1077.     {
  1078.         if (!$this->comments->contains($comment)) {
  1079.             $this->comments[] = $comment;
  1080.             $comment->setUser($this);
  1081.         }
  1082.         return $this;
  1083.     }
  1084.     public function removeComment(Comment $comment): self
  1085.     {
  1086.         if ($this->comments->contains($comment)) {
  1087.             $this->comments->removeElement($comment);
  1088.             // set the owning side to null (unless already changed)
  1089.             if ($comment->getUser() === $this) {
  1090.                 $comment->setUser(null);
  1091.             }
  1092.         }
  1093.         return $this;
  1094.     }
  1095.     
  1096.     /**
  1097.      * @return Collection|Traffic[]
  1098.      */
  1099.     public function getTraffic(): Collection
  1100.     {
  1101.         return $this->traffic;
  1102.     }
  1103.     public function addTraffic(Traffic $traffic): self
  1104.     {
  1105.         if (!$this->traffic->contains($traffic)) {
  1106.             $this->traffic[] = $traffic;
  1107.             $traffic->setUser($this);
  1108.         }
  1109.         return $this;
  1110.     }
  1111.     public function removeTraffic(Traffic $traffic): self
  1112.     {
  1113.         if ($this->traffic->contains($traffic)) {
  1114.             $this->traffic->removeElement($traffic);
  1115.             // set the owning side to null (unless already changed)
  1116.             if ($traffic->getUser() === $this) {
  1117.                 $traffic->setUser(null);
  1118.             }
  1119.         }
  1120.         return $this;
  1121.     }
  1122.     
  1123.     public function getContact(): ?Contact
  1124.     {
  1125.         return $this->contact;
  1126.     }
  1127.     public function setContact(?Contact $contact null): self
  1128.     {
  1129.         $this->contact $contact;
  1130.         
  1131.         return $this;
  1132.     }
  1133.     
  1134.     /**
  1135.      * @return Collection|PollResponse[]
  1136.      */
  1137.     public function getPollResponses(): Collection
  1138.     {
  1139.         return $this->pollResponses;
  1140.     }
  1141.     
  1142.     public function addPollResponse(PollResponse $pollResponse): self
  1143.     {
  1144.         if (!$this->pollResponses->contains($pollResponse)) {
  1145.             $this->pollResponses[] = $pollResponse;
  1146.             $pollResponse->setUser($this);
  1147.         }
  1148.         
  1149.         return $this;
  1150.     }
  1151.     
  1152.     public function removePollResponse(PollResponse $pollResponse): self
  1153.     {
  1154.         if ($this->pollResponses->contains($pollResponse)) {
  1155.             $this->pollResponses->removeElement($pollResponse);
  1156.             // set the owning side to null (unless already changed)
  1157.             if ($pollResponse->getUser() === $this) {
  1158.                 $pollResponse->setUser(null);
  1159.             }
  1160.         }
  1161.         
  1162.         return $this;
  1163.     }
  1164.     public function getSiteSignedUpOn(): ?int
  1165.     {
  1166.         return $this->site_signed_up_on;
  1167.     }
  1168.     
  1169.     public function setSiteSignedUpOn(int $site_signed_up_on): self
  1170.     {
  1171.         $this->site_signed_up_on $site_signed_up_on;
  1172.         return $this;
  1173.     }
  1174.     
  1175.     public function getAuthorBio(): string
  1176.     {
  1177.         return $this->author_bio;
  1178.     }
  1179.     public function setAuthorBio(string $author_bio null): self
  1180.     {
  1181.         if (is_null($author_bio)) {
  1182.             $author_bio "";
  1183.         }
  1184.         
  1185.         $this->author_bio $author_bio;
  1186.         return $this;
  1187.     }
  1188. }