<?php
/**
* Created by PhpStorm.
* User: lisavandaele
* Date: 30/01/15
* Time: 12:53
*/
namespace Notaris\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="SectionModuleRepository")
* @ORM\Table(name="section_module")
*/
class SectionModule {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Notaris\AdminBundle\Entity\Module")
* @ORM\JoinColumn(name="module_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $module;
/**
* @var string
*
* @ORM\Column(name="title", type="text", nullable = true)
*/
private $title;
/**
* @ORM\Column(type="text", name="text", nullable = true)
*/
private $text;
/**
* @ORM\OneToOne(targetEntity="Asset")
* @ORM\JoinColumn(name="asset_id", referencedColumnName="id")
*/
protected $asset;
/**
* @ORM\Column(type="boolean", name="is_active")
* @Assert\Type("boolean")
*/
private $isActive;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* @ORM\Column(name="updated", type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $updated;
/**
* @ORM\Column(name="pub_date", type="datetime")
*/
private $publicationDate;
/**
* @ORM\ManyToOne(targetEntity="Notaris\AdminBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="Notaris\AdminBundle\Entity\Section", inversedBy="modules")
* @ORM\JoinColumn(name="section_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $section;
/**
* @var integer
*
* @ORM\Column(type="integer")
*/
private $position = 0;
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @var string
*
* @ORM\Column(name="locale", type="string", length=5)
*/
private $locale;
/**
* @return string
*/
public function getRenderStatus()
{
if ($this->getIsActive()) {
$now = new \DateTime('now');
$date = $this->getPublicationDate();
if ($date <= $now) {
return '<span class="label label-success">ON</span>';
}
return '<span class="label label-warning">...</span>';
}
return '<span class="label label-danger">OFF</span>';
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return SectionModule
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set text
*
* @param string $text
* @return SectionModule
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get text
*
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Get text's first line
*
* @return string
*/
public function getTextFirstLine()
{
return html_entity_decode(strip_tags(mb_substr($this->text , 0, mb_strpos($this->text, '</p>'))));
}
/**
* Set created
*
* @param \DateTime $created
* @return SectionModule
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param \DateTime $updated
* @return SectionModule
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set publicationDate
*
* @param \DateTime $publicationDate
* @return SectionModule
*/
public function setPublicationDate($publicationDate)
{
$this->publicationDate = $publicationDate;
return $this;
}
/**
* Get publicationDate
*
* @return \DateTime
*/
public function getPublicationDate()
{
return $this->publicationDate;
}
/**
* Set position
*
* @param integer $position
* @return SectionModule
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return integer
*/
public function getPosition()
{
return $this->position;
}
/**
* Set module
*
* @param \Notaris\AdminBundle\Entity\Module $module
* @return SectionModule
*/
public function setModule(\Notaris\AdminBundle\Entity\Module $module = null)
{
$this->module = $module;
return $this;
}
/**
* Get module
*
* @return \Notaris\AdminBundle\Entity\Module
*/
public function getModule()
{
return $this->module;
}
/**
* Set user
*
* @param \Notaris\AdminBundle\Entity\User $user
* @return SectionModule
*/
public function setUser(\Notaris\AdminBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Notaris\AdminBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set section
*
* @param \Notaris\AdminBundle\Entity\Section $section
* @return SectionModule
*/
public function setSection(\Notaris\AdminBundle\Entity\Section $section = null)
{
$this->section = $section;
return $this;
}
/**
* Get section
*
* @return \Notaris\AdminBundle\Entity\Section
*/
public function getSection()
{
return $this->section;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return SectionModule
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Constructor
*/
public function __construct()
{
}
/**
* Set asset
*
* @param \Notaris\AdminBundle\Entity\Asset $asset
* @return SectionModule
*/
public function setAsset(\Notaris\AdminBundle\Entity\Asset $asset = null)
{
$this->asset = $asset;
return $this;
}
/**
* Get asset
*
* @return \Notaris\AdminBundle\Entity\Asset
*/
public function getAsset()
{
return $this->asset;
}
/**
* Set slug
*
* @param string $slug
* @return SectionModule
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set locale
*
* @param string $locale
* @return SectionModule
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* @return string
*/
public function getLocale()
{
return $this->locale;
}
}