<?php
/**
* Created by PhpStorm.
* User: lisavandaele
* Date: 30/01/15
* Time: 12:53
*/
namespace Notaris\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Eko\FeedBundle\Field\Item\GroupItemField;
use Eko\FeedBundle\Field\Item\ItemField;
use Eko\FeedBundle\Field\Item\MediaItemField;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Eko\FeedBundle\Item\Writer\RoutedItemInterface; //RSS
/**
* @ORM\Entity(repositoryClass="NewsRepository")
* @ORM\Table(name="news")
*/
class News implements RoutedItemInterface{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @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\ManyToOne(targetEntity="Notaris\AdminBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $user;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="subtitle", type="string", length=255)
*/
private $subtitle;
/**
* @ORM\Column(type="text", name="introduction")
*/
private $introduction;
/**
* @ORM\Column(type="text", name="text")
*/
private $text;
/**
* @ORM\OneToOne(targetEntity="Asset")
* @ORM\JoinColumn(name="asset_id", referencedColumnName="id")
*/
protected $asset;
/**
* @var string
*
* @ORM\Column(name="source", type="string", length=255)
*/
private $source;
/**
* @var string
*
* @ORM\Column(name="author", type="string", length=255)
*/
private $author;
/**
* @ORM\Column(type="boolean", name="is_active")
* @Assert\Type("boolean")
*/
private $isActive;
/**
* @ORM\Column(name="pub_date", type="datetime")
*/
private $publicationDate;
/**
* @ORM\Column(type="boolean", name="home")
* @Assert\Type("boolean")
*/
private $home;
/**
* @ORM\Column(type="boolean", name="in_newsletter")
* @Assert\Type("boolean")
*/
private $inNewsletter;
/**
* @ORM\Column(type="boolean", name="in_kabinetsmail")
* @Assert\Type("boolean")
*/
private $inKabinetsMail;
/**
* @ORM\Column(name="newsletter_sended", type="datetime", nullable=true)
*/
private $newsletterSended;
/**
* @ORM\ManyToMany(targetEntity="Subsite")
* @ORM\JoinTable(name="news_subsite")
*/
protected $subsites;
/**
* @ORM\ManyToMany(targetEntity="IzimiCategory")
* @ORM\JoinTable(name="news_original_izimi_category")
*/
protected $categories;
/**
* @ORM\Column(type="boolean", name="is_izimi")
* @Assert\Type("boolean")
*/
private $isIzimi;
/**
* @ORM\Column(type="boolean", name="spotlight")
* @Assert\Type("boolean")
*/
private $spotlight;
/**
* @ORM\OneToOne(targetEntity="Meta", cascade={"remove"})
* @ORM\JoinColumn(name="meta_id", referencedColumnName="id")
*/
protected $meta;
/**
* @var string
*
* @ORM\Column(name="locale", type="string", length=5)
*/
private $locale;
/**
* @ORM\Column(type="boolean", name="is_pers")
* @Assert\Type("boolean")
*/
private $isPers;
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @ORM\OneToOne(targetEntity="Faq", mappedBy="news", cascade={"persist"})
*/
private $faq;
/**
* @ORM\OneToOne(targetEntity="Video", mappedBy="news", cascade={"persist"})
*/
private $video;
/**
* @ORM\OneToOne(targetEntity="Brochure", mappedBy="news", cascade={"persist"})
*/
private $brochure;
/**
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="newsitems")
* @ORM\JoinTable(name="tag_news")
*/
protected $tags;
/**
* @ORM\Column(type="boolean", name="is_reduced", nullable=true)
* @Assert\Type("boolean")
*/
private $isReduced;
/**
* @var integer
*
* @ORM\Column(type="integer", name="count_clicked")
*/
private $countClicked = 0;
/**
* @ORM\OneToOne(targetEntity="Asset")
* @ORM\JoinColumn(name="first_paragraph_asset_id", referencedColumnName="id")
*/
protected $firstParagraphAsset;
/**
* @ORM\OneToMany(targetEntity="NewsParagraph", mappedBy="news")
*/
private $paragraphs;
/**
* Constructor
*/
public function __construct()
{
$this->subsites = new \Doctrine\Common\Collections\ArrayCollection();
$this->inKabinetsMail = false;
$this->isIzimi = false;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set created
*
* @param \DateTime $created
* @return News
*/
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 News
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set title
*
* @param string $title
* @return News
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set subtitle
*
* @param string $subtitle
* @return News
*/
public function setSubtitle($subtitle)
{
$this->subtitle = $subtitle;
return $this;
}
/**
* Get subtitle
*
* @return string
*/
public function getSubtitle()
{
return $this->subtitle;
}
/**
* Set introduction
*
* @param string $introduction
* @return News
*/
public function setIntroduction($introduction)
{
$this->introduction = $introduction;
return $this;
}
/**
* Get introduction
*
* @return string
*/
public function getIntroduction()
{
return $this->introduction;
}
/**
* Set source
*
* @param string $source
* @return News
*/
public function setSource($source)
{
$this->source = $source;
return $this;
}
/**
* Get source
*
* @return string
*/
public function getSource()
{
return $this->source;
}
/**
* Set author
*
* @param string $author
* @return News
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set publicationDate
*
* @param \DateTime $publicationDate
* @return News
*/
public function setPublicationDate($publicationDate)
{
$this->publicationDate = $publicationDate;
return $this;
}
/**
* Get publicationDate
*
* @return \DateTime
*/
public function getPublicationDate()
{
return $this->publicationDate;
}
/**
* Set home
*
* @param boolean $home
* @return News
*/
public function setHome($home)
{
$this->home = $home;
return $this;
}
/**
* Get home
*
* @return boolean
*/
public function getHome()
{
return $this->home;
}
/**
* Set inNewsletter
*
* @param boolean $inNewsletter
* @return News
*/
public function setInNewsletter($inNewsletter)
{
$this->inNewsletter = $inNewsletter;
return $this;
}
/**
* Get inNewsletter
*
* @return boolean
*/
public function getInNewsletter()
{
return $this->inNewsletter;
}
/**
* Set spotlight
*
* @param boolean $spotlight
* @return News
*/
public function setSpotlight($spotlight)
{
$this->spotlight = $spotlight;
return $this;
}
/**
* Get spotlight
*
* @return boolean
*/
public function getSpotlight()
{
return $this->spotlight;
}
/**
* Set locale
*
* @param string $locale
* @return News
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* @return string
*/
public function getLocale()
{
return $this->locale;
}
/**
* Set isPers
*
* @param boolean $isPers
* @return News
*/
public function setIsPers($isPers)
{
$this->isPers = $isPers;
return $this;
}
/**
* Get isPers
*
* @return boolean
*/
public function getIsPers()
{
return $this->isPers;
}
/**
* Set slug
*
* @param string $slug
* @return News
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set isReduced
*
* @param boolean $isReduced
* @return News
*/
public function setIsReduced($isReduced)
{
$this->isReduced = $isReduced;
return $this;
}
/**
* Get isReduced
*
* @return boolean
*/
public function getIsReduced()
{
return $this->isReduced;
}
/**
* Set user
*
* @param \Notaris\AdminBundle\Entity\User $user
* @return News
*/
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;
}
/**
* Add subsites
*
* @param \Notaris\AdminBundle\Entity\Subsite $subsites
* @return News
*/
public function addSubsite(\Notaris\AdminBundle\Entity\Subsite $subsites)
{
$this->subsites[] = $subsites;
return $this;
}
/**
* Remove subsites
*
* @param \Notaris\AdminBundle\Entity\Subsite $subsites
*/
public function removeSubsite(\Notaris\AdminBundle\Entity\Subsite $subsites)
{
$this->subsites->removeElement($subsites);
}
/**
* Get subsites
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSubsites()
{
return $this->subsites;
}
/**
* Set video
*
* @param \Notaris\AdminBundle\Entity\Video $video
* @return News
*/
public function setVideo(\Notaris\AdminBundle\Entity\Video $video = null)
{
$this->video = $video;
return $this;
}
/**
* Get video
*
* @return \Notaris\AdminBundle\Entity\Video
*/
public function getVideo()
{
return $this->video;
}
/**
* Add tags
*
* @param \Notaris\AdminBundle\Entity\Tag $tags
* @return News
*/
public function addTag(\Notaris\AdminBundle\Entity\Tag $tags)
{
$this->tags[] = $tags;
return $this;
}
/**
* Remove tags
*
* @param \Notaris\AdminBundle\Entity\Tag $tags
*/
public function removeTag(\Notaris\AdminBundle\Entity\Tag $tags)
{
$this->tags->removeElement($tags);
}
/**
* Get tags
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTags()
{
return $this->tags;
}
/**
* Set meta
*
* @param \Notaris\AdminBundle\Entity\Meta $meta
* @return News
*/
public function setMeta(\Notaris\AdminBundle\Entity\Meta $meta = null)
{
$this->meta = $meta;
return $this;
}
/**
* Get meta
*
* @return \Notaris\AdminBundle\Entity\Meta
*/
public function getMeta()
{
return $this->meta;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return News
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set brochure
*
* @param \Notaris\AdminBundle\Entity\Brochure $brochure
* @return News
*/
public function setBrochure(\Notaris\AdminBundle\Entity\Brochure $brochure = null)
{
$this->brochure = $brochure;
return $this;
}
/**
* Get brochure
*
* @return \Notaris\AdminBundle\Entity\Brochure
*/
public function getBrochure()
{
return $this->brochure;
}
/**
* Set asset
*
* @param \Notaris\AdminBundle\Entity\Asset $asset
* @return News
*/
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 text
*
* @param string $text
* @return News
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get text
*
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Set countClicked
*
* @param integer $countClicked
* @return News
*/
public function setCountClicked($countClicked)
{
$this->countClicked = $countClicked;
return $this;
}
/**
* Get countClicked
*
* @return integer
*/
public function getCountClicked()
{
return $this->countClicked;
}
/**
* Set newsletterSended
*
* @param \DateTime $newsletterSended
* @return News
*/
public function setNewsletterSended($newsletterSended)
{
$this->newsletterSended = $newsletterSended;
return $this;
}
/**
* Get newsletterSended
*
* @return \DateTime
*/
public function getNewsletterSended()
{
return $this->newsletterSended;
}
/**
* Set faq
*
* @param \Notaris\AdminBundle\Entity\Faq $faq
* @return News
*/
public function setFaq(\Notaris\AdminBundle\Entity\Faq $faq = null)
{
$this->faq = $faq;
return $this;
}
/**
* Get faq
*
* @return \Notaris\AdminBundle\Entity\Faq
*/
public function getFaq()
{
return $this->faq;
}
/**
* @return string
*/
public function __toString(){
return $this->getTitle();
}
/**
* Set inKabinetsMail
*
* @param boolean $inKabinetsMail
*
* @return News
*/
public function setInKabinetsMail($inKabinetsMail)
{
$this->inKabinetsMail = $inKabinetsMail;
return $this;
}
/**
* Get inKabinetsMail
*
* @return boolean
*/
public function getInKabinetsMail()
{
return $this->inKabinetsMail;
}
/**
* Set firstParagraphAsset
*
* @param \Notaris\AdminBundle\Entity\Asset $firstParagraphAsset
* @return News
*/
public function setFirstParagraphAsset(\Notaris\AdminBundle\Entity\Asset $firstParagraphAsset = null)
{
$this->firstParagraphAsset = $firstParagraphAsset;
return $this;
}
/**
* Get firstParagraphAsset
*
* @return \Notaris\AdminBundle\Entity\Asset
*/
public function getFirstParagraphAsset()
{
return $this->firstParagraphAsset;
}
/**
* Add paragraph
*
* @param \Notaris\AdminBundle\Entity\NewsParagraph $paragraph
*
* @return Article
*/
public function addParagraph(\Notaris\AdminBundle\Entity\NewsParagraph $paragraph)
{
$this->paragraphs[] = $paragraph;
return $this;
}
/**
* Remove paragraph
*
* @param \Notaris\AdminBundle\Entity\NewsParagraph $paragraph
*/
public function removeParagraph(\Notaris\AdminBundle\Entity\NewsParagraph $paragraph)
{
$this->paragraphs->removeElement($paragraph);
}
/**
* Get paragraphs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getParagraphs()
{
return $this->paragraphs;
}
//RSS methods
public function getFeedItemTitle()
{
return $this->title;
}
public function getFeedItemDescription()
{
$description = '';
if($this->subtitle){
$description = '<h4>'.$this->subtitle.'</h4>';
}
if($this->introduction){
$description = '<p>'.$this->introduction.'</p>';
}
//images
if($this->asset and sizeof($this->asset->getAssetImages()) > 0 ){
foreach ($this->asset->getAssetImages() as $assetImage){
if($assetImage->getImage()){
$image = $assetImage->getImage();
$domain = 'https://www.notaris.be/';
if($image->getLocale() != 'nl'){
$domain = 'https://www.notaire.be/';
}
$description .= '<p><img src='.$domain .'uploads/' . $image->getLocale() . $image->getFilename(). ' alt="'.$image->getCaption().'"/></p>';
}
}
}
$description .= $this->text;
//video
if($this->asset and sizeof($this->asset->getAssetVideoPaths()) > 0 ){
// $description .= '<div>';
foreach ($this->asset->getAssetVideoPaths() as $assetImage){
if($assetImage->getVideoPath()){
$video = $assetImage->getVideoPath();
$domain = 'http://notaris.be/';
if($video->getLocale() != 'nl'){
$domain = 'https://www.notaire.be/';
}
if($video->getPath() != '') {
$description .= '<video width="610" height="347" controls><source src="'.$domain . 'video/' . $video->getLocale() . '/' . $video->getPath().'"></video>';
}elseif($video->getYoutube() != ''){
$description .= '<iframe frameborder="0" allowfullscreen="1" title="YouTube video player" width="490" height="280" src="//www.youtube-nocookie.com/embed/'.$video->getYoutube().'?enablejsapi=1&widgetid=1" kwframeid="2"></iframe>';
}
}
}
// $description .= '</div>';
}
//links
if($this->asset and sizeof($this->asset->getAssetLinks()) > 0 ){
$description .='<ul>';
foreach ($this->asset->getAssetLinks() as $assetImage){
if($assetImage->getLink()){
$link = $assetImage->getLink();
$title = $link->getTitle();
$url = $link->getUrl();
$description .= '<li><a href='.$url.'>'.$title.'</a></li>';
}
}
$description .='</ul>';
}
//bijlagen
if($this->asset and sizeof($this->asset->getAssetAttachments()) > 0 ){
$description .='<ul>';
foreach ($this->asset->getAssetAttachments() as $assetImage){
if($assetImage->getAttachment()){
$attachment = $assetImage->getAttachment();
$domain = 'https://www.notaris.be/';
if($attachment->getLocale() != 'nl'){
$domain = 'https://www.notaire.be/';
}
$description .= '<li><a href='.$domain .'uploads/' . $attachment->getLocale() . $attachment->getFilename().'>'.$attachment->getOriginalFilename().'</a></li>';
}
}
$description .='</ul>';
}
//bron + auteur
if($this->getSource()){
$bron = 'Bron';
if($this->getLocale() != 'nl'){
$bron = 'Source';
}
$description .= '<p>'.$bron.':'. $this->getSource().'</p>';
}
if($this->getAuthor()){
$auteur = 'Auteur';
$description .= '<p>'.$auteur.':'. $this->getAuthor().'</p>';
}
return $description;
}
public function getFeedItemIntroduction()
{
return $this->introduction;
}
public function getFeedItemSubtitle()
{
return $this->subtitle;
}
public function getFeedItemPubDate()
{
return $this->getPublicationDate();
}
public function getFeedItemRouteName()
{
return 'notaris_frontend_news_detail';
}
public function getFeedItemRouteParameters()
{
return array('slug' => $this->slug);
}
public function getFeedItemUrlAnchor()
{
return '';
}
/**
* Add category
*
* @param \Notaris\AdminBundle\Entity\IzimiCategory $category
*
* @return News
*/
public function addCategory(\Notaris\AdminBundle\Entity\IzimiCategory $category)
{
$this->categories[] = $category;
return $this;
}
/**
* Remove category
*
* @param \Notaris\AdminBundle\Entity\IzimiCategory $category
*/
public function removeCategory(\Notaris\AdminBundle\Entity\IzimiCategory $category)
{
$this->categories->removeElement($category);
}
/**
* Get categories
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCategories()
{
return $this->categories;
}
/**
* Set isIzimi
*
* @param boolean $isIzimi
* @return News
*/
public function setIsIzimi(bool $isIzimi)
{
$this->isIzimi = $isIzimi;
return $this;
}
/**
* Get isIzimi
*
* @return boolean
*/
public function getIsIzimi()
{
return $this->isIzimi;
}
/**
* Returns a custom media field
*
* @return string
*/
public function getFeedMediaItem()
{
$mediaItems = array();
if($this->asset and sizeof($this->asset->getAssetImages()) > 0 ){
foreach ($this->asset->getAssetImages() as $assetImage){
if($assetImage->getImage()){
$image = $assetImage->getImage();
$domain = 'https://www.notaris.be/';
if($image->getLocale() != 'nl'){
$domain = 'https://www.notaire.be/';
}
$mediaItems[] = array(
'type' => 'image/jpeg',
'length' => 500,
'value' => $domain .'uploads/' . $image->getLocale() . $image->getFilename()
);
}
}
}
return $mediaItems;
}
/**
* Returns a custom media field
*
* @return string
*/
public function getFeedAttachmentMediaItem()
{
$mediaItems = array();
if($this->asset and sizeof($this->asset->getAssetAttachments()) > 0 ){
foreach ($this->asset->getAssetAttachments() as $assetImage){
if($assetImage->getAttachment()){
$attachment = $assetImage->getAttachment();
$domain = 'https://www.notaris.be/';
if($attachment->getLocale() != 'nl'){
$domain = 'https://www.notaire.be/';
}
$mediaItems[] = array(
'type' => $attachment->getFileType(),
'length' => 500,
'value' => $domain .'uploads/' . $attachment->getLocale() . $attachment->getFilename()
);
}
}
}
return $mediaItems;
}
/**
* Returns a custom media field
*
* @return string
*/
public function getFeedVideoMediaItem()
{
$mediaItems = array();
if($this->asset and sizeof($this->asset->getAssetVideoPaths()) > 0 ){
foreach ($this->asset->getAssetVideoPaths() as $assetImage){
if($assetImage->getVideoPath()){
$video = $assetImage->getVideoPath();
$domain = 'https://www.notaris.be/';
if($video->getLocale() != 'nl'){
$domain = 'https://www.notaire.be/';
}
if($video->getPath() != '') {
$mediaItems[] = array(
'type' => 'video/mp4',
'length' => 500,
'value' => $domain . 'video/' . $video->getLocale() . '/' . $video->getPath()
);
}
}
}
}
return $mediaItems;
}
/**
* Returns a custom media field
*
* @return string
*/
public function getLinkItems()
{
$items = array();
if($this->asset and sizeof($this->asset->getAssetLinks()) > 0 ){
foreach ($this->asset->getAssetLinks() as $assetImage){
if($assetImage->getLink()){
$link = $assetImage->getLink();
$title = $link->getTitle();
$url = $link->getUrl();
$items[] =
new GroupItemField('link', array(
new ItemField('url', $url),
new ItemField('title', $title),
));
}
}
}
return new GroupItemField('links', array($items));
// return array($items);
}
}