HosipLan

Untitled

Dec 20th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. /**
  2.  * @Entity
  3.  */
  4. class Category extends Nette\Object
  5. {
  6.  
  7.     /**
  8.      * @OneToMany(targetEntity="Article", mappedBy="highlightedIn")
  9.      */
  10.     private $highlighted;
  11.  
  12.     /**
  13.      * @OneToMany(targetEntity="Article", mappedBy="category")
  14.      */
  15.     private $articles;
  16.  
  17.     public function getArticles()
  18.     {
  19.         return $this->articles->toArray();
  20.     }
  21.  
  22.  
  23.     public function getHighlighted()
  24.     {
  25.         return $this->highlighted->toArray();
  26.     }
  27.  
  28. }
  29.  
  30. /**
  31.  * @Entity
  32.  */
  33. class Article extends Nette\Object
  34. {
  35.  
  36.     /**
  37.      * @ManyToOne(targetEntity="Category", inversedBy="highlighted")
  38.      */
  39.     private $highlightedIn;
  40.  
  41.     /**
  42.      * @ManyToOne(targetEntity="Category", inversedBy="articles")
  43.      */
  44.     private $category;
  45.  
  46.  
  47.     public function setCategory(Category $category)
  48.     {
  49.         $this->category = $category;
  50.         // $category->articles->add($this);
  51.     }
  52.  
  53.  
  54.     public function setHighlighted(Category $category)
  55.     {
  56.         $this->highlightedIn = $category;
  57.         // $category->highlighted->add($this);
  58.     }
  59.  
  60. }
  61.  
  62.  
  63. $category = new Category();
  64.  
  65. $fooArticle = new Article();
  66. $fooArticle->setCategory($category);
  67.  
  68. $barArticle = new Article();
  69. $barArticle->setCategory($category);
  70. $barArticle->setHighlighted($category);
  71.  
  72.  
  73. // ...
  74.  
  75. $category->getArticles() // foo, bar
  76. $category->getHighlighted() // bar
Advertisement
Add Comment
Please, Sign In to add comment