src/AtechNet/CoreBundle/Entity/StaticPage.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping\Entity;
  5. use Doctrine\ORM\Mapping\JoinColumn;
  6. use Doctrine\ORM\Mapping\ManyToOne;
  7. use Doctrine\ORM\Mapping\OneToMany;
  8. use Doctrine\ORM\Mapping\OrderBy;
  9. use Doctrine\ORM\Mapping\Table as Table;
  10. /**
  11.  * StaticPage
  12.  *
  13.  * @Table(name="pages_static")
  14.  * @Entity()
  15.  */
  16. class StaticPage extends AbstractPage
  17. {
  18.     /**
  19.      * @var Domain
  20.      *
  21.      * @ManyToOne(targetEntity="Domain")
  22.      * @JoinColumn(name="domain_id", referencedColumnName="id")
  23.      */
  24.     private $domain;
  25.     /**
  26.      * @var ArrayCollection
  27.      *
  28.      * @OneToMany(targetEntity="PageMeta", mappedBy="staticPage", orphanRemoval=true, cascade={"persist", "remove"})
  29.      * @OrderBy({"id" = "ASC"})
  30.      **/
  31.     private $metas;
  32.     public function __construct()
  33.     {
  34.         parent::__construct();
  35.         $this->metas = new ArrayCollection();
  36.     }
  37.     /**
  38.      * @return Domain
  39.      */
  40.     public function getDomain()
  41.     {
  42.         return $this->domain;
  43.     }
  44.     /**
  45.      * @param Domain $domain
  46.      */
  47.     public function setDomain($domain)
  48.     {
  49.         $this->domain = $domain;
  50.     }
  51.     /**
  52.      * @return string
  53.      */
  54.     public function getLink()
  55.     {
  56.         return $this->link;
  57.     }
  58.     /**
  59.      * @param string $link
  60.      */
  61.     public function setLink($link)
  62.     {
  63.         $this->link = $link;
  64.     }
  65.     /**
  66.      * @return ArrayCollection
  67.      */
  68.     public function getMetas()
  69.     {
  70.         return $this->metas;
  71.     }
  72.     /**
  73.      * @return string
  74.      */
  75.     public function getLanguage()
  76.     {
  77.         return $this->getDomain()->getLanguage()->getCode();
  78.     }
  79.     /**
  80.      * @param Language $language
  81.      * @return null|PageMeta
  82.      */
  83.     public function getMetaByLanguage(Language $language)
  84.     {
  85.         foreach ($this->getMetas() as $meta) {
  86.             if ($meta->getLanguage()->getCode() == $language->getCode()) {
  87.                 return $meta;
  88.             }
  89.         }
  90.         return null;
  91.     }
  92.     /**
  93.      * @param string $code
  94.      * @return null|PageMeta
  95.      */
  96.     public function getMetaByCode($code)
  97.     {
  98.         foreach ($this->getMetas() as $meta) {
  99.             if ($meta->getLanguage()->getCode() == $code) {
  100.                 return $meta;
  101.             }
  102.         }
  103.         return null;
  104.     }
  105. }