src/CoreBundle/Entity/ServicePage.php line 14

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Application\Sonata\MediaBundle\Entity\Media;
  5. use DcSiteBundle\Entity\Job;
  6. use Doctrine\Common\Collections\Collection;
  7. use DcSiteBundle\Entity\PageContent;
  8. /**
  9.  * ServicePage
  10.  */
  11. class ServicePage
  12. {
  13.     /**
  14.      * @var integer
  15.      */
  16.     private $id;
  17.     /**
  18.      * @var boolean
  19.      */
  20.     private $state;
  21.     /**
  22.      * @var string
  23.      */
  24.     private $url;
  25.     /**
  26.      * @var integer
  27.      */
  28.     private $position;
  29.     /**
  30.      * @var Media
  31.      */
  32.     private $image;
  33.     /**
  34.      * @var Collection
  35.      */
  36.     private $content;
  37.     /**
  38.      * @var string
  39.      */
  40.     private $uid_1c;
  41.     /**
  42.      * @var Dealer
  43.      */
  44.     private $dealer;
  45.     /**
  46.      * @var Collection
  47.      */
  48.     private $jobs;
  49.     /**
  50.      * Constructor
  51.      */
  52.     public function __construct()
  53.     {
  54.         $this->content = new ArrayCollection();
  55.         $this->content->add((new ServicePageContent())->setLanguage('ru'));
  56.         $this->content->add((new ServicePageContent())->setLanguage('ua'));
  57.     }
  58.     /**
  59.      * Get id
  60.      *
  61.      * @return integer
  62.      */
  63.     public function getId()
  64.     {
  65.         return $this->id;
  66.     }
  67.     /**
  68.      * Get title
  69.      *
  70.      * @return string
  71.      */
  72.     public function getTitle()
  73.     {
  74.         return $this->getContentByLocale()->getTitle();
  75.     }
  76.     /**
  77.      * Set state
  78.      *
  79.      * @param boolean $state
  80.      *
  81.      * @return ServicePage
  82.      */
  83.     public function setState($state)
  84.     {
  85.         $this->state $state;
  86.         return $this;
  87.     }
  88.     /**
  89.      * Get state
  90.      *
  91.      * @return boolean
  92.      */
  93.     public function getState()
  94.     {
  95.         return $this->state;
  96.     }
  97.     /**
  98.      * Set url
  99.      *
  100.      * @param string $url
  101.      *
  102.      * @return ServicePage
  103.      */
  104.     public function setUrl($url)
  105.     {
  106.         $this->url $url;
  107.         return $this;
  108.     }
  109.     /**
  110.      * Get url
  111.      *
  112.      * @return string
  113.      */
  114.     public function getUrl()
  115.     {
  116.         return $this->url;
  117.     }
  118.     /**
  119.      * Set position
  120.      *
  121.      * @param integer $position
  122.      *
  123.      * @return ServicePage
  124.      */
  125.     public function setPosition($position)
  126.     {
  127.         $this->position $position;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Get position
  132.      *
  133.      * @return integer
  134.      */
  135.     public function getPosition()
  136.     {
  137.         return $this->position;
  138.     }
  139.     /**
  140.      * Set image
  141.      *
  142.      * @param Media $image
  143.      *
  144.      * @return ServicePage
  145.      */
  146.     public function setImage(Media $image null)
  147.     {
  148.         $this->image $image;
  149.         return $this;
  150.     }
  151.     /**
  152.      * Get image
  153.      *
  154.      * @return Media
  155.      */
  156.     public function getImage()
  157.     {
  158.         return $this->image;
  159.     }
  160.     /**
  161.      * Add content
  162.      *
  163.      * @param ServicePageContent $content
  164.      *
  165.      * @return ServicePage
  166.      */
  167.     public function addContent(ServicePageContent $content)
  168.     {
  169.         $this->content[] = $content;
  170.         return $this;
  171.     }
  172.     /**
  173.      * Remove content
  174.      *
  175.      * @param ServicePageContent $content
  176.      */
  177.     public function removeContent(ServicePageContent $content)
  178.     {
  179.         $this->content->removeElement($content);
  180.     }
  181.     /**
  182.      * Get content
  183.      *
  184.      * @return Collection
  185.      */
  186.     public function getContent()
  187.     {
  188.         return $this->content;
  189.     }
  190.     /**
  191.      * @var Collection
  192.      */
  193.     private $categories;
  194.     /**
  195.      * Add page
  196.      *
  197.      * @param ServicePageCategory $category
  198.      *
  199.      * @return ServicePage
  200.      */
  201.     public function addCategory(ServicePageCategory $category)
  202.     {
  203.         $this->categories[] = $category;
  204.         return $this;
  205.     }
  206.     /**
  207.      * Remove page
  208.      *
  209.      * @param ServicePageCategory $category
  210.      */
  211.     public function removeCategory(ServicePageCategory $category)
  212.     {
  213.         $this->categories->removeElement($category);
  214.     }
  215.     /**
  216.      * Set category
  217.      *
  218.      * @param ServicePageCategory $category
  219.      *
  220.      * @return ServicePageCategory
  221.      */
  222.     public function setCategories(ServicePageCategory $category null)
  223.     {
  224.         $this->category $category;
  225.         return $this;
  226.     }
  227.     /**
  228.      * Get category
  229.      *
  230.      * @return Collection
  231.      */
  232.     public function getCategories()
  233.     {
  234.         return $this->categories;
  235.     }
  236.     /**
  237.      * Set uid1c
  238.      *
  239.      * @param string $uid1c
  240.      *
  241.      * @return ServicePage
  242.      */
  243.     public function setUid1c($uid1c)
  244.     {
  245.         $this->uid_1c $uid1c;
  246.         return $this;
  247.     }
  248.     /**
  249.      * Get uid1c
  250.      *
  251.      * @return string
  252.      */
  253.     public function getUid1c()
  254.     {
  255.         return $this->uid_1c;
  256.     }
  257.     /**
  258.      * Set dealer
  259.      *
  260.      * @param Dealer $dealer
  261.      *
  262.      * @return ServicePage
  263.      */
  264.     public function setDealer(Dealer $dealer null)
  265.     {
  266.         $this->dealer $dealer;
  267.         return $this;
  268.     }
  269.     /**
  270.      * Get dealer
  271.      *
  272.      * @return Dealer
  273.      */
  274.     public function getDealer()
  275.     {
  276.         return $this->dealer;
  277.     }
  278.     public function __toString()
  279.     {
  280.         return $this->content->first() ? (string) $this->content->first()->getTitle() : '';
  281.     }
  282.     public function getContentByLocale($locale 'ru')
  283.     {
  284.         /** @var ServicePageContent $content */
  285.         foreach ($this->content as $content) {
  286.             if($content->getLanguage() == $locale) {
  287.                 return $content;
  288.             }
  289.         }
  290.         return $this->content->first();
  291.     }
  292.     /**
  293.      * Add job
  294.      *
  295.      * @param Job $job
  296.      *
  297.      * @return ServicePage
  298.      */
  299.     public function addJob(Job $job)
  300.     {
  301.         $this->jobs[] = $job;
  302.         return $this;
  303.     }
  304.     /**
  305.      * Remove job
  306.      *
  307.      * @param Job $job
  308.      */
  309.     public function removeJob(Job $job)
  310.     {
  311.         $this->jobs->removeElement($job);
  312.     }
  313.     /**
  314.      * Get jobs
  315.      *
  316.      * @return Collection
  317.      */
  318.     public function getJobs()
  319.     {
  320.         return $this->jobs;
  321.     }
  322. }