<?php
namespace DcSiteBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;use CoreBundle\Entity\Dealer;use Doctrine\Common\Collections\Collection;use Application\Sonata\MediaBundle\Entity\Media;
/**
* Vacancy
*/
class Vacancy
{
/**
* @var integer
*/
private $id;
/**
* @var integer
*/
private $state;
/** * @var Collection */ private $content;
/** * @var Dealer */ private $dealer;
/**
* @var int
*/
private $hot;
/**
* @var Media
*/
private $image;
/**
* Constructor
*/
public function __construct()
{
$this->content = new ArrayCollection();
$this->content->add((new VacancyContent())->setLanguage('ru'));
$this->content->add((new VacancyContent())->setLanguage('ua'));
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set state
*
* @param integer $state
*
* @return Vacancy
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get state
*
* @return integer
*/
public function getState()
{
return $this->state > 0;
}
/** * Add content * * @param VacancyContent $content * * @return Vacancy */ public function addContent(VacancyContent $content)
{
$this->content[] = $content;
return $this;
}
/** * Remove content * * @param VacancyContent $content */ public function removeContent(VacancyContent $content)
{
$this->content->removeElement($content);
}
/** * Get content * * @return Collection */ public function getContent()
{
return $this->content;
}
/** * Set dealer * * @param Dealer $dealer * * @return Vacancy */ public function setDealer(Dealer $dealer = null)
{
$this->dealer = $dealer;
return $this;
}
/** * Get dealer * * @return Dealer */ public function getDealer()
{
return $this->dealer;
}
/**
* @param $locale
* @return VacancyContent|mixed
*/
public function getContentByLang($locale) {
/** @var VacancyContent $row */
foreach ($this->content as $row) {
if($row->getLanguage() == $locale) return $row;
}
return $this->content->first();
}
/**
* @return string
*/
public function __toString()
{
return (string) $this->getTitle();
}
/**
* @return string
*/
public function getTitle($locale = null) {
return $this->getContentByLang($locale)->getTitle();
}
/**
* @return boolean
*/
public function getHot()
{
return $this->hot;
}
/**
* @param $hot
* @return $this
*/
public function setHot($hot)
{
$this->hot = $hot;
return $this;
}
/**
* @param Media $image
* @return $this
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* @return Media
*/
public function getImage()
{
return $this->image;
}
public function getSalary()
{
return $this->getContent()->first()->getSalary();
}
public function getCompanyName()
{
return $this->getContent()->first()->getCompanyName();
}
}