| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace internship\bo;
- use n2n\reflection\ObjectAdapter;
- use n2n\persistence\orm\attribute\ManyToMany;
- use n2n\persistence\orm\attribute\ManyToOne;
- class Article extends ObjectAdapter implements \JsonSerializable {
- public int $id;
- public string $categoryName;
- public string $text;
- public string $title;
- #[ManyToMany(Category::class, 'articles')]
- public \ArrayObject $categories;
- /* #[ManyToOne(Comment::class, 'articles')] */
- // public \ArrayObject $comments;
- function basicJsonSerialize() {
- return [
- 'id' => $this->id,
- 'title' => $this->title,
- 'text' => $this->text
- ];
- }
- function jsonSerialize(): mixed {
- $basicJson = $this->basicJsonSerialize();
- $basicJson['categoryName'] = $this->categoryName;
- $basicJson['categories'] = $this->categories;
- return $basicJson;
- }
- }
|