src/Entity/Member.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Dictionary\MemberSex;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\JoinColumn;
  8. use Doctrine\ORM\Mapping\OneToMany;
  9. use Doctrine\ORM\Mapping\OneToOne;
  10. use JMS\Serializer\Annotation as Serializer;
  11. use JMS\Serializer\Annotation\Exclude;
  12. use JMS\Serializer\Annotation\Groups;
  13. /**
  14.  * @ORM\Table(name="Member", indexes={
  15.  *
  16.  *   @ORM\Index(name="username_idx", columns={"username"}),
  17.  *   @ORM\Index(name="sex_idx", columns={"sex"}),
  18.  *   @ORM\Index(name="is_active_idx", columns={"is_active"})
  19.  * }, uniqueConstraints={@ORM\UniqueConstraint(name="username_idx", columns={"username"})})
  20.  *
  21.  * @ORM\Entity(repositoryClass="App\Repository\MemberRepository")
  22.  *
  23.  * @ORM\HasLifecycleCallbacks()
  24.  */
  25. class Member
  26. {
  27.     /**
  28.      * @Groups({"noticeindex", "memberfrontendindex", "memberblockedindex", "activityfeedindex", "conversationdetail", "spamindex", "messageindex", "grouplist", "memberdetail", "waitrating", "contentlist", "phonenumberindex", "operatorindex", "livechatmessageindex", "mediaindex", "massmessageindex"})
  29.      *
  30.      * @OneToOne(targetEntity="App\Entity\Account", mappedBy="member", cascade={"persist"})
  31.      */
  32.     protected $account;
  33.     /**
  34.      * @OneToOne(targetEntity="App\Entity\Member")
  35.      */
  36.     protected $couple_member;
  37.     /**
  38.      * @Groups({"memberfrontendindex", "activityfeedindex", "membermainphoto", "amateur_search"})
  39.      *
  40.      * @OneToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"})
  41.      *
  42.      * @JoinColumn(name="main_photo_id", referencedColumnName="id", onDelete="SET NULL")
  43.      */
  44.     protected $main_photo;
  45.     /**
  46.      * @OneToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"})
  47.      *
  48.      * @JoinColumn(name="main_video_id", referencedColumnName="id", onDelete="SET NULL")
  49.      */
  50.     protected $main_video;
  51.     /**
  52.      * @Groups({"memberdetail", "memberperson"})
  53.      *
  54.      * @OneToOne(targetEntity="Person",cascade={"persist"})
  55.      *
  56.      * @JoinColumn(name="person_id", referencedColumnName="id", onDelete="SET NULL")
  57.      */
  58.     protected $person;
  59.     /**
  60.      * @Exclude()
  61.      *
  62.      * @OneToMany(targetEntity="BalanceMember", mappedBy="member")
  63.      */
  64.     protected $balance_member;
  65.     /**
  66.      * @Groups({"activityfeedindex", "memberfrontendindex", "memberonlineindex", "amateur_search"})
  67.      *
  68.      * @ORM\OneToOne(targetEntity="App\Entity\MemberOnline", mappedBy="member")
  69.      */
  70.     protected ?MemberOnline $member_online null;
  71.     /**
  72.      * This will be set from the MemberSerializer class, if the context for lists is set.
  73.      *
  74.      * @Groups({"memberfrontendindex"})
  75.      */
  76.     protected int $likes 0;
  77.     /**
  78.      * @Groups({"lastConversationMessage"})
  79.      */
  80.     protected ?\DateTimeInterface $lastConversationMessageAt null;
  81.     /**
  82.      * @ORM\Id()
  83.      *
  84.      * @ORM\GeneratedValue()
  85.      *
  86.      * @ORM\Column(type="integer")
  87.      *
  88.      * @Groups({"friendshipindex", "commonids", "activityfeedindex", "conversationdetail", "messageindex", "grouplist", "waitrating", "contentlist", "commentlist", "adminindex", "memberindex", "photocheck", "actorlist", "mediaindex", "amateur_search", "video_search", "imageset_search", "likefrontendindex"})
  89.      */
  90.     private $id;
  91.     /**
  92.      * @ORM\Column(type="string", length=255, nullable=true)
  93.      *
  94.      * @Groups({"webmasterstats", "memberfrontendindex", "memberblockedindex", "grouppostindex", "activityfeedindex", "conversationdetail", "messageindex", "grouplist", "waitrating", "contentlist", "commentlist", "adminindex", "memberindex", "amateurupgradeindex", "photocheck", "actorlist", "mediaindex", "amateur_search", "video_search", "imageset_search", "logindetails", "operatorindex"})
  95.      */
  96.     private $username;
  97.     /**
  98.      * @Groups({"amateurindex", "memberdetail", "operatormemberdetail", "messengerinbox"})
  99.      *
  100.      * @ORM\Column(type="datetime")
  101.      */
  102.     private $registration_date;
  103.     /**
  104.      * @ORM\Column(type="date", nullable=true)
  105.      *
  106.      * @Groups({"memberfrontendindex", "contentlist", "activityfeedindex", "operatorindex", "operatormemberdetail", "messengerinbox"})
  107.      */
  108.     private $date_of_birth;
  109.     /**
  110.      * @Groups({"amateurindex"})
  111.      *
  112.      * @ORM\Column(type="datetime", nullable=true)
  113.      */
  114.     private $amateur_upgrade_date;
  115.     /**
  116.      * @ORM\Column(type="smallint", nullable=true)
  117.      *
  118.      * @Groups({"memberfrontendindex", "activityfeedindex", "contentlist", "amateur_search", "grouplist", "commonids", "operatorindex", "operatormemberdetail", "livechatmessageindex"})
  119.      */
  120.     private $sex MemberSex::MALE;
  121.     /**
  122.      * @Groups({"memberfrontendindex", "memberblockedindex", "accountindex", "adminindex", "mediaindex", "amateur_search"})
  123.      *
  124.      * @ORM\Column(type="boolean")
  125.      */
  126.     private $is_active true;
  127.     /**
  128.      * @ORM\Column(type="boolean")
  129.      *
  130.      * @Groups({"memberfrontendindex", "activityfeedindex", "messageindex", "contentlist", "adminindex", "photocheck", "mediaindex", "amateur_search", "operatorindex", "livechatmessageindex"})
  131.      */
  132.     private $is_amateur false;
  133.     /**
  134.      * @ORM\Column(type="boolean")
  135.      *
  136.      * @Groups({"memberfrontendindex", "activityfeedindex", "contentlist", "memberdetail", "amateur_search"})
  137.      */
  138.     private $is_webcam_active false;
  139.     /**
  140.      * @Groups({"memberdetail"})
  141.      *
  142.      * @ORM\Column(type="boolean")
  143.      */
  144.     private $is_public_profile true;
  145.     /**
  146.      * @ORM\Column(type="string", length=4)
  147.      *
  148.      * @Groups({"memberfrontendindex", "contentlist", "memberdetail", "operatormemberdetail", "amateur_search"})
  149.      */
  150.     private $public_country 'DE';
  151.     /**
  152.      * @ORM\Column(type="string", length=12, nullable=true)
  153.      *
  154.      * @Groups({"memberfrontendindex", "contentlist", "memberdetail", "operatormemberdetail", "amateur_search"})
  155.      */
  156.     private $public_region;
  157.     /**
  158.      * @Groups({"memberdetail", "operatormemberdetail"})
  159.      *
  160.      * @ORM\Column(type="string", length=12, nullable=true)
  161.      */
  162.     private $public_zipcode;
  163.     /**
  164.      * @Groups({"adminreport"})
  165.      *
  166.      * @ORM\Column(type="string", length=4, nullable=true)
  167.      */
  168.     private $tax_country;
  169.     /**
  170.      * @Exclude()
  171.      *
  172.      * @ORM\OneToMany(targetEntity="App\Entity\MemberMediaFolder", mappedBy="member", orphanRemoval=true)
  173.      */
  174.     private $memberMediaFolders;
  175.     /**
  176.      * @Groups({"amateur_search"})
  177.      *
  178.      * @ORM\OneToOne(targetEntity="App\Entity\MemberRanking", mappedBy="member")
  179.      */
  180.     private ?MemberRanking $ranking null;
  181.     /**
  182.      * This will be set from the MemberSerializer class, if the context for lists is set.
  183.      * Used for common values such as weight and height.
  184.      *
  185.      * @Groups({"memberfrontendindex", "memberdetail"})
  186.      *
  187.      * @var array
  188.      */
  189.     private $profileValues;
  190.     /**
  191.      * @Groups({"memberdetail", "operatormemberdetail"})
  192.      *
  193.      * @ORM\OneToOne(targetEntity="App\Entity\MemberInfo", mappedBy="member", cascade={"persist", "remove"})
  194.      */
  195.     private $memberInfo;
  196.     /**
  197.      * @var ArrayCollection
  198.      *
  199.      * @Exclude()
  200.      *
  201.      * @ORM\OneToMany(targetEntity="App\Entity\MemberOperator", mappedBy="operator")
  202.      */
  203.     private $operators;
  204.     /**
  205.      * @Groups({"memberfrontendindex", "adminindex"})
  206.      *
  207.      * @ORM\Column(type="boolean")
  208.      */
  209.     private $shallHardcore false;
  210.     /**
  211.      * @Groups({"adminindex"})
  212.      *
  213.      * @ORM\Column(type="string", length=255, nullable=true)
  214.      */
  215.     private $hardcoreReason "";
  216.     public function __construct()
  217.     {
  218.         $this->setBalanceMember(new ArrayCollection());
  219.         $this->memberMediaFolders = new ArrayCollection();
  220.         $this->operators = new ArrayCollection();
  221.     }
  222.     /**
  223.      * @return $this
  224.      */
  225.     public function setLastConversationMessageAt(?\DateTimeInterface $lastConversationMessageAt): self
  226.     {
  227.         $this->lastConversationMessageAt $lastConversationMessageAt;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @ORM\PrePersist()
  232.      */
  233.     public function prePersist()
  234.     {
  235.         if (!$this->getRegistrationDate()) {
  236.             $this->setRegistrationDate(new \DateTime());
  237.         }
  238.     }
  239.     public function getRegistrationDate(): ?\DateTimeInterface
  240.     {
  241.         return $this->registration_date;
  242.     }
  243.     public function setRegistrationDate(\DateTimeInterface $registration_date): self
  244.     {
  245.         $this->registration_date $registration_date;
  246.         return $this;
  247.     }
  248.     public function getId()
  249.     {
  250.         return $this->id;
  251.     }
  252.     public function getUsername(): ?string
  253.     {
  254.         return $this->username;
  255.     }
  256.     public function setUsername(?string $username): self
  257.     {
  258.         $this->username $username;
  259.         return $this;
  260.     }
  261.     public function getAmateurUpgradeDate(): ?\DateTimeInterface
  262.     {
  263.         return $this->amateur_upgrade_date;
  264.     }
  265.     public function setAmateurUpgradeDate(?\DateTimeInterface $amateur_upgrade_date): self
  266.     {
  267.         $this->amateur_upgrade_date $amateur_upgrade_date;
  268.         return $this;
  269.     }
  270.     public function getSex(): ?int
  271.     {
  272.         return $this->sex;
  273.     }
  274.     public function setSex(?int $sex): self
  275.     {
  276.         $this->sex $sex;
  277.         return $this;
  278.     }
  279.     public function getIsWebcamActive(): bool
  280.     {
  281.         return $this->is_webcam_active;
  282.     }
  283.     public function setIsWebcamActive(bool $is_webcam_active): self
  284.     {
  285.         $this->is_webcam_active $is_webcam_active;
  286.         return $this;
  287.     }
  288.     public function getDateOfBirth(): ?\DateTimeInterface
  289.     {
  290.         return $this->date_of_birth;
  291.     }
  292.     public function setDateOfBirth(?\DateTimeInterface $date_of_birth): self
  293.     {
  294.         $this->date_of_birth $date_of_birth;
  295.         return $this;
  296.     }
  297.     /**
  298.      * @Serializer\VirtualProperty()
  299.      *
  300.      * @Serializer\Groups({"memberfrontendindex", "contentlist", "activityfeedindex", "operatorindex", "operatormemberdetail", "messengerinbox","amateur_search"})
  301.      */
  302.     public function getAge(): int
  303.     {
  304.         if ($this->date_of_birth instanceof \DateTime) {
  305.             $date $this->date_of_birth->format('Y-m-d');
  306.             $age intval(date('Y'time() - strtotime($date))) - 1970;
  307.             return max($age18);
  308.         }
  309.         return 0;
  310.     }
  311.     public function getIsPublicProfile(): ?bool
  312.     {
  313.         return $this->is_public_profile;
  314.     }
  315.     public function setIsPublicProfile(bool $is_public_profile): self
  316.     {
  317.         $this->is_public_profile $is_public_profile;
  318.         return $this;
  319.     }
  320.     public function getPublicCountry(): ?string
  321.     {
  322.         return $this->public_country;
  323.     }
  324.     public function setPublicCountry(string $public_country): self
  325.     {
  326.         $this->public_country strtoupper($public_country);
  327.         return $this;
  328.     }
  329.     public function getPublicRegion(): ?string
  330.     {
  331.         return $this->public_region;
  332.     }
  333.     public function setPublicRegion(?string $public_region): self
  334.     {
  335.         $this->public_region $public_region;
  336.         return $this;
  337.     }
  338.     public function getCoupleMember(): ?Member
  339.     {
  340.         return $this->couple_member;
  341.     }
  342.     public function setCoupleMember(?Member $couple): self
  343.     {
  344.         $this->couple_member $couple;
  345.         return $this;
  346.     }
  347.     public function getBalanceMember(): ArrayCollection
  348.     {
  349.         return $this->balance_member;
  350.     }
  351.     public function setBalanceMember(ArrayCollection $balance_member): self
  352.     {
  353.         $this->balance_member $balance_member;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return ArrayCollection
  358.      */
  359.     public function getOperators()
  360.     {
  361.         return $this->operators;
  362.     }
  363.     public function getPerson(): ?Person
  364.     {
  365.         return $this->person;
  366.     }
  367.     public function setPerson(?Person $person): self
  368.     {
  369.         $this->person $person;
  370.         return $this;
  371.     }
  372.     public function getMainVideo(): ?MemberMedia
  373.     {
  374.         return $this->main_video;
  375.     }
  376.     public function setMainVideo(?MemberMedia $main_video): self
  377.     {
  378.         $this->main_video $main_video;
  379.         return $this;
  380.     }
  381.     public function getMainPhoto(): ?MemberMedia
  382.     {
  383.         return $this->main_photo;
  384.     }
  385.     public function setMainPhoto(?MemberMedia $main_photo): self
  386.     {
  387.         $this->main_photo $main_photo;
  388.         return $this;
  389.     }
  390.     /**
  391.      * @Serializer\VirtualProperty()
  392.      *
  393.      * @Serializer\Groups({"amateur_search"})
  394.      */
  395.     public function hasMainPhoto(): bool
  396.     {
  397.         return null !== $this->main_photo;
  398.     }
  399.     public function getPublicZipcode(): ?string
  400.     {
  401.         return $this->public_zipcode;
  402.     }
  403.     public function setPublicZipcode(?string $public_zipcode): self
  404.     {
  405.         $this->public_zipcode $public_zipcode;
  406.         return $this;
  407.     }
  408.     public function getTaxCountry(): ?string
  409.     {
  410.         return $this->tax_country;
  411.     }
  412.     public function setTaxCountry(?string $tax_country): self
  413.     {
  414.         $this->tax_country $tax_country;
  415.         return $this;
  416.     }
  417.     /**
  418.      * Helper method to use from outside (messenger emails etc).
  419.      */
  420.     public function isMemberOnline(): bool
  421.     {
  422.         // quick check: must be active, maybe admin recently disabled him/her
  423.         if (!$this->getIsActive()) {
  424.             return false;
  425.         }
  426.         $memberOnline $this->getMemberOnline();
  427.         if (!$memberOnline) {
  428.             // seems he or she has never been online
  429.             return false;
  430.         }
  431.         return $memberOnline->getIsOnlineWithBusinessLogic();
  432.     }
  433.     public function getIsActive(): bool
  434.     {
  435.         return $this->is_active;
  436.     }
  437.     public function setIsActive(bool $is_active): self
  438.     {
  439.         $this->is_active $is_active;
  440.         return $this;
  441.     }
  442.     public function getMemberOnline(): ?MemberOnline
  443.     {
  444.         return $this->member_online;
  445.     }
  446.     public function setMemberOnline(?MemberOnline $memberOnline): self
  447.     {
  448.         $this->member_online $memberOnline;
  449.         return $this;
  450.     }
  451.     public function getRanking(): ?MemberRanking
  452.     {
  453.         return $this->ranking;
  454.     }
  455.     public function setRanking(?MemberRanking $ranking): self
  456.     {
  457.         $this->ranking $ranking;
  458.         return $this;
  459.     }
  460.     /**
  461.      * @return Collection|MemberMediaFolder[]
  462.      */
  463.     public function getMemberMediaFolders(): Collection
  464.     {
  465.         return $this->memberMediaFolders;
  466.     }
  467.     public function addMemberMediaFolder(MemberMediaFolder $memberMediaFolder): self
  468.     {
  469.         if (!$this->memberMediaFolders->contains($memberMediaFolder)) {
  470.             $this->memberMediaFolders[] = $memberMediaFolder;
  471.             $memberMediaFolder->setMember($this);
  472.         }
  473.         return $this;
  474.     }
  475.     public function removeMemberMediaFolder(MemberMediaFolder $memberMediaFolder): self
  476.     {
  477.         if ($this->memberMediaFolders->contains($memberMediaFolder)) {
  478.             $this->memberMediaFolders->removeElement($memberMediaFolder);
  479.             // set the owning side to null (unless already changed)
  480.             if ($memberMediaFolder->getMember() === $this) {
  481.                 $memberMediaFolder->setMember(null);
  482.             }
  483.         }
  484.         return $this;
  485.     }
  486.     /**
  487.      * @return $this
  488.      */
  489.     public function addProfileValue(MemberProfileValue $value): self
  490.     {
  491.         $collection $this->getProfileValues();
  492.         if (!$collection->contains($value)) {
  493.             $collection->add($value);
  494.         }
  495.         return $this;
  496.     }
  497.     public function getProfileValues(): ArrayCollection
  498.     {
  499.         if (null === $this->profileValues) {
  500.             $this->profileValues = new ArrayCollection();
  501.         }
  502.         return $this->profileValues;
  503.     }
  504.     public function getLikes(): int
  505.     {
  506.         return $this->likes;
  507.     }
  508.     /**
  509.      * @return $this
  510.      */
  511.     public function setLikes(int $likes): self
  512.     {
  513.         $this->likes $likes;
  514.         return $this;
  515.     }
  516.     public function getMemberInfo(): ?MemberInfo
  517.     {
  518.         return $this->memberInfo;
  519.     }
  520.     public function setMemberInfo(MemberInfo $memberInfo): self
  521.     {
  522.         $this->memberInfo $memberInfo;
  523.         // set the owning side of the relation if necessary
  524.         if ($this !== $memberInfo->getMember()) {
  525.             $memberInfo->setMember($this);
  526.         }
  527.         return $this;
  528.     }
  529.     public function getFrontendApiKey(string $memberPropertySalt ''): ?string
  530.     {
  531.         if (!$this->getIsAmateur() || !$this->getIsActive()) {
  532.             return null;
  533.         }
  534.         if (!$this->registration_date instanceof \DateTimeInterface || !$this->amateur_upgrade_date instanceof \DateTimeInterface) {
  535.             return null;
  536.         }
  537.         if (empty($memberPropertySalt)) {
  538.             return null;
  539.         }
  540.         return hash(
  541.             'sha224',// If changing algo here, also change in the DB query!
  542.             $this->username .
  543.             $this->registration_date->format('Y-m-d H:i:s') .
  544.             $this->amateur_upgrade_date->format('Y-m-d H:i:s') .
  545.             ((string)$this->getAccount()?->getPassword()) . // When user changes password, also changes api-key
  546.             $memberPropertySalt // Allows changing FE api key for some reason
  547.         );
  548.     }
  549.     public function getIsAmateur(): bool
  550.     {
  551.         return $this->is_amateur;
  552.     }
  553.     public function setIsAmateur(bool $is_amateur): self
  554.     {
  555.         $this->is_amateur $is_amateur;
  556.         return $this;
  557.     }
  558.     public function getAccount(): ?Account
  559.     {
  560.         return $this->account;
  561.     }
  562.     public function setAccount(Account $account): self
  563.     {
  564.         $this->account $account;
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return mixed
  569.      */
  570.     public function getShallHardcore()
  571.     {
  572.         return $this->shallHardcore;
  573.     }
  574.     /**
  575.      * @param mixed $shallHardcore
  576.      * @return self
  577.      */
  578.     public function setShallHardcore($shallHardcore): self
  579.     {
  580.         $this->shallHardcore $shallHardcore;
  581.         return $this;
  582.     }
  583.     /**
  584.      * @return mixed
  585.      */
  586.     public function getHardcoreReason()
  587.     {
  588.         return $this->hardcoreReason;
  589.     }
  590.     /**
  591.      * @param mixed $hardcoreReason
  592.      * @return self
  593.      */
  594.     public function setHardcoreReason($hardcoreReason): self
  595.     {
  596.         $this->hardcoreReason $hardcoreReason;
  597.         return $this;
  598.     }
  599. }