<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Criteria;
/**
* A customer can currently represent a directory listing, or a classified listing.
*
* Todo: should probably rename entity to: "Company"
*
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
*/
class Customer
{
const TYPE_PRODUCTS_SERVICES = 1024;
const TYPE_DISTRIBUTORS = 2048;
const TYPE_CONSULTANTS = 4096;
const TYPE_CONTRACTORS = 8192;
const TYPE_ASSOCIATIONS = 16384;
const TYPE_MANUFACTURERS_REP = 32768;
const TYPE_RCS_PARTNERS = 65536;
const TYPE_PRODUCTS_SERVICES_STRING = "Products & Services";
const TYPE_DISTRIBUTORS_STRING = "Distributors";
const TYPE_CONSULTANTS_STRING = "Consultants";
const TYPE_CONTRACTORS_STRING = "Contractors";
const TYPE_ASSOCIATIONS_STRING = "Associations";
const TYPE_MANUFACTURERS_REP_STRING = "Manufacturers Reps";
const TYPE_RCS_PARTNERS_STRING = "RCS Partners";
const LEVEL_PREMIUM = 1000;
const LEVEL_BEST = 2000;
const LEVEL_BETTER = 3000;
const LEVEL_GOOD = 4000;
const LEVEL_RCLUB = 4001;
const LEVEL_PARTNER = 5000;
const LEVEL_STANDARD = 6000;
const COUNTRIES = [
'USA' => "USA",
'Canada' => "Canada",
];
const STATES_PROVINCES = [
'Alabama'=>'Alabama',
'Alaska'=>'Alaska',
'Arizona'=>'Arizona',
'Arkansas'=>'Arkansas',
'California'=>'California',
'Colorado'=>'Colorado',
'Connecticut'=>'Connecticut',
'Delaware'=>'Delaware',
'District of Columbia'=>'District of Columbia',
'Florida'=>'Florida',
'Georgia'=>'Georgia',
'Hawaii'=>'Hawaii',
'Idaho'=>'Idaho',
'Illinois'=>'Illinois',
'Indiana'=>'Indiana',
'Iowa'=>'Iowa',
'Kansas'=>'Kansas',
'Kentucky'=>'Kentucky',
'Louisiana'=>'Louisiana',
'Maine'=>'Maine',
'Maryland'=>'Maryland',
'Massachusetts'=>'Massachusetts',
'Michigan'=>'Michigan',
'Minnesota'=>'Minnesota',
'Mississippi'=>'Mississippi',
'Missouri'=>'Missouri',
'Montana'=>'Montana',
'Nebraska'=>'Nebraska',
'Nevada'=>'Nevada',
'New Hampshire'=>'New Hampshire',
'New Jersey'=>'New Jersey',
'New Mexico'=>'New Mexico',
'New York'=>'New York',
'North Carolina'=>'North Carolina',
'North Dakota'=>'North Dakota',
'Ohio'=>'Ohio',
'Oklahoma'=>'Oklahoma',
'Oregon'=>'Oregon',
'Pennsylvania'=>'Pennsylvania',
'Rhode Island'=>'Rhode Island',
'South Carolina'=>'South Carolina',
'South Dakota'=>'South Dakota',
'Tennessee'=>'Tennessee',
'Texas'=>'Texas',
'Utah'=>'Utah',
'Vermont'=>'Vermont',
'Virginia'=>'Virginia',
'Washington'=>'Washington',
'West Virginia'=>'West Virginia',
'Wisconsin'=>'Wisconsin',
'Wyoming'=>'Wyoming',
"Alberta" => "Alberta",
"British Columbia" => "British Columbia",
"Manitoba" => "Manitoba",
"New Brunswick" => "New Brunswick",
"Newfoundland and Labrador" => "Newfoundland and Labrador",
"Northwest Territories" => "Northwest Territories",
"Nova Scotia" => "Nova Scotia",
"Nunavut" => "Nunavut",
"Ontario" => "Ontario",
"Prince Edward Island" => "Prince Edward Island",
"Quebec" => "Quebec",
"Saskatchewan" => "Saskatchewan",
"Yukon Territory" => "Yukon Territory",
];
const SITE_RCS = 1;
const SITE_AAR = 2;
const SITE_MCS = 3;
const SITE_CCS = 4;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Version @ORM\Column(type="integer")
*/
private $version;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="children", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $prnt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Customer", mappedBy="prnt")
* @ORM\OrderBy({"title" = "ASC"})
*/
private $children;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="text")
*/
private $call_to_action;
/**
* @ORM\Column(type="text")
*/
private $bio;
/**
* @ORM\Column(type="datetime")
*/
private $modified_at;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CustomerPhone", mappedBy="customer", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $phones;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CustomerWebsite", mappedBy="customer", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $websites;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CustomerAddress", mappedBy="customer", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $addresses;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
private $external_request_more;
/**
* @ORM\Column(type="string", length=255)
*/
private $website;
/**
* @ORM\Column(type="string", length=255)
*/
private $facebook;
/**
* @ORM\Column(type="string", length=255)
*/
private $twitter;
/**
* @ORM\Column(type="string", length=255)
*/
private $linkedin;
/**
* @ORM\Column(type="string", length=255)
*/
private $instagram;
/**
* @ORM\Column(type="string", length=255)
*/
private $tiktok;
/**
* @ORM\Column(type="string", length=255)
*/
private $youtube;
/**
* @ORM\Column(type="string", length=255)
*/
private $hash_tag;
/**
* @ORM\Column(type="string", length=255)
*/
private $location; //country
/**
* @ORM\Column(type="string", length=255)
*/
private $state; //state/province
/**
* @ORM\OneToOne(targetEntity="App\Entity\MediaGroup", inversedBy="customer_literature", cascade={"persist", "remove"})
*/
private $literature;
/**
* JGF - media_group will work but should we update "content" to handle this?
*
* @ORM\OneToOne(targetEntity="App\Entity\MediaGroup", inversedBy="customer_photo_gallery", cascade={"persist", "remove"})
*/
private $photo_gallery;
/**
* JGF - media_group will work but should we update "content" to handle this?
*
* @ORM\OneToOne(targetEntity="App\Entity\MediaGroup", inversedBy="customer_video_gallery", cascade={"persist", "remove"})
*/
private $video_gallery;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Media", cascade={"persist", "remove"})
*/
private $logo;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $media;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $dummy_media; //In sonata admin, can't have multiple ModelListType fields of the same type... event if one is unmapped
//Delete this as soon as it's fixed, really don't want this here as it adds a field to the database
/**
* @ORM\OneToOne(targetEntity="App\Entity\Link", cascade={"persist", "remove"})
*/
private $blog;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Link", cascade={"persist", "remove"})
*/
private $branch_locator;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Menu", cascade={"persist", "remove"})
*/
private $external_events;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Menu", cascade={"persist", "remove"})
*/
private $newsletters;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Menu", cascade={"persist", "remove"})
*/
private $partners_reps;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Menu", cascade={"persist", "remove"})
*/
private $rep_lines;
/**
* @ORM\Column(type="text")
*/
private $keywords;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\User", inversedBy="companies")
*/
private $members;
/**
* @ORM\Column(type="integer")
*/
private $customer_level;
/**
* @ORM\Column(type="integer")
*/
private $customer_type;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Content", inversedBy="customers", cascade={"persist"})
*/
private $contents;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Content", mappedBy="primaryCustomer")
*/
private $primaryContents;
//This is just to simplify the relationship between the customer and its directory type content object...
/**
* @ORM\OneToOne(targetEntity="App\Entity\Content", inversedBy="directory", cascade={"persist", "remove"})
*/
private $directory_content;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Category", inversedBy="customers")
*/
private $categories;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\MediaGroupItem", inversedBy="customers", cascade={"persist"})
*/
private $mediaGroupItems;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Link", mappedBy="customer", orphanRemoval=true, cascade={"persist", "remove"})
* @ORM\OrderBy({"id" = "DESC"})
*/
private $links;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Product", inversedBy="customers", cascade={"persist"})
*/
private $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CustomerMeta", mappedBy="customer", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $customermeta;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Poll", inversedBy="customers", cascade={"persist"})
*/
private $polls;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Quiz", mappedBy="customers", cascade={"persist"})
*/
private $quizzes;
/**
* @ORM\Column(type="string", length=24)
*/
private $type_work;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Site", inversedBy="customers")
*/
private $site;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CustomerSiteLevel", mappedBy="customer", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $levels;
public function __construct()
{
$this->title = "";
$this->description = "";
$this->call_to_action = "";
$this->bio = "";
$this->status = 1;
$this->customer_level = 6000;
$this->email = "";
$this->external_request_more = "";
$this->website = "";
$this->facebok = "";
$this->twitter = "";
$this->linkedin = "";
$this->instagram = "";
$this->tiktok = "";
$this->youtube = "";
$this->hash_tag = "";
$this->location = "";
$this->state = "";
$this->keywords = "";
$this->customer_type = 0;
$this->type_work = "";
$this->phones = new ArrayCollection();
$this->websites = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->contents = new ArrayCollection();
$this->polls = new ArrayCollection();
$this->quizzes = new ArrayCollection();
$this->mediaGroupItems = new ArrayCollection();
$this->created_at = new \DateTime("now");
$this->modified_at = new \DateTime("now");
$this->members = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->products = new ArrayCollection();
$this->contentmeta = new ArrayCollection();
$this->site = new ArrayCollection();
$this->children = new ArrayCollection();
}
public function getDummyMedia (): ?Media
{
return $this->dummy_media;
}
public function setDummyMedia (Media $dummy_media = null): self
{
$this->dummy_media = $dummy_media;
return $this;
}
public function getId()
{
return $this->id;
}
public function getVersion() {
return $this->version;
}
public function getPrnt(): ?self
{
return $this->prnt;
}
public function setPrnt(self $parent = null): self
{
$this->prnt = $parent;
return $this;
}
/**
* @return Collection
*/
public function getChildren(): Collection
{
return $this->children;
}
public function getActiveChildren(): Collection
{
$childDirs = [];
foreach($this->getChildren() as $child) {
$childDir = $child->getDirectoryContent();
if($childDir && $childDir->getStatus() == 1) {
$childDirs[] = $childDir;
}
}
//$childDirsCollection = new ArrayCollection($childDirs);
return $childDirs();
}
public function addChildren(Customer $children): self
{
if (!$this->children->contains($children)) {
$this->children[] = $children;
$children->setPrnt($this);
}
return $this;
}
public function removeChildren(Customer $children): self
{
if ($this->children->contains($children)) {
$this->children->removeElement($children);
// set the owning side to null (unless already changed)
if ($children->getPrnt() === $this) {
$children->setPrnt(null);
}
}
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function getTitleClean()
{
return preg_replace('/[^A-Za-z0-9 \-\.]/', ' ', $this->title); //remove special characters
}
public function setTitle(string $title = null): self
{
if (is_null($title)) {
$title = "";
}
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
if (is_null($description)) {
$description = "";
}
$this->description = $description;
return $this;
}
public function getCallToAction(): ?string
{
return $this->call_to_action;
}
public function setCallToAction(string $call_to_action = null): self
{
if (is_null($call_to_action)) {
$call_to_action = "";
}
$this->call_to_action = $call_to_action;
return $this;
}
public function getBio(): ?string
{
return $this->bio;
}
public function setBio(string $bio = null): self
{
if (is_null($bio)) {
$bio = "";
}
$this->bio = $bio;
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modified_at;
}
public function setModifiedAt(\DateTimeInterface $modified_at): self
{
$this->modified_at = $modified_at;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection|CustomerPhone[]
*/
public function getPhones(): Collection
{
return $this->phones;
}
public function addPhone(CustomerPhone $phone): self
{
if (!$this->phones->contains($phone)) {
$this->phones[] = $phone;
$phone->setCustomer($this);
}
return $this;
}
public function removePhone(CustomerPhone $phone): self
{
if ($this->phones->contains($phone)) {
$this->phones->removeElement($phone);
// set the owning side to null (unless already changed)
if ($phone->getCustomer() === $this) {
$phone->setCustomer(null);
}
}
return $this;
}
public function resetPhones(): self
{
foreach($this->phones as $phone) {
$this->removePhone($phone);
}
return $this;
}
/**
* @return Collection|CustomerWebsite[]
*/
public function getWebsites(): Collection
{
return $this->websites;
}
public function addWebsite(CustomerWebsite $website): self
{
if (!$this->websites->contains($website)) {
$this->websites[] = $website;
$website->setCustomer($this);
}
return $this;
}
public function removeWebsite(CustomerWebsite $website): self
{
if ($this->websites->contains($website)) {
$this->websites->removeElement($website);
// set the owning side to null (unless already changed)
if ($website->getCustomer() === $this) {
$website->setCustomer(null);
}
}
return $this;
}
public function resetWebsites(): self
{
foreach($this->websites as $website) {
$this->removeWebsite($website);
}
return $this;
}
/**
* @return Collection|CustomerAddress[]
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function addAddress(CustomerAddress $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses[] = $address;
$address->setCustomer($this);
}
return $this;
}
public function removeAddress(CustomerAddress $address): self
{
if ($this->addresses->contains($address)) {
$this->addresses->removeElement($address);
// set the owning side to null (unless already changed)
if ($address->getCustomer() === $this) {
$address->setCustomer(null);
}
}
return $this;
}
public function resetAddresses(): self
{
foreach($this->addresses as $address) {
$this->removeAddress($address);
}
return $this;
}
public function __toString ()
{
return $this->title;
}
public function getEmail(): ?string
{
return $this->email;
}
// This is for external Request More Link -- everything has to be named youtube becuase... again this server is shit.
public function getYoutube3(): ?string
{
return $this->external_request_more;
}
// This is for external Request More Link -- everything has to be named youtube becuase... again this server is shit.
public function setYoutube3(string $external_request_more = null): self
{
if (is_null($external_request_more)) {
$external_request_more = "";
}
$this->external_request_more = $external_request_more;
return $this;
}
public function setEmail(string $email = null): self
{
if (is_null($email)) {
$email = "";
}
$this->email = $email;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(string $website = null): self
{
if (is_null($website)) {
$website = "";
}
$this->website = $website;
return $this;
}
public function getFacebook(): ?string
{
return $this->facebook;
}
public function setFacebook(string $facebook = null): self
{
if (is_null($facebook)) {
$facebook = "";
}
$this->facebook = $facebook;
return $this;
}
public function getTwitter(): ?string
{
return $this->twitter;
}
public function setTwitter(string $twitter = null): self
{
if (is_null($twitter)) {
$twitter = "";
}
$this->twitter = $twitter;
return $this;
}
public function getLinkedin(): ?string
{
return $this->linkedin;
}
public function setLinkedin(string $linkedin = null): self
{
if (is_null($linkedin)) {
$linkedin = "";
}
$this->linkedin = $linkedin;
return $this;
}
public function getInstagram(): ?string
{
return $this->instagram;
}
public function setInstagram(string $instagram = null): self
{
if (is_null($instagram)) {
$instagram = "";
}
$this->instagram = $instagram;
return $this;
}
// This is for the TikTok URL -- the server is a shit
public function getYoutube2(): ?string
{
return $this->tiktok;
}
public function getTiktok(): ?string
{
return $this->tiktok;
}
// This is for the TikTok URL -- the server is a shit
public function setYoutube2(string $tiktok = null): self
{
if (is_null($tiktok)) {
$tiktok = "";
}
$this->tiktok = $tiktok;
return $this;
}
public function getYoutube(): ?string
{
return $this->youtube;
}
public function setYoutube(string $youtube = null): self
{
if (is_null($youtube)) {
$youtube = "";
}
$this->youtube = $youtube;
return $this;
}
public function getHashTag(): ?string
{
return $this->hash_tag;
}
public function setHashTag(string $hash_tag = null): self
{
if (is_null($hash_tag)) {
$hash_tag = "";
}
$this->hash_tag = $hash_tag;
return $this;
}
/*
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(string $location = null): self
{
if (is_null($location)) {
$location = "";
}
$this->location = $location;
return $this;
}
*/
public function getLocation(): ?array
{
return json_decode($this->location);
}
public function setLocation(array $location = null): self
{
if (is_null($location)) {
$location = "";
}
$this->location = json_encode($location);
return $this;
}
public function getState(): ?array
{
return json_decode($this->state);
}
public function setState(array $state = null): self
{
if (is_null($state)) {
$state = "";
}
$this->state = json_encode($state);
return $this;
}
public function getLiterature(): ?MediaGroup
{
return $this->literature;
}
public function setLiterature(?MediaGroup $literature): self
{
$this->literature = $literature;
return $this;
}
public function getPhotoGallery(): ?MediaGroup
{
return $this->photo_gallery;
}
public function setPhotoGallery(?MediaGroup $photo_gallery): self
{
$this->photo_gallery = $photo_gallery;
return $this;
}
public function getFirstPartnerGalleryMediaGroup()
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("type", 5))
->andWhere(Criteria::expr()->eq("status", "1"))
->andWhere(Criteria::expr()->eq("status", "1"))
//->join('.category', 'cat')
//->andWhere($query->expr()->eq('cat.slug', ':catSlug'))
//->setParameter('catSlug', 'partner-galleries')
->orderBy(array("published_at" => Criteria::DESC));
$galleries = $this->contents->matching($criteria);
$partnerGallery = null;
foreach($galleries as $gallery) {
$partnerGallery = $gallery;
$category = $gallery->getCategory();
if($category && $category->getSlug() == "partner-galleries") {
$containers = $partnerGallery->getMediaGroupContainers();
foreach($containers as $container) {
$group = $container->getMediaGroup();
if($group && !$group->getMediaGroupItems()->isEmpty()) {
return $group;
}
}
}
}
return $this->getPhotoGallery();
}
public function getVideoGallery(): ?MediaGroup
{
return $this->video_gallery;
}
public function setVideoGallery(?MediaGroup $video_gallery): self
{
$this->video_gallery = $video_gallery;
return $this;
}
public function getLogo(): ?Media
{
return $this->logo;
}
public function getMedia (): ?Media
{
return $this->media;
}
public function setMedia (Media $media = null): self
{
$this->media = $media;
return $this;
}
public function setLogo(?Media $logo): self
{
$this->logo = $logo;
return $this;
}
public function getDirectoryContent(): ?Content
{
return $this->directory_content;
}
public function setDirectoryContent(?Content $directory_content): self
{
$this->directory_content = $directory_content;
$this->addContent($directory_content);
return $this;
}
public function getBlog(): ?Link
{
return $this->blog;
}
public function setBlog(?Link $blog): self
{
$this->blog = $blog;
return $this;
}
public function getBranchLocator(): ?Link
{
return $this->branch_locator;
}
public function setBranchLocator(?Link $branch_locator): self
{
$this->branch_locator = $branch_locator;
return $this;
}
public function getExternalEvents(): ?Menu
{
return $this->external_events;
}
public function setExternalEvents(?Menu $external_events): self
{
$this->external_events = $external_events;
return $this;
}
public function setExternalEvent($title="", $url=""):self
{
$menu = new Menu();
$item = new MenuItem();
$link = new Link();
$link->setTitle($title);
$link->setRefExternal($url);
$item->setTitle($title);
$item->setLink($link);
$menu->addMenuItem($item);
$this->setExternalEvents($menu);
return $this;
}
public function getNewsletters(): ?Menu
{
return $this->newsletters;
}
public function setNewsletters(?Menu $newsletters): self
{
$this->newsletters = $newsletters;
return $this;
}
public function getPartnersReps(): ?Menu
{
return $this->partners_reps;
}
public function setPartnersReps(?Menu $partners_reps): self
{
$this->partners_reps = $partners_reps;
return $this;
}
public function getRepLines(): ?Menu
{
return $this->rep_lines;
}
public function setRepLines(?Menu $rep_lines): self
{
$this->rep_lines = $rep_lines;
return $this;
}
public function getKeywords(): ?string
{
return $this->keywords;
}
public function setKeywords(string $keywords = null): self
{
if (is_null($keywords)) {
$keywords = "";
}
$this->keywords = $keywords;
return $this;
}
/**
* @return Collection|User[]
*/
public function getMembers(): Collection
{
return $this->members;
}
public function addMember(User $member): self
{
if (!$this->members->contains($member)) {
$this->members[] = $member;
}
return $this;
}
public function removeMember(User $member): self
{
if ($this->members->contains($member)) {
$this->members->removeElement($member);
}
return $this;
}
public function getCustomerLevel($site_id = ""): ?int
{
if($site_id) {
foreach($this->getLevels() as $level) {
if($level->getSiteId() == $site_id) {
return $level->getLevel();
}
}
}
return $this->customer_level;
}
public function setCustomerLevel(int $customer_level): self
{
$this->customer_level = $customer_level;
return $this;
}
public function getCustomerType(): ?int
{
return $this->customer_type;
}
public function setCustomerType(int $customer_type): self
{
$this->customer_type = $customer_type;
return $this;
}
public function getCustomerTypeArray()
{
$type = $this->customer_type;
$values = array(
self::TYPE_PRODUCTS_SERVICES,
self::TYPE_DISTRIBUTORS,
self::TYPE_CONSULTANTS,
self::TYPE_CONTRACTORS,
self::TYPE_ASSOCIATIONS,
self::TYPE_MANUFACTURERS_REP,
self::TYPE_RCS_PARTNERS
);
$return = array();
foreach($values as $value) {
if($value & $type) {
switch ($value) {
case self::TYPE_PRODUCTS_SERVICES:
$return[] = self::TYPE_PRODUCTS_SERVICES_STRING;
break;
case self::TYPE_DISTRIBUTORS:
$return[] = self::TYPE_DISTRIBUTORS_STRING;
break;
case self::TYPE_CONSULTANTS:
$return[] = self::TYPE_CONSULTANTS_STRING;
break;
case self::TYPE_CONTRACTORS:
$return[] = self::TYPE_CONTRACTORS_STRING;
break;
case self::TYPE_ASSOCIATIONS:
$return[] = self::TYPE_ASSOCIATIONS_STRING;
break;
case self::TYPE_MANUFACTURERS_REP:
$return[] = self::TYPE_MANUFACTURERS_REP_STRING;
break;
case self::TYPE_RCS_PARTNERS:
$return[] = self::TYPE_RCS_PARTNERS_STRING;
break;
default:
break;
}
}
}
return $return;
}
// Takes an array of strings
public function setCustomerTypeArray($customer_type): self
{
$value = 0;
if(is_array($customer_type)){
foreach($customer_type as $type) {
switch ($type) {
case self::TYPE_PRODUCTS_SERVICES_STRING:
$value += self::TYPE_PRODUCTS_SERVICES;
break;
case self::TYPE_DISTRIBUTORS_STRING:
$value += self::TYPE_DISTRIBUTORS;
break;
case self::TYPE_CONSULTANTS_STRING:
$value += self::TYPE_CONSULTANTS;
break;
case self::TYPE_CONTRACTORS_STRING:
$value += self::TYPE_CONTRACTORS;
break;
case self::TYPE_ASSOCIATIONS_STRING:
$value += self::TYPE_ASSOCIATIONS;
break;
case self::TYPE_MANUFACTURERS_REP_STRING:
$value += self::TYPE_MANUFACTURERS_REP;
break;
case self::TYPE_RCS_PARTNERS_STRING:
$value += self::TYPE_RCS_PARTNERS;
break;
default:
break;
}
}
$this->customer_type = $value;
}
return $this;
}
public function getCustomerTypeString()
{
$customerTypes = $this->getCustomerTypeArray();
return implode(", ", $customerTypes);
}
public function toArray ()
{
$return = [];
foreach ($this as $key => $value) {
$return[$key] = $value;
}
return $return;
}
/**
* @return Collection|Content[]
*/
public function getContents(): Collection
{
return $this->contents;
}
public function getContentsByType($type = ""): Collection
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("type", $type))
->andWhere(Criteria::expr()->eq("status", "1"))
->orderBy(array("published_at" => Criteria::DESC));
return $this->contents->matching($criteria);
}
public function addContent(Content $content): self
{
if (!$this->contents->contains($content)) {
$this->contents[] = $content;
$content->addCustomer($this);
}
return $this;
}
public function removeContent(Content $content): self
{
if ($this->contents->contains($content)) {
$this->contents->removeElement($content);
$content->removeCustomer($this);
}
return $this;
}
/**
* @return Collection|Poll[]
*/
public function getPolls(): Collection
{
return $this->polls;
}
public function addPoll(Poll $poll): self
{
if (!$this->polls->contains($poll)) {
$this->polls[] = $poll;
$poll->addCustomer($this);
}
return $this;
}
public function removePoll(Poll $poll): self
{
if ($this->polls->contains($poll)) {
$this->polls->removeElement($poll);
$poll->removeCustomer($this);
}
return $this;
}
/**
* @return Collection|Quiz[]
*/
public function getQuizzes(): Collection
{
return $this->quizzes;
}
public function addQuiz(Quiz $quiz): self
{
if (!$this->quizzes->contains($quiz)) {
$this->quizzes[] = $quiz;
$quiz->addCustomer($this);
}
return $this;
}
public function removeQuiz(Quiz $quiz): self
{
if ($this->quizzes->contains($quiz)) {
$this->quizzes->removeElement($quiz);
$quiz->removeCustomer($this);
}
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function setCategories (Collection $categories): self {
foreach ($categories as $category) {
$this->addCategory($category);
}
return $this;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
$category->addCustomer($this);
}
return $this;
}
public function removeCategories(Category $category): self
{
if ($this->categories->contains($category)) {
$this->categories->removeElement($category);
$category->removeCustomer($this);
}
return $this;
}
public function getLatestContent($type = "", $limit = 3, $cat = ""):Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("status", "1"));
if($type) {
$criteria->andWhere(Criteria::expr()->eq("type", $type));
}
$criteria->orderBy(array("published_at" => Criteria::DESC));
if($limit) {
$criteria->setFirstResult(0);
$criteria->setMaxResults($limit);
}
return $this->contents->matching($criteria);
}
// The directory twig template are using these
//should find all and replace with getLatestContent() above and remove
public function getPromosRebates($limit = 4): Collection
{
return $this->getLatestContent(14, 4);
}
public function getContestsGames($limit = 4): Collection
{
return $this->getLatestContent(20, 4);
}
public function getAwards($limit = 4): Collection
{
return $this->getLatestContent(25, 4);
}
public function getVideos($limit = 4): Collection
{
return $this->getLatestContent(26, 4);
}
public function getEbooks($limit = 4): Collection
{
return $this->getLatestContent(19, $limit);
}
public function getHUBContent($limit = 4): Collection
{
return $this->getLatestContent(15, 4);
}
public function getPodcasts($limit = 4): Collection
{
return $this->getLatestContent(18, 4);
}
public function getWebinars($limit = 4): Collection
{
return $this->getLatestContent(8, 4);
}
public function getClassifieds($limit = 4): Collection
{
return $this->getLatestContent(3, 4);
}
public function getScholarships($limit = 4): Collection
{
return $this->getLatestContent(28, 4);
}
// -=-=-=- Virtual Properties for EasyAdmin -=-=-=-
public function getCustomerLevelString($site_id = "")
{
switch($this->getCustomerLevel()) {
case 1000:
return "Premium";
case 2000:
return "Best";
case 3000:
return "Better";
case 4000:
return "Good";
case 4001:
return "R-Club";
case 5000:
return "Partner";
case 6000:
return "Standard";
default:
return "Standard";
}
}
public function getContactPerson()
{
//return $this->getContentMetaValueByKey("_job_location");
//$directory = $this->getContentsByType(4)->first();
$directory = $this->getDirectoryContent();
if($directory) {
return $directory->getContentMetaValueByKey("_company_contact");
}
else {
return null;
}
}
public function getFeaturedEventTitle()
{
$directory = $this->getDirectoryContent();
if($directory) {
return $directory->getContentMetaValueByKey("_featured_event_title");
}
else {
return "";
}
}
public function setFeaturedEventTitle($value)
{
$directory = $this->getDirectoryContent();
if($directory) {
$directory->setContentmetum("_featured_event_title", $value);
}
return $this;
}
public function getFeaturedEventUrl()
{
$directory = $this->getDirectoryContent();
if($directory) {
return $directory->getContentMetaValueByKey("_featured_event_url");
}
else {
return "";
}
}
public function setFeaturedEventUrl($value)
{
$directory = $this->getDirectoryContent();
if($directory) {
$directory->setContentmetum("_featured_event_url", $value);
}
return $this;
}
public function getWebsiteTitle()
{
$directory = $this->getDirectoryContent();
if($directory) {
return $directory->getContentMetaValueByKey("_directory_website_title");
}
else {
return "";
}
}
public function setWebsiteTitle($value)
{
$directory = $this->getDirectoryContent();
if($directory) {
$directory->setContentmetum("_directory_website_title", $value);
}
return $this;
}
public function getWebsiteTitleText()
{
$title = "";
$directory = $this->getDirectoryContent();
if($directory) {
$title = $directory->getContentMetaValueByKey("_directory_website_title");
}
if(!$title) {
$title = $this->getWebsite();
}
return $title;
}
/**
* @return Collection|MediaGroupItem[]
*/
public function getMediaGroupItems(): Collection
{
return $this->mediaGroupItems;
}
public function addMediaGroupItem(MediaGroupItem $mediaGroupItem): self
{
if (!$this->mediaGroupItems->contains($mediaGroupItem)) {
$this->mediaGroupItems[] = $mediaGroupItem;
$mediaGroupItem->addCustomer($this);
}
return $this;
}
/*public function setMediaGroupItems (Collection $mediaGroupItems):self
{
$this->mediaGroupItems = $mediaGroupItems;
return $this;
}*/
public function removeMediaGroupItem(MediaGroupItem $mediaGroupItem): self
{
if ($this->mediaGroupItems->contains($mediaGroupItem)) {
$this->mediaGroupItems->removeElement($mediaGroupItem);
$mediaGroupItem->removeCustomer($this);
}
return $this;
}
/**
* @return Collection|Link[]
*/
public function getLinks(): Collection
{
return $this->links;
}
public function addLink(Link $link): self
{
if (!$this->links->contains($link)) {
$this->links[] = $link;
$link->setCustomer($this);
}
return $this;
}
public function setLinks (Collection $links):self
{
$this->links = $links;
return $this;
}
public function removeLink(Link $link): self
{
if ($this->links->contains($link)) {
$this->links->removeElement($link);
// set the owning side to null (unless already changed)
if ($link->getCustomer() === $this) {
$link->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->addCustomer($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
$product->removeCustomer($this);
}
return $this;
}
public function getGiftStoreProducts($limit = 3): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("status", "1"));
$criteria->andWhere(Criteria::expr()->eq("type", "4"));
$criteria->orderBy(array("published" => Criteria::DESC));
if($limit) {
$criteria->setFirstResult(0);
$criteria->setMaxResults($limit);
}
return $this->products->matching($criteria);
}
/**
* @return Collection|CustomerMeta[]
*/
public function getCustomermeta(): Collection
{
return $this->customermeta;
}
//only works with unique keys, otherwise returns the first
public function getCustomerMetaByKey ($key = "")
{
foreach ($this->customermeta as $meta) {
if ($meta->getMetakey() == $key) {
return $meta;
}
}
return null;
}
public function getCustomerMetaValueByKey ($key = "")
{
$meta = $this->getCustomerMetaByKey($key);
if ($meta) {
return $meta->getMetavalue();
}
return "";
}
// sets the customer meta with the provided certain key / value, or changes it if one with that key already exists
public function setCustomermetum($key = "", $value = "")
{
$meta = $this->getCustomerMetaByKey($key);
if ($meta) {
$meta->setMetavalue($value);
}
else {
$meta = new CustomerMeta();
$meta->setMetakey($key);
$meta->setMetavalue($value);
$this->addCustomerMetum($meta);
}
}
// adds customer meta with the provided key / value, even if one with that key already exists
public function addCustomerMetumKV($key = "", $value = ""): self
{
$meta = new CustomerMeta();
$meta->setMetakey($key);
$meta->setMetavalue($value);
$this->addCustomerMetum($meta);
return $this;
}
public function removeCustomerMetumKV($key = "", $value = ""): self
{
foreach ($this->customermeta as $meta) {
if ($meta->getMetakey() == $key && $meta->getMetavalue() == $value) {
$this->removeCustomermetum($meta);
}
}
return $this;
}
public function addCustomerMetum(CustomerMeta $customermetum): self
{
if (!$this->customermeta->contains($customermetum)) {
$this->customermeta[] = $customermetum;
$customermetum->setCustomer($this);
}
return $this;
}
public function removeCustomermetum(CustomerMeta $customermetum): self
{
if ($this->customermeta->contains($customermetum)) {
$this->customermeta->removeElement($customermetum);
// set the owning side to null (unless already changed)
if ($customermetum->getCustomer() === $this) {
$customermetum->setCustomer(null);
}
}
return $this;
}
// Content Impressions + Ad Impressions
public function getMonthlyImpressions($year, $month) {
$json = $this->getCustomerMetaValueByKey("monthly_impressions_v2");
if(!$json) {
return false;
}
$data = json_decode($json, true);
return isset($data[$year."-".$month]) ? $data[$year."-".$month] : false;
}
// Content Views
public function getMonthlyViews($year, $month) {
$json = $this->getCustomerMetaValueByKey("monthly_views_v2");
if(!$json) {
return false;
}
$data = json_decode($json, true);
return isset($data[$year."-".$month]) ? $data[$year."-".$month] : false;
}
// Ad Clicks + Link Clicks
public function getMonthlyClicks($year, $month) {
$json = $this->getCustomerMetaValueByKey("monthly_clicks_v2");
if(!$json) {
return false;
}
$data = json_decode($json, true);
return isset($data[$year."-".$month]) ? $data[$year."-".$month] : false;
}
public function setMonthlyImpressions($year, $month, $impressions) {
$data = [];
$json = $this->getCustomerMetaValueByKey("monthly_impressions_v2");
if($json) {
$data = json_decode($json, true);
}
$data[$year."-".$month] = $impressions;
$this->setCustomermetum("monthly_impressions_v2", json_encode($data));
return $this;
}
public function setMonthlyViews($year, $month, $views) {
$data = [];
$json = $this->getCustomerMetaValueByKey("monthly_views_v2");
if($json) {
$data = json_decode($json, true);
}
$data[$year."-".$month] = $views;
$this->setCustomermetum("monthly_views_v2", json_encode($data));
return $this;
}
public function setMonthlyClicks($year, $month, $clicks) {
$data = [];
$json = $this->getCustomerMetaValueByKey("monthly_clicks_v2");
if($json) {
$data = json_decode($json, true);
}
$data[$year."-".$month] = $clicks;
$this->setCustomermetum("monthly_clicks_v2", json_encode($data));
return $this;
}
/*
//OLD:
public function getMonthlyViews($year, $month) {
$json = $this->getCustomerMetaValueByKey("monthly_views");
if(!$json) {
return false;
}
$data = json_decode($json, true);
return isset($data[$year."-".$month]) ? $data[$year."-".$month] : false;
}
public function getMonthlyClicks($year, $month) {
$json = $this->getCustomerMetaValueByKey("monthly_clicks");
if(!$json) {
return false;
}
$data = json_decode($json, true);
return isset($data[$year."-".$month]) ? $data[$year."-".$month] : false;
}
public function setMonthlyViews($year, $month, $views) {
$data = [];
$json = $this->getCustomerMetaValueByKey("monthly_views");
if($json) {
$data = json_decode($json, true);
}
$data[$year."-".$month] = $views;
$this->setCustomermetum("monthly_views", json_encode($data));
return $this;
}
public function setMonthlyClicks($year, $month, $clicks) {
$data = [];
$json = $this->getCustomerMetaValueByKey("monthly_clicks");
if($json) {
$data = json_decode($json, true);
}
$data[$year."-".$month] = $clicks;
$this->setCustomermetum("monthly_clicks", json_encode($data));
return $this;
}
*/
public function getTypeWork(): string
{
return $this->type_work;
}
public function setTypeWork(string $type_work = null): self
{
if (is_null($type_work)) {
$type_work = "";
}
$this->type_work = $type_work;
return $this;
}
/**
* @return Collection|Site[]
*/
public function getSite(): Collection
{
return $this->site;
}
public function getSites(): Collection
{
return $this->site;
}
public function addSite(Site $site): self
{
if (!$this->site->contains($site)) {
$this->site[] = $site;
$site->addCustomer($this);
}
return $this;
}
public function resetSite(): self
{
$this->site = new ArrayCollection();
return $this;
}
public function removeSite(Site $site): self
{
if ($this->site->contains($site)) {
$this->site->removeElement($site);
$site->removeCustomer($this);
}
return $this;
}
public function getSiteTextShort()
{
$site_texts = [];
foreach($this->getSite() as $s) {
$site_texts[] = $s->getSiteTextShort();
}
return implode(", ", $site_texts);
}
public function getSiteIds()
{
$site_ids = [];
foreach($this->getSite() as $s) {
$site_ids[] = $s->getId();
}
return $site_ids;
}
public function getLevels(): Collection
{
return $this->levels;
}
public function addLevel(CustomerSiteLevel $level): self
{
if (!$this->levels->contains($level)) {
$this->levels[] = $level;
$level->setCustomer($this);
}
return $this;
}
public function resetLevels(): self
{
$this->levels = new ArrayCollection();
return $this;
}
}