<?php
namespace App\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\AdsFacebookCampaignStaticReportRepository")
* @ORM\Table(name="`ads_facebook_campaign_static_report`")
*/
class AdsFacebookCampaignStaticReport
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $name = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="adsFacebookCampaignStaticReports")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private ?User $user;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\AdsFacebookCampaign")
* @ORM\JoinColumn(name="campaign_id", referencedColumnName="id")
*/
private ?AdsFacebookCampaign $campaign;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AdsFacebookCampaignStaticReportStatistic", mappedBy="report", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private Collection $statistics;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AdsFacebookCampaignStaticReportStatisticPlatform", mappedBy="report", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private Collection $platformStatistics;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected ?\DateTime $latestReportCreatedAt = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $hash;
public function __construct()
{
$this->hash = uniqid('', true);
}
public function getId(): ?int
{
return $this->id;
}
public function setId(?int $id): void
{
$this->id = $id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): void
{
$this->name = $name;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): void
{
$this->user = $user;
}
public function getCampaign(): ?AdsFacebookCampaign
{
return $this->campaign;
}
public function setCampaign(?AdsFacebookCampaign $campaign): void
{
$this->campaign = $campaign;
}
public function getStatistics(): Collection
{
return $this->statistics;
}
public function setStatistics(Collection $statistics): void
{
$this->statistics = $statistics;
}
public function getPlatformStatistics(): Collection
{
return $this->platformStatistics;
}
public function setPlatformStatistics(Collection $platformStatistics): void
{
$this->platformStatistics = $platformStatistics;
}
public function getLatestReportCreatedAt(): ?\DateTime
{
return $this->latestReportCreatedAt;
}
public function setLatestReportCreatedAt(?\DateTime $latestReportCreatedAt): void
{
$this->latestReportCreatedAt = $latestReportCreatedAt;
}
public function isReady(): bool
{
return null !== $this->getLatestReportCreatedAt();
}
public function getDisplayName(): string
{
if ($this->getName()) {
return $this->getName();
}
return strtolower($this->getCampaign()->getName());
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(?string $hash): void
{
$this->hash = $hash;
}
public function getImpressions(): int
{
$impressions = 0;
foreach ($this->statistics as $statistic) {
$impressions += $statistic->getImpressions();
}
return $impressions;
}
public function __toString(): string
{
return $this->id ?? 'New Facebook Ads Campaign Report';
}
}