<?php
namespace Products\SocialBundle\Entity;
use App\Model\Async\StringSemaphoreInterface;
use App\Model\Async\StringSemaphoreTrait;
use Cms\TenantBundle\Entity\TenantedEntity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SocialPost
* @package Products\SocialBundle\Entity
*
* @ORM\Entity(
* repositoryClass = "Products\SocialBundle\Doctrine\Repository\SocialPostRepository"
* )
* @ORM\Table(
* name = "smm__post"
* )
*/
class SocialPost extends TenantedEntity implements StringSemaphoreInterface
{
const STATUSES__SCHEDULED = 0;
const STATUSES__POSTED = 1;
const STATUSES__ERROR = -1;
use StringSemaphoreTrait;
/**
* @var SocialAccount
*
* @ORM\ManyToOne(
* targetEntity = "SocialAccount"
* )
* @ORM\JoinColumn(
* name = "socialAccount",
* referencedColumnName = "id",
* onDelete = "SET NULL"
* )
*/
protected $socialAccount;
/**
* @var string
*
* @ORM\Column(
* type = "text",
* nullable = false
* )
*/
protected $message;
/**
* @var string
*
* @ORM\Column(
* type = "text",
* nullable = true
* )
*/
protected $link;
/**
* @var array|string[]
*
* @ORM\Column(
* type = "json",
* nullable = true
* )
*/
protected $media = [];
/**
* @var DateTime
*
* @ORM\Column(
* type = "datetime",
* nullable = false
* )
*/
protected $postAt;
/**
* @var DateTime
*
* @ORM\Column(
* type = "datetime",
* nullable = true
* )
*/
protected $postedAt;
/**
* @var int
*
* @ORM\Column(
* type = "string",
* nullable = true
* )
*/
protected $postedId;
/**
* @var string
*
* @ORM\Column(
* type = "text",
* nullable = true
* )
*/
protected $postedDetails;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false,
* options = {
* "default" = SocialPost::STATUSES__SCHEDULED
* }
* )
*/
protected $status = self::STATUSES__SCHEDULED;
/**
* @var string
*
* @ORM\Column(
* type = "text",
* nullable = true
* )
*/
protected $errorTrace;
/**
* @return bool
*/
public function isPosted()
{
if ( ! empty($this->getPostedId())) {
return true;
}
return ($this->getStatus() !== self::STATUSES__SCHEDULED);
}
/**
* @return SocialAccount
*/
public function getSocialAccount()
{
return $this->socialAccount;
}
/**
* @param SocialAccount $value
* @return $this
*/
public function setSocialAccount(SocialAccount $value)
{
$this->socialAccount = $value;
return $this;
}
/**
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* @param string $value
* @return $this
*/
public function setMessage($value)
{
$this->message = $value;
return $this;
}
/**
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* @param string $value
* @return $this
*/
public function setLink($value)
{
$this->link = $value;
return $this;
}
/**
* @return array|string[]
*/
public function getMedia()
{
return array_values(array_unique(array_filter($this->media)));
}
/**
* @param array|string[] $value
* @return $this
*/
public function setMedia(array $value)
{
$this->media = array_values(array_unique(array_filter($value)));
return $this;
}
/**
* @return DateTime
*/
public function getPostAt()
{
return $this->postAt;
}
/**
* @param DateTime $value
* @return $this
*/
public function setPostAt(DateTime $value = null)
{
$this->postAt = $value;
return $this;
}
/**
* @return DateTime
*/
public function getPostedAt()
{
return $this->postedAt;
}
/**
* @param DateTime $value
* @return $this
*/
public function setPostedAt(DateTime $value = null)
{
$this->postedAt = $value;
return $this;
}
/**
* @return string
*/
public function getPostedId()
{
return $this->postedId;
}
/**
* @param string $value
* @return $this
*/
public function setPostedId($value)
{
$this->postedId = $value;
return $this;
}
/**
* @return string
*/
public function getPostedDetails()
{
return $this->postedDetails;
}
/**
* @param string $value
* @return $this
*/
public function setPostedDetails($value)
{
$this->postedDetails = $value;
return $this;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* @param int $value
* @return $this
*/
public function setStatus($value)
{
$this->status = $value;
return $this;
}
/**
* @return string
*/
public function getErrorTrace()
{
return $this->errorTrace;
}
/**
* @param string $value
* @return $this
*/
public function setErrorTrace($value)
{
$this->errorTrace = $value;
return $this;
}
}