src/DcSiteBundle/Entity/ServiceWorkCategory.php line 13

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