Advertisement
Guest User

Untitled

a guest
Apr 14th, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2.  
  3. namespace ArticleModule;
  4.  
  5. /**
  6.  * @property-read int $id
  7.  * @property string $title
  8.  * @property string $perex
  9.  * @property string $content
  10.  * @property string $visibility
  11.  * @property string $type
  12.  * @property string $status
  13.  * @property int $order
  14.  * @property DateTime $created
  15.  * @property DateTime|NULL $modified
  16.  * @property int|NULL $parent_id
  17.  * @property int $user_id
  18.  */
  19. class Article extends \YetORM\Entity {
  20.  
  21.     /** @param int $id */
  22.     public function setId($id) {}
  23.  
  24.     /** @return \YetORM\EntityCollection */
  25.     public function getSections() {
  26.         return $this->getMany('Section', 'article_has_section', 'section');
  27.     }
  28.  
  29.     /** @return \YetORM\EntityCollection */
  30.     public function getTags() {
  31.         return $this->getMany('Tag', 'article_has_tag', 'tag');
  32.     }
  33.  
  34.     /** @return \UserModule\User */
  35.     public function getAuthor() {
  36.         return new \UserModule\User($this->row->user);
  37.     }
  38.  
  39.     /**
  40.      * @param  \UserModule\User
  41.      * @return \ArticleModule\Article
  42.      */
  43.     function setAuthor(\UserModule\User $user) {
  44.         $this->row->user_id = $user->id;
  45.         return $this;
  46.     }
  47.  
  48.     /** @return array */
  49.     function toArray() {
  50.         $return = parent::toArray();
  51.         $author = $this->getAuthor();
  52.         $return['author'] = $author->name . ' ' . $author->surname;
  53.  
  54.         $return['tags'] = array();
  55.         foreach ($this->getTags() as $tag) {
  56.             $return['tags'][] = $tag->getName();
  57.         }
  58.  
  59.         $return['sections'] = array();
  60.         foreach ($this->getSections() as $section) {
  61.             $return['sections'][] = $section->getName();
  62.         }
  63.  
  64.         return $return;
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement