<?php
namespace App\Entity;
use App\Dictionary\MemberSex;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Table(name="Member", indexes={
*
* @ORM\Index(name="username_idx", columns={"username"}),
* @ORM\Index(name="sex_idx", columns={"sex"}),
* @ORM\Index(name="is_active_idx", columns={"is_active"})
* }, uniqueConstraints={@ORM\UniqueConstraint(name="username_idx", columns={"username"})})
*
* @ORM\Entity(repositoryClass="App\Repository\MemberRepository")
*
* @ORM\HasLifecycleCallbacks()
*/
class Member
{
/**
* @Groups({"noticeindex", "memberfrontendindex", "memberblockedindex", "activityfeedindex", "conversationdetail", "spamindex", "messageindex", "grouplist", "memberdetail", "waitrating", "contentlist", "phonenumberindex", "operatorindex", "livechatmessageindex", "mediaindex", "massmessageindex"})
*
* @OneToOne(targetEntity="App\Entity\Account", mappedBy="member", cascade={"persist"})
*/
protected $account;
/**
* @OneToOne(targetEntity="App\Entity\Member")
*/
protected $couple_member;
/**
* @Groups({"memberfrontendindex", "activityfeedindex", "membermainphoto", "amateur_search"})
*
* @OneToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"})
*
* @JoinColumn(name="main_photo_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $main_photo;
/**
* @OneToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"})
*
* @JoinColumn(name="main_video_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $main_video;
/**
* @Groups({"memberdetail", "memberperson"})
*
* @OneToOne(targetEntity="Person",cascade={"persist"})
*
* @JoinColumn(name="person_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $person;
/**
* @Exclude()
*
* @OneToMany(targetEntity="BalanceMember", mappedBy="member")
*/
protected $balance_member;
/**
* @Groups({"activityfeedindex", "memberfrontendindex", "memberonlineindex", "amateur_search"})
*
* @ORM\OneToOne(targetEntity="App\Entity\MemberOnline", mappedBy="member")
*/
protected ?MemberOnline $member_online = null;
/**
* This will be set from the MemberSerializer class, if the context for lists is set.
*
* @Groups({"memberfrontendindex"})
*/
protected int $likes = 0;
/**
* @Groups({"lastConversationMessage"})
*/
protected ?\DateTimeInterface $lastConversationMessageAt = null;
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*
* @Groups({"friendshipindex", "commonids", "activityfeedindex", "conversationdetail", "messageindex", "grouplist", "waitrating", "contentlist", "commentlist", "adminindex", "memberindex", "photocheck", "actorlist", "mediaindex", "amateur_search", "video_search", "imageset_search", "likefrontendindex"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @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"})
*/
private $username;
/**
* @Groups({"amateurindex", "memberdetail", "operatormemberdetail", "messengerinbox"})
*
* @ORM\Column(type="datetime")
*/
private $registration_date;
/**
* @ORM\Column(type="date", nullable=true)
*
* @Groups({"memberfrontendindex", "contentlist", "activityfeedindex", "operatorindex", "operatormemberdetail", "messengerinbox"})
*/
private $date_of_birth;
/**
* @Groups({"amateurindex"})
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $amateur_upgrade_date;
/**
* @ORM\Column(type="smallint", nullable=true)
*
* @Groups({"memberfrontendindex", "activityfeedindex", "contentlist", "amateur_search", "grouplist", "commonids", "operatorindex", "operatormemberdetail", "livechatmessageindex"})
*/
private $sex = MemberSex::MALE;
/**
* @Groups({"memberfrontendindex", "memberblockedindex", "accountindex", "adminindex", "mediaindex", "amateur_search"})
*
* @ORM\Column(type="boolean")
*/
private $is_active = true;
/**
* @ORM\Column(type="boolean")
*
* @Groups({"memberfrontendindex", "activityfeedindex", "messageindex", "contentlist", "adminindex", "photocheck", "mediaindex", "amateur_search", "operatorindex", "livechatmessageindex"})
*/
private $is_amateur = false;
/**
* @ORM\Column(type="boolean")
*
* @Groups({"memberfrontendindex", "activityfeedindex", "contentlist", "memberdetail", "amateur_search"})
*/
private $is_webcam_active = false;
/**
* @Groups({"memberdetail"})
*
* @ORM\Column(type="boolean")
*/
private $is_public_profile = true;
/**
* @ORM\Column(type="string", length=4)
*
* @Groups({"memberfrontendindex", "contentlist", "memberdetail", "operatormemberdetail", "amateur_search"})
*/
private $public_country = 'DE';
/**
* @ORM\Column(type="string", length=12, nullable=true)
*
* @Groups({"memberfrontendindex", "contentlist", "memberdetail", "operatormemberdetail", "amateur_search"})
*/
private $public_region;
/**
* @Groups({"memberdetail", "operatormemberdetail"})
*
* @ORM\Column(type="string", length=12, nullable=true)
*/
private $public_zipcode;
/**
* @Groups({"adminreport"})
*
* @ORM\Column(type="string", length=4, nullable=true)
*/
private $tax_country;
/**
* @Exclude()
*
* @ORM\OneToMany(targetEntity="App\Entity\MemberMediaFolder", mappedBy="member", orphanRemoval=true)
*/
private $memberMediaFolders;
/**
* @Groups({"amateur_search"})
*
* @ORM\OneToOne(targetEntity="App\Entity\MemberRanking", mappedBy="member")
*/
private ?MemberRanking $ranking = null;
/**
* This will be set from the MemberSerializer class, if the context for lists is set.
* Used for common values such as weight and height.
*
* @Groups({"memberfrontendindex", "memberdetail"})
*
* @var array
*/
private $profileValues;
/**
* @Groups({"memberdetail", "operatormemberdetail"})
*
* @ORM\OneToOne(targetEntity="App\Entity\MemberInfo", mappedBy="member", cascade={"persist", "remove"})
*/
private $memberInfo;
/**
* @var ArrayCollection
*
* @Exclude()
*
* @ORM\OneToMany(targetEntity="App\Entity\MemberOperator", mappedBy="operator")
*/
private $operators;
/**
* @Groups({"memberfrontendindex", "adminindex"})
*
* @ORM\Column(type="boolean")
*/
private $shallHardcore = false;
/**
* @Groups({"adminindex"})
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $hardcoreReason = "";
public function __construct()
{
$this->setBalanceMember(new ArrayCollection());
$this->memberMediaFolders = new ArrayCollection();
$this->operators = new ArrayCollection();
}
/**
* @return $this
*/
public function setLastConversationMessageAt(?\DateTimeInterface $lastConversationMessageAt): self
{
$this->lastConversationMessageAt = $lastConversationMessageAt;
return $this;
}
/**
* @ORM\PrePersist()
*/
public function prePersist()
{
if (!$this->getRegistrationDate()) {
$this->setRegistrationDate(new \DateTime());
}
}
public function getRegistrationDate(): ?\DateTimeInterface
{
return $this->registration_date;
}
public function setRegistrationDate(\DateTimeInterface $registration_date): self
{
$this->registration_date = $registration_date;
return $this;
}
public function getId()
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
public function getAmateurUpgradeDate(): ?\DateTimeInterface
{
return $this->amateur_upgrade_date;
}
public function setAmateurUpgradeDate(?\DateTimeInterface $amateur_upgrade_date): self
{
$this->amateur_upgrade_date = $amateur_upgrade_date;
return $this;
}
public function getSex(): ?int
{
return $this->sex;
}
public function setSex(?int $sex): self
{
$this->sex = $sex;
return $this;
}
public function getIsWebcamActive(): bool
{
return $this->is_webcam_active;
}
public function setIsWebcamActive(bool $is_webcam_active): self
{
$this->is_webcam_active = $is_webcam_active;
return $this;
}
public function getDateOfBirth(): ?\DateTimeInterface
{
return $this->date_of_birth;
}
public function setDateOfBirth(?\DateTimeInterface $date_of_birth): self
{
$this->date_of_birth = $date_of_birth;
return $this;
}
/**
* @Serializer\VirtualProperty()
*
* @Serializer\Groups({"memberfrontendindex", "contentlist", "activityfeedindex", "operatorindex", "operatormemberdetail", "messengerinbox","amateur_search"})
*/
public function getAge(): int
{
if ($this->date_of_birth instanceof \DateTime) {
$date = $this->date_of_birth->format('Y-m-d');
$age = intval(date('Y', time() - strtotime($date))) - 1970;
return max($age, 18);
}
return 0;
}
public function getIsPublicProfile(): ?bool
{
return $this->is_public_profile;
}
public function setIsPublicProfile(bool $is_public_profile): self
{
$this->is_public_profile = $is_public_profile;
return $this;
}
public function getPublicCountry(): ?string
{
return $this->public_country;
}
public function setPublicCountry(string $public_country): self
{
$this->public_country = strtoupper($public_country);
return $this;
}
public function getPublicRegion(): ?string
{
return $this->public_region;
}
public function setPublicRegion(?string $public_region): self
{
$this->public_region = $public_region;
return $this;
}
public function getCoupleMember(): ?Member
{
return $this->couple_member;
}
public function setCoupleMember(?Member $couple): self
{
$this->couple_member = $couple;
return $this;
}
public function getBalanceMember(): ArrayCollection
{
return $this->balance_member;
}
public function setBalanceMember(ArrayCollection $balance_member): self
{
$this->balance_member = $balance_member;
return $this;
}
/**
* @return ArrayCollection
*/
public function getOperators()
{
return $this->operators;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
public function getMainVideo(): ?MemberMedia
{
return $this->main_video;
}
public function setMainVideo(?MemberMedia $main_video): self
{
$this->main_video = $main_video;
return $this;
}
public function getMainPhoto(): ?MemberMedia
{
return $this->main_photo;
}
public function setMainPhoto(?MemberMedia $main_photo): self
{
$this->main_photo = $main_photo;
return $this;
}
/**
* @Serializer\VirtualProperty()
*
* @Serializer\Groups({"amateur_search"})
*/
public function hasMainPhoto(): bool
{
return null !== $this->main_photo;
}
public function getPublicZipcode(): ?string
{
return $this->public_zipcode;
}
public function setPublicZipcode(?string $public_zipcode): self
{
$this->public_zipcode = $public_zipcode;
return $this;
}
public function getTaxCountry(): ?string
{
return $this->tax_country;
}
public function setTaxCountry(?string $tax_country): self
{
$this->tax_country = $tax_country;
return $this;
}
/**
* Helper method to use from outside (messenger emails etc).
*/
public function isMemberOnline(): bool
{
// quick check: must be active, maybe admin recently disabled him/her
if (!$this->getIsActive()) {
return false;
}
$memberOnline = $this->getMemberOnline();
if (!$memberOnline) {
// seems he or she has never been online
return false;
}
return $memberOnline->getIsOnlineWithBusinessLogic();
}
public function getIsActive(): bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}
public function getMemberOnline(): ?MemberOnline
{
return $this->member_online;
}
public function setMemberOnline(?MemberOnline $memberOnline): self
{
$this->member_online = $memberOnline;
return $this;
}
public function getRanking(): ?MemberRanking
{
return $this->ranking;
}
public function setRanking(?MemberRanking $ranking): self
{
$this->ranking = $ranking;
return $this;
}
/**
* @return Collection|MemberMediaFolder[]
*/
public function getMemberMediaFolders(): Collection
{
return $this->memberMediaFolders;
}
public function addMemberMediaFolder(MemberMediaFolder $memberMediaFolder): self
{
if (!$this->memberMediaFolders->contains($memberMediaFolder)) {
$this->memberMediaFolders[] = $memberMediaFolder;
$memberMediaFolder->setMember($this);
}
return $this;
}
public function removeMemberMediaFolder(MemberMediaFolder $memberMediaFolder): self
{
if ($this->memberMediaFolders->contains($memberMediaFolder)) {
$this->memberMediaFolders->removeElement($memberMediaFolder);
// set the owning side to null (unless already changed)
if ($memberMediaFolder->getMember() === $this) {
$memberMediaFolder->setMember(null);
}
}
return $this;
}
/**
* @return $this
*/
public function addProfileValue(MemberProfileValue $value): self
{
$collection = $this->getProfileValues();
if (!$collection->contains($value)) {
$collection->add($value);
}
return $this;
}
public function getProfileValues(): ArrayCollection
{
if (null === $this->profileValues) {
$this->profileValues = new ArrayCollection();
}
return $this->profileValues;
}
public function getLikes(): int
{
return $this->likes;
}
/**
* @return $this
*/
public function setLikes(int $likes): self
{
$this->likes = $likes;
return $this;
}
public function getMemberInfo(): ?MemberInfo
{
return $this->memberInfo;
}
public function setMemberInfo(MemberInfo $memberInfo): self
{
$this->memberInfo = $memberInfo;
// set the owning side of the relation if necessary
if ($this !== $memberInfo->getMember()) {
$memberInfo->setMember($this);
}
return $this;
}
public function getFrontendApiKey(string $memberPropertySalt = ''): ?string
{
if (!$this->getIsAmateur() || !$this->getIsActive()) {
return null;
}
if (!$this->registration_date instanceof \DateTimeInterface || !$this->amateur_upgrade_date instanceof \DateTimeInterface) {
return null;
}
if (empty($memberPropertySalt)) {
return null;
}
return hash(
'sha224',// If changing algo here, also change in the DB query!
$this->username .
$this->registration_date->format('Y-m-d H:i:s') .
$this->amateur_upgrade_date->format('Y-m-d H:i:s') .
((string)$this->getAccount()?->getPassword()) . // When user changes password, also changes api-key
$memberPropertySalt // Allows changing FE api key for some reason
);
}
public function getIsAmateur(): bool
{
return $this->is_amateur;
}
public function setIsAmateur(bool $is_amateur): self
{
$this->is_amateur = $is_amateur;
return $this;
}
public function getAccount(): ?Account
{
return $this->account;
}
public function setAccount(Account $account): self
{
$this->account = $account;
return $this;
}
/**
* @return mixed
*/
public function getShallHardcore()
{
return $this->shallHardcore;
}
/**
* @param mixed $shallHardcore
* @return self
*/
public function setShallHardcore($shallHardcore): self
{
$this->shallHardcore = $shallHardcore;
return $this;
}
/**
* @return mixed
*/
public function getHardcoreReason()
{
return $this->hardcoreReason;
}
/**
* @param mixed $hardcoreReason
* @return self
*/
public function setHardcoreReason($hardcoreReason): self
{
$this->hardcoreReason = $hardcoreReason;
return $this;
}
}