<?php
// src/Entity/User.php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\File;
use SpecShaper\EncryptBundle\Annotations\Encrypted;
use Doctrine\Common\Collections\Criteria;
use FOS\UserBundle\Model\User as BaseUser;
use App\Entity\Cart;
/**
* @ORM\Table(name="app_users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity(fields="email", message="Email already taken")
* @UniqueEntity(fields="displayName", message="Votre usagé est déja pris")
*
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="datetime")
*/
private $dateCreated;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $displayName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=4)
*/
private $lang='fr';
/**
* @ORM\OneToMany(targetEntity="App\Entity\Notification", mappedBy="user", orphanRemoval=true, cascade={"remove"})
* @ORM\OrderBy({"dateCreated" = "DESC"})
*/
private $notifications;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Image",orphanRemoval=true, cascade={"remove"})
*/
private $profileImage;
/**
* @ORM\Column(type="boolean")
*/
private $settingsReceiveMessageNotification=true;
/**
* @ORM\Column(name="facebook_id", type="string", length=255, nullable=true)
*/
private $facebookId;
private $facebookAccessToken;
/**
* @ORM\Column(name="google_id", type="string", length=255, nullable=true)
*/
private $googleId;
private $googleAccessToken;
/**
* @ORM\Column(name="linkedin_id", type="string", length=255, nullable=true)
*/
private $linkedinId;
private $linkedinAccessToken;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserVariables", mappedBy="user", cascade={"remove"}, orphanRemoval=true)
*/
private $variables;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="usersAdmin")
*/
private $adminOfCompanies;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserShippingLocation", mappedBy="user", cascade={"persist", "remove"})
*/
private $shippingAddresses;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserSearch", mappedBy="user", orphanRemoval=true)
*/
private $searches;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserViewedProduct", mappedBy="user", orphanRemoval=true)
*/
private $viewedProducts;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $termsAcceptanceDate;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $termsAcceptanceIp;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="userPaying")
*/
private $transactionsPaid;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FinancialLog", mappedBy="userReceiving")
*/
private $transactionsReceived;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Encrypted
*/
private $stripeAccountId;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserFavorite", mappedBy="user", orphanRemoval=true, cascade={"remove"})
*/
private $favorites;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Cart", mappedBy="user", orphanRemoval=true, cascade={"persist"})
*/
private $carts;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Image", mappedBy="user", orphanRemoval=true)
*/
private $images;
/**
* @ORM\Column(type="boolean")
*/
private $isBetaTester=false;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\CartCoupon", inversedBy="usedByUsers")
*/
private $couponsUsed;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $paymentLast4digits;
/**
* @ORM\OneToMany(targetEntity="App\Entity\RecurringOrder", mappedBy="user", orphanRemoval=true)
*/
private $recurringOrders;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CartCoupon", mappedBy="forUser")
*/
private $cartCoupons;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="usersReferred")
*/
private $referredBy;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="referredBy")
*/
private $usersReferred;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Subscription", mappedBy="forUser")
*/
private $subscriptions;
/**
* @ORM\Column(type="boolean")
*/
private $IsARecruiter=false;
/**
* @ORM\Column(type="boolean")
*/
private $isHri=false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Company", mappedBy="recruiter")
*/
private $companiesRecruited;
/**
* @ORM\OneToMany(targetEntity="App\Entity\EmailSent", mappedBy="user")
*/
private $emailReceiveds;
/**
* @ORM\Column(type="boolean")
* LEGACY TO BE REMOVED
*/
private $isAllowedToMakeGroups=false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* LEGACY TO BE REMOVED
*/
private $makeGroupName;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Company", mappedBy="inGroupOfUser")
* LEGACY TO BE REMOVED
*/
private $myGroupOfCompanies;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\CompanyAssociation", inversedBy="adminUsers")
*/
private $AdminOfCompanyAssociations;
/**
* @ORM\Column(type="boolean")
*/
private $isAllowedToMakeCompanyForAssociation=false;
// /**
// * @ORM\Column(type="string")
// */
// protected $confirmationToken;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CompanyAssociation", inversedBy="usersAddingCompanies")
*/
private $makeCompanyForAssociation;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $hasReusableBox=false;
/*
* @ORM\OneToMany(targetEntity="App\Entity\Message", mappedBy="userTo",orphanRemoval=true, cascade={"remove"})
*/
//private $messages;
//$this->messages = new ArrayCollection();
/**
* @ORM\Column(type="boolean")
*/
private $reminderCouponSent = false;
/**
* @ORM\OneToOne(targetEntity="App\Entity\UserSurvey", mappedBy="user", cascade={"persist", "remove"})
*/
private $userSurvey;
/**
* @ORM\Column(type="datetime")
*/
private $nextUserSurveyTime;
/**
* @ORM\Column(type="boolean")
*/
private $dontShowSurvey = false;
/**
* @ORM\Column(type="boolean")
*/
private $userSubscriptionMaturin = false;
/**
* @ORM\Column(type="datetime")
*/
private $dateLogSubscriptionMaturin;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Encrypted
*/
private $subscriptionStripeId;
public function __construct(){
$this->dateCreated = new \DateTime();
$this->roles = array('ROLE_ADMIN');
$this->variables = new ArrayCollection();
$this->date = new ArrayCollection();
$this->adminOfCompanies= new ArrayCollection();
$this->shippingAddresses = new ArrayCollection();
$this->searches = new ArrayCollection();
$this->viewedProducts = new ArrayCollection();
$this->transactionsPaid = new ArrayCollection();
$this->transactionsReceived = new ArrayCollection();
$this->favorites = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->images = new ArrayCollection();
$this->couponsUsed = new ArrayCollection();
$this->recurringOrders = new ArrayCollection();
$this->cartCoupons = new ArrayCollection();
$this->usersReferred = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->companiesRecruited = new ArrayCollection();
$this->emailReceiveds = new ArrayCollection();
$this->myGroupOfCompanies = new ArrayCollection();
$this->AdminOfCompanyAssociations = new ArrayCollection();
}
public function getLoginType(){
if(!empty($this->googleAccessToken))
return 'google';
if(!empty($this->facebookAccessToken))
return 'facebook';
if(!empty($this->linkedinAccessToken))
return 'linkedin';
return 'form';
}
public function setId($id)
{
$this->id = $id;
}
public function setEmail($email)
{
$email = is_null($email) ? '' : $email;
parent::setEmail($email);
$this->setUsername($email);
return $this;
}
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
}
public function getDateCreated()
{
return $this->dateCreated;
}
public function setFacebookId($facebookId)
{
$this->facebookId = $facebookId;
}
public function getFacebookId()
{
return $this->facebookId;
}
public function setFacebookAccessToken($facebookAccessToken)
{
$this->facebookAccessToken = $facebookAccessToken;
}
public function getFacebookAccessToken()
{
return $this->facebookAccessToken;
}
public function setGoogleId($googleId)
{
$this->googleId = $googleId;
}
public function getGoogleId()
{
return $this->googleId;
}
public function setGoogleAccessToken($googleAccessToken)
{
$this->googleAccessToken = $googleAccessToken;
}
public function getGoogleAccessToken()
{
return $this->googleAccessToken;
}
public function setLinkedinId($linkedinId)
{
$this->linkedinId = $linkedinId;
}
public function getLinkedinId()
{
return $this->linkedinId;
}
public function setLinkedinAccessToken($linkedinAccessToken)
{
$this->linkedinAccessToken = $linkedinAccessToken;
}
public function getLinkedinAccessToken()
{
return $this->linkedinAccessToken;
}
public function setSettingsReceiveMessageNotification($settingsReceiveMessageNotification)
{
$this->settingsReceiveMessageNotification = $settingsReceiveMessageNotification;
}
public function getSettingsReceiveMessageNotification()
{
return $this->settingsReceiveMessageNotification;
}
public function getId()
{
return $this->id;
}
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
public function getFirstName()
{
return $this->firstName;
}
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
public function getLastName()
{
return $this->lastName;
}
public function getFullName(){
return $this->firstName.' '.$this->lastName;
}
public function setPhone($phone)
{
$this->phone = $phone;
}
public function getDisplayName(){
if(empty($this->displayName)){
if(!empty($this->firstName) || !empty($this->lastName)){
$username = substr($this->firstName, 0, 1).'.'.$this->lastName;
}else{
if(!empty($this->getEmail()))
$username = current(explode('@', $this->getEmail()));
}
}else
$username = $this->displayName;
if(!empty($username))
return ucfirst($username);
else
return '';
}
public function setdisplayName($name){
$this->displayName = $name;
}
public function getPhone()
{
if(!empty($this->phone))
return $this->phone;
if($this->getShippingAddresses()->count() > 0){
return $this->getShippingAddresses()->first()->getPhone();
}
return null;
}
public function setLocale($lang)
{
$this->lang = $lang;
}
public function getLocale()
{
return $this->lang;
}
public function getLang()
{
return $this->lang;
}
public function setLang()
{
return $this->lang;
}
public function setNotifications($notifications)
{
$this->notifications = $notifications;
}
public function getNotifications()
{
return $this->notifications;
}
public function setProfileImage($profileImage)
{
if($profileImage === false)
$profileImage = null;
$this->profileImage = $profileImage;
}
public function getProfileImage()
{
return $this->profileImage;
}
/**
* @return Collection|UserVariables[]
*/
public function getVariables(): Collection
{
return $this->variables;
}
public function getVariable($varname, $category=false){
foreach($this->variables as $variable){
if($category){
if( ($variable->getName() == $varname) && ($variable->getCategory() == $category))
return $variable;
}else{
if($variable->getName() == $varname)
return $variable;
}
}
return false;
}
/*
* @TODO Find the variable and set the right one
*/
public function setVariable(UserVariables $variable){
return $this->addVariable($variable);
}
public function addVariable(UserVariables $variable): self
{
if (!$this->variables->contains($variable)) {
$this->variables[] = $variable;
$variable->setUser($this);
}else{
foreach($this->variables as $key => $var){
if($var->getName() == $variable->getName() && $var->getCategory() && $variable->getCategory())
$this->variables->get($key)->setValue($variable->getValue());
}
}
return $this;
}
public function removeVariable(UserVariables $variable): self
{
if ($this->variables->contains($variable)) {
$this->variables->removeElement($variable);
// set the owning side to null (unless already changed)
if ($variable->getUser() === $this) {
$variable->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Company[]
*/
public function getProducts(): Collection
{
$combined = array();
foreach ($this->getCompanies() as $c){
$combined = array_merge($combined, $c->getProducts()->toArray());
}
return new ArrayCollection($combined);
}
/**
* @return Collection|Company[]
*/
public function getCompanies(): Collection
{
if(!empty($this->getMakeCompanyForAssociation())){
$companies = $this->adminOfCompanies;
foreach($this->getMakeCompanyForAssociation()->getCompanies() as $c){
if(!$companies->contains($c))
$companies[] = $c;
}
return $companies;
}else
return $this->adminOfCompanies;
}
public function addCompany(Company $company): self
{
if (!$this->adminOfCompanies->contains($company)) {
$this->adminOfCompanies[] = $company;
$company->addAdminUser($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->adminOfCompanies->contains($company)) {
$this->adminOfCompanies->removeElement($company);
$company->removeAdminUsers($this);
}
return $this;
}
public function getAdminOfCompanies(): Collection
{
return $this->adminOfCompanies;
}
public function addAdminOfCompany(Company $company): self
{
if (!$this->adminOfCompanies->contains($company)) {
$this->adminOfCompanies[] = $company;
$company->addAdminUser($this);
}
return $this;
}
public function removeAdminOfCompany(Company $company): self
{
if ($this->adminOfCompanies->contains($company)) {
$this->adminOfCompanies->removeElement($company);
$company->removeAdminUsers($this);
}
return $this;
}
/**
* @return Collection|UserShippingLocation[]
*/
public function getShippingAddresses(): Collection
{
return $this->shippingAddresses;
}
public function getValidShippingAddresses(): Array
{
$validShippingAddresses = [];
$shippingAddresses = $this->shippingAddresses;
foreach($shippingAddresses as $shippingAddresse) {
if ($shippingAddresse->isCityValid()) {
$validShippingAddresses[] = $shippingAddresse;
}
}
return $validShippingAddresses;
}
public function addShippingAddress(UserShippingLocation $shippingAddress): self
{
if (!$this->shippingAddresses->contains($shippingAddress)) {
$shippingAddress->setUser($this);
$this->shippingAddresses[] = $shippingAddress;
}
return $this;
}
public function removeShippingAddress(UserShippingLocation $shippingAddress): self
{
if ($this->shippingAddresses->contains($shippingAddress)) {
$this->shippingAddresses->removeElement($shippingAddress);
}
return $this;
}
/**
* @return Collection|UserSearch[]
*/
public function getSearches(): Collection
{
return $this->searches;
}
public function addSearch(UserSearch $search): self
{
if (!$this->searches->contains($search)) {
$this->searches[] = $search;
$search->setUser($this);
}
return $this;
}
public function removeSearch(UserSearch $search): self
{
if ($this->searches->contains($search)) {
$this->searches->removeElement($search);
// set the owning side to null (unless already changed)
if ($search->getUser() === $this) {
$search->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserViewedProduct[]
*/
public function getViewedProducts(): Collection
{
return $this->viewedProducts;
}
public function addViewedProduct(UserViewedProduct $viewedProduct): self
{
if (!$this->viewedProducts->contains($viewedProduct)) {
$this->viewedProducts[] = $viewedProduct;
$viewedProduct->setUser($this);
}
return $this;
}
public function removeViewedProduct(UserViewedProduct $viewedProduct): self
{
if ($this->viewedProducts->contains($viewedProduct)) {
$this->viewedProducts->removeElement($viewedProduct);
// set the owning side to null (unless already changed)
if ($viewedProduct->getUser() === $this) {
$viewedProduct->setUser(null);
}
}
return $this;
}
public function getTermsAcceptanceDate(): ?\DateTimeInterface
{
return $this->termsAcceptanceDate;
}
public function setTermsAcceptanceDate(?\DateTimeInterface $termsAcceptanceDate): self
{
$this->termsAcceptanceDate = $termsAcceptanceDate;
return $this;
}
public function getTermsAcceptanceIp(): ?string
{
return $this->termsAcceptanceIp;
}
public function setTermsAcceptanceIp(?string $termsAcceptanceIp): self
{
$this->termsAcceptanceIp = $termsAcceptanceIp;
return $this;
}
/**
* @return Collection|FinancialLog[]
*/
public function getTransactionsPaid(): Collection
{
return $this->transactionsPaid;
}
public function addTransactionsPaid(FinancialLog $transactionsPaid): self
{
if (!$this->transactionsPaid->contains($transactionsPaid)) {
$this->transactionsPaid[] = $transactionsPaid;
$transactionsPaid->setUserPaying($this);
}
return $this;
}
public function removeTransactionsPaid(FinancialLog $transactionsPaid): self
{
if ($this->transactionsPaid->contains($transactionsPaid)) {
$this->transactionsPaid->removeElement($transactionsPaid);
// set the owning side to null (unless already changed)
if ($transactionsPaid->getUserPaying() === $this) {
$transactionsPaid->setUserPaying(null);
}
}
return $this;
}
/**
* @return Collection|FinancialLog[]
*/
public function getTransactionsReceived(): Collection
{
return $this->transactionsReceived;
}
public function addTransactionsReceived(FinancialLog $transactionsReceived): self
{
if (!$this->transactionsReceived->contains($transactionsReceived)) {
$this->transactionsReceived[] = $transactionsReceived;
$transactionsReceived->setUserReceiving($this);
}
return $this;
}
public function removeTransactionsReceived(FinancialLog $transactionsReceived): self
{
if ($this->transactionsReceived->contains($transactionsReceived)) {
$this->transactionsReceived->removeElement($transactionsReceived);
// set the owning side to null (unless already changed)
if ($transactionsReceived->getUserReceiving() === $this) {
$transactionsReceived->setUserReceiving(null);
}
}
return $this;
}
public function getStripeAccountId(): ?string
{
return $this->stripeAccountId;
}
public function setStripeAccountId($stripeAccountId): self
{
$this->stripeAccountId = $stripeAccountId;
return $this;
}
/**
* @return Collection|Message[]
*/
/*
public function getMessages(): Collection
{
return $this->messages;
}
public function addMessage(Message $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
$message->setUserTo($this);
}
return $this;
}
public function removeMessage(Message $message): self
{
if ($this->messages->contains($message)) {
$this->messages->removeElement($message);
// set the owning side to null (unless already changed)
if ($message->getUserTo() === $this) {
$message->setUserTo(null);
}
}
return $this;
}
*/
public function __toString(){
return $this->getId().' - '.$this->getEmail();
}
/**
* @return Collection|UserFavorite[]
*/
public function getFavorites(): Collection
{
return $this->favorites;
}
public function hasFavorite(Product $product){
$return = false;
foreach($this->getFavorites() as $f){
if($f->getProduct() == $product)
return $f;
}
return $return;
}
public function addFavorite(UserFavorite $favorite): self
{
if (!$this->favorites->contains($favorite)) {
$this->favorites[] = $favorite;
$favorite->setUser($this);
}
return $this;
}
public function removeFavorite(UserFavorite $favorite): self
{
if ($this->favorites->contains($favorite)) {
$this->favorites->removeElement($favorite);
// set the owning side to null (unless already changed)
if ($favorite->getUser() === $this) {
$favorite->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Cart[]
*/
public function getCart(){
$criteria = Criteria::create();
$criteria
->where(Criteria::expr()->eq('isPaid', false))
->andWhere(Criteria::expr()->eq('isRefunded', false))
->andWhere(Criteria::expr()->eq('isBulkOrder', false))
;
$cart = $this->carts->matching($criteria);
if(!empty($cart) && count($cart) > 0){
//Need to put all this in criteria;
$cart = array_reverse($cart->toArray());
for($i = 0; $i <= count($cart); $i++){
if(!is_bool(current($cart)) && current($cart)->getRecurringOrders()->count() == 0 ){
return current($cart);
}
next($cart);
}
}
$cart = new Cart();
$this->addCart($cart);
return $cart;
}
/*
* Set the current cart
*/
public function setCart(Cart $cart){
if($this->getCarts()->count() > 0 ){
$carts = $this->getCarts();
$carts->set(0, $cart);
$this->carts = $carts;
}else
$this->addCart($cart);
return $this;
}
/*
* Return if its the first order of the user
*/
public function isFirstOrder(): bool
{
$orders = $this->getPaidOrders();
if(!empty($orders) && count($orders) == 1)
return true;
else
return false;
}
public function getPaidOrders($limit=false){
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('isPaid', true));
$criteria->OrWhere(Criteria::expr()->eq('isRefunded', true));
$criteria->orderBy(array('datePayment' => Criteria::DESC));
if($limit)
$criteria->setMaxResults($limit);
return $this->carts->matching($criteria);
}
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(Cart $cart): self
{
if (!$this->carts->contains($cart)) {
$this->carts[] = $cart;
$cart->setUser($this);
}
return $this;
}
public function removeCart(Cart $cart): self
{
if ($this->carts->contains($cart)) {
$this->carts->removeElement($cart);
// set the owning side to null (unless already changed)
if ($cart->getUser() === $this) {
$cart->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Image[]
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
// $image->setUser2($this);
}
return $this;
}
public function removeImage(Image $image): self
{
if ($this->images->contains($image)) {
$this->images->removeElement($image);
// set the owning side to null (unless already changed)
// if ($image->getUser2() === $this) {
// $image->setUser2(null);
// }
}
return $this;
}
public function isGranted($role)
{
return in_array($role, $this->getRoles());
}
public function getIsBetaTester(): ?bool
{
return $this->isBetaTester;
}
public function setIsBetaTester(bool $isBetaTester): self
{
$this->isBetaTester = $isBetaTester;
return $this;
}
/**
* @return Collection|CartCoupon[]
*/
public function getCouponsUsed(): Collection
{
return $this->couponsUsed;
}
public function addCouponUsed(CartCoupon $couponsUsed): self
{
if (!$this->couponsUsed->contains($couponsUsed)) {
$this->couponsUsed[] = $couponsUsed;
}
return $this;
}
public function removeCouponUsed(CartCoupon $couponsUsed): self
{
if ($this->couponsUsed->contains($couponsUsed)) {
$this->couponsUsed->removeElement($couponsUsed);
}
return $this;
}
public function getPaymentLast4digits(): ?int
{
return $this->paymentLast4digits;
}
public function setPaymentLast4digits(?int $paymentLast4digits): self
{
$this->paymentLast4digits = $paymentLast4digits;
return $this;
}
public function isABuyerAccount(): bool
{
if($this->adminOfCompanies->count() > 0)
return false;
else
return true;
}
/**
* @return Collection|RecurringOrder[]
*/
public function getRecurringOrders(): Collection
{
return $this->recurringOrders;
}
public function addRecurringOrder(RecurringOrder $recurringOrder): self
{
if (!$this->recurringOrders->contains($recurringOrder)) {
$this->recurringOrders[] = $recurringOrder;
$recurringOrder->setUser($this);
}
return $this;
}
public function removeRecurringOrder(RecurringOrder $recurringOrder): self
{
if ($this->recurringOrders->contains($recurringOrder)) {
$this->recurringOrders->removeElement($recurringOrder);
// set the owning side to null (unless already changed)
if ($recurringOrder->getUser() === $this) {
$recurringOrder->setUser(null);
}
}
return $this;
}
/**
* @return Collection|CartCoupon[]
*/
public function getCartCoupons(): Collection
{
return $this->cartCoupons;
}
public function addCartCoupon(CartCoupon $cartCoupon): self
{
if (!$this->cartCoupons->contains($cartCoupon)) {
$this->cartCoupons[] = $cartCoupon;
$cartCoupon->setForUser($this);
}
return $this;
}
public function removeCartCoupon(CartCoupon $cartCoupon): self
{
if ($this->cartCoupons->contains($cartCoupon)) {
$this->cartCoupons->removeElement($cartCoupon);
// set the owning side to null (unless already changed)
if ($cartCoupon->getForUser() === $this) {
$cartCoupon->setForUser(null);
}
}
return $this;
}
public function getConfirmationToken()
{
return $this->confirmationToken;
}
public function setConfirmationToken($confirmationToken)
{
$this->confirmationToken = $confirmationToken;
return $this;
}
public function getReferredBy(): ?self
{
return $this->referredBy;
}
public function setReferredBy(?self $referredBy): self
{
$this->referredBy = $referredBy;
return $this;
}
/**
* @return Collection|self[]
*/
public function getUsersReferred(): Collection
{
return $this->usersReferred;
}
public function addUsersReferred(self $usersReferred): self
{
if (!$this->usersReferred->contains($usersReferred)) {
$this->usersReferred[] = $usersReferred;
$usersReferred->setReferredBy($this);
}
return $this;
}
public function removeUsersReferred(self $usersReferred): self
{
if ($this->usersReferred->contains($usersReferred)) {
$this->usersReferred->removeElement($usersReferred);
// set the owning side to null (unless already changed)
if ($usersReferred->getReferredBy() === $this) {
$usersReferred->setReferredBy(null);
}
}
return $this;
}
/**
* @return Collection|Subscription[]
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setForUser($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->contains($subscription)) {
$this->subscriptions->removeElement($subscription);
// set the owning side to null (unless already changed)
if ($subscription->getForUser() === $this) {
$subscription->setForUser(null);
}
}
return $this;
}
public function getIsARecruiter(): ?bool
{
return $this->IsARecruiter;
}
public function setIsARecruiter(bool $IsARecruiter): self
{
$this->IsARecruiter = $IsARecruiter;
return $this;
}
public function getIsHri(): ?bool
{
return $this->isHri;
}
public function setIsHri(bool $isHri): self
{
$this->isHri = $isHri;
return $this;
}
/**
* @return Collection|Company[]
*/
public function getCompaniesRecruited(): Collection
{
return $this->companiesRecruited;
}
public function addCompaniesRecruited(Company $companiesRecruited): self
{
if (!$this->companiesRecruited->contains($companiesRecruited)) {
$this->companiesRecruited[] = $companiesRecruited;
$companiesRecruited->setRecruiter($this);
}
return $this;
}
public function removeCompaniesRecruited(Company $companiesRecruited): self
{
if ($this->companiesRecruited->contains($companiesRecruited)) {
$this->companiesRecruited->removeElement($companiesRecruited);
// set the owning side to null (unless already changed)
if ($companiesRecruited->getRecruiter() === $this) {
$companiesRecruited->setRecruiter(null);
}
}
return $this;
}
public function getValidSubscriptions(){
$active = [];
foreach($this->getSubscriptions() as $s){
if($s->getIsActive() && $s->getFrequency() == 2)
$active[]=$s;
}
return $active;
}
public function getActiveSubscriptions(){
$active = [];
foreach($this->getSubscriptions() as $s){
if($s->getIsActive())
$active[]=$s;
}
return $active;
}
/**
* @return Collection|EmailSent[]
*/
public function getEmailReceiveds(): Collection
{
return $this->emailReceiveds;
}
public function addEmailReceived(EmailSent $emailReceived): self
{
if (!$this->emailReceiveds->contains($emailReceived)) {
$this->emailReceiveds[] = $emailReceived;
$emailReceived->setUser($this);
}
return $this;
}
public function removeEmailReceived(EmailSent $emailReceived): self
{
if ($this->emailReceiveds->contains($emailReceived)) {
$this->emailReceiveds->removeElement($emailReceived);
// set the owning side to null (unless already changed)
if ($emailReceived->getUser() === $this) {
$emailReceived->setUser(null);
}
}
return $this;
}
/*
* LEGACY DO NOT USE, WILL BE REMOVED
*/
public function getIsAllowedToMakeGroups(): ?bool
{
return $this->isAllowedToMakeCompanyForAssociation;
}
/*
* LEGACY DO NOT USE, WILL BE REMOVED
*/
public function setIsAllowedToMakeGroups(bool $isAllowedToMakeGroups): self
{
$this->isAllowedToMakeCompanyForAssociation = $isAllowedToMakeGroups;
return $this;
}
public function getMakeGroupName(): ?string
{
if($this->getIsAllowedToMakeGroups() && empty($this->makeGroupName))
return $this->getId();
else
return $this->makeGroupName;
}
public function setMakeGroupName(?string $makeGroupName): self
{
$this->makeGroupName = $makeGroupName;
return $this;
}
/**
* @return Collection|Company[]
*/
public function getMyGroupOfCompanies(): Collection
{
return $this->myGroupOfCompanies;
}
public function addMyGroupOfCompany(Company $myGroupOfCompany): self
{
if (!$this->myGroupOfCompanies->contains($myGroupOfCompany)) {
$this->myGroupOfCompanies[] = $myGroupOfCompany;
$myGroupOfCompany->setInGroupOfUser($this);
}
return $this;
}
public function removeMyGroupOfCompany(Company $myGroupOfCompany): self
{
if ($this->myGroupOfCompanies->contains($myGroupOfCompany)) {
$this->myGroupOfCompanies->removeElement($myGroupOfCompany);
// set the owning side to null (unless already changed)
if ($myGroupOfCompany->getInGroupOfUser() === $this) {
$myGroupOfCompany->setInGroupOfUser(null);
}
}
return $this;
}
public function getSwitchLink(){
return '/?_switch_user='.$this->getEmail();
}
/**
* @return Collection|CompanyAssociation[]
*/
public function getMakeGroupOfAssociations(): Collection
{
return $this->makeGroupOfAssociations;
}
public function addMakeGroupOfAssociation(CompanyAssociation $makeGroupOfAssociation): self
{
if (!$this->makeGroupOfAssociations->contains($makeGroupOfAssociation)) {
$this->makeGroupOfAssociations[] = $makeGroupOfAssociation;
}
return $this;
}
public function removeMakeGroupOfAssociation(CompanyAssociation $makeGroupOfAssociation): self
{
if ($this->makeGroupOfAssociations->contains($makeGroupOfAssociation)) {
$this->makeGroupOfAssociations->removeElement($makeGroupOfAssociation);
}
return $this;
}
/**
* @return Collection|CompanyAssociation[]
*/
public function getAdminOfCompanyAssociations(): Collection
{
return $this->AdminOfCompanyAssociations;
}
public function addAdminOfCompanyAssociation(CompanyAssociation $adminOfCompanyAssociation): self
{
if (!$this->AdminOfCompanyAssociations->contains($adminOfCompanyAssociation)) {
$this->AdminOfCompanyAssociations[] = $adminOfCompanyAssociation;
}
return $this;
}
public function removeAdminOfCompanyAssociation(CompanyAssociation $adminOfCompanyAssociation): self
{
if ($this->AdminOfCompanyAssociations->contains($adminOfCompanyAssociation)) {
$this->AdminOfCompanyAssociations->removeElement($adminOfCompanyAssociation);
}
return $this;
}
public function getIsAllowedToMakeCompanyForAssociation(): ?bool
{
return $this->isAllowedToMakeCompanyForAssociation;
}
public function setIsAllowedToMakeCompanyForAssociation(bool $isAllowedToMakeCompanyForAssociation): self
{
$this->isAllowedToMakeCompanyForAssociation = $isAllowedToMakeCompanyForAssociation;
return $this;
}
public function getMakeCompanyForAssociation(): ?CompanyAssociation
{
return $this->makeCompanyForAssociation;
}
public function setMakeCompanyForAssociation(?CompanyAssociation $makeCompanyForAssociation): self
{
$this->makeCompanyForAssociation = $makeCompanyForAssociation;
return $this;
}
/**
* @return bool
*/
public function getHasReusableBox(): bool
{
return $this->hasReusableBox;
}
/**
* @param bool $hasReusableBox
* @return User
*/
public function setHasReusableBox(bool $hasReusableBox): self
{
$this->hasReusableBox = $hasReusableBox;
return $this;
}
public function getPaidPickUpOrders(){
$orders = $this->getPaidOrders();
$pickupOrders=[];
if (!empty($orders)) {
foreach ($orders as $order) {
if($order->hasPickUp() && $order->getIsPaid()){
array_push($pickupOrders,$order);
}
}
}
return $pickupOrders;
}
public function getAllCartsProducts()
{
$tempArray = [];
$products = [];
$paidOrders = $this->getPaidOrders();
foreach ($paidOrders as $paidOrder) {
foreach ($paidOrder->getProducts() as $key => $cartProduct) {
$product = $cartProduct->getProduct();
$id = $product->getId();
if( empty($products[$id]) && $product->isSalable()){
$products[$id]=[$product];
array_Push($tempArray,$product);
}
}
}
return $tempArray;
}
/**
* @return bool
*/
public function getReminderCouponSent(): bool
{
return $this->reminderCouponSent;
}
/**
* @param bool $reminderCouponSent
* @return User
*/
public function setReminderCouponSent(bool $reminderCouponSent): self
{
$this->reminderCouponSent = $reminderCouponSent;
return $this;
}
public function getUserSurvey(): ?UserSurvey
{
return $this->userSurvey;
}
public function setUserSurvey(UserSurvey $userSurvey): self
{
$this->userSurvey = $userSurvey;
// set the owning side of the relation if necessary
if ($userSurvey->getUser() !== $this) {
$userSurvey->setUser($this);
}
return $this;
}
public function setNextUserSurveyTime($nextUserSurveyTime)
{
$this->nextUserSurveyTime = $nextUserSurveyTime;
}
public function getNextUserSurveyTime()
{
return $this->nextUserSurveyTime;
}
/*
* @return bool
*/
public function getDontShowSurvey(): bool
{
return $this->dontShowSurvey;
}
/**
* @param bool $reminderCouponSent
* @return User
*/
public function setDontShowSurvey(bool $dontShowSurvey): self
{
$this->dontShowSurvey = $dontShowSurvey;
return $this;
}
public function getUserSubscriptionMaturin(): bool
{
return $this->userSubscriptionMaturin;
}
public function setUserSubscriptionMaturin(bool $userSubscriptionMaturin): self
{
$this->userSubscriptionMaturin = $userSubscriptionMaturin;
return $this;
}
public function getDateLogSubscriptionMaturin()
{
return $this->dateLogSubscriptionMaturin;
}
public function setDateLogSubscriptionMaturin($dateLogSubscriptionMaturin)
{
$this->dateLogSubscriptionMaturin = $dateLogSubscriptionMaturin;
}
public function getSubscriptionStripeId(): ?string
{
return $this->subscriptionStripeId;
}
public function setSubscriptionStripeId($subscriptionStripeId): self
{
$this->subscriptionStripeId = $subscriptionStripeId;
return $this;
}
}