Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
NoteToLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
8
100.00% covered (success)
100.00%
1 / 1
 setLinkId
n/a
0 / 0
1
n/a
0 / 0
 getLinkId
n/a
0 / 0
1
n/a
0 / 0
 setNoteId
n/a
0 / 0
1
n/a
0 / 0
 getNoteId
n/a
0 / 0
1
n/a
0 / 0
 setModified
n/a
0 / 0
1
n/a
0 / 0
 getModified
n/a
0 / 0
1
n/a
0 / 0
 create
n/a
0 / 0
1
n/a
0 / 0
 schemaDef
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3// {{{ License
4// This file is part of GNU social - https://www.gnu.org/software/social
5//
6// GNU social is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Affero General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// GNU social is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU Affero General Public License for more details.
15//
16// You should have received a copy of the GNU Affero General Public License
17// along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
18// }}}
19
20namespace App\Entity;
21
22use App\Core\DB\DB;
23use App\Core\Entity;
24use App\Core\Event;
25use DateTimeInterface;
26
27/**
28 * Entity for relating a Link to a post
29 *
30 * @category  DB
31 * @package   GNUsocial
32 *
33 * @author    Diogo Peralta Cordeiro <mail@diogo.site>
34 * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
35 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
36 */
37class NoteToLink extends Entity
38{
39    // {{{ Autocode
40    // @codeCoverageIgnoreStart
41    private int $link_id;
42    private int $note_id;
43    private \DateTimeInterface $modified;
44
45    public function setLinkId(int $link_id): self
46    {
47        $this->link_id = $link_id;
48        return $this;
49    }
50
51    public function getLinkId(): int
52    {
53        return $this->link_id;
54    }
55
56    public function setNoteId(int $note_id): self
57    {
58        $this->note_id = $note_id;
59        return $this;
60    }
61
62    public function getNoteId(): int
63    {
64        return $this->note_id;
65    }
66
67    public function setModified(DateTimeInterface $modified): self
68    {
69        $this->modified = $modified;
70        return $this;
71    }
72
73    public function getModified(): DateTimeInterface
74    {
75        return $this->modified;
76    }
77
78    /**
79     * Create an instance of NoteToLink or fill in the
80     * properties of $obj with the associative array $args. Doesn't
81     * persist the result
82     *
83     * @param null|mixed $obj
84     */
85    public static function create(array $args, $obj = null)
86    {
87        $link = DB::find('link', ['id' => $args['link_id']]);
88        $note = DB::find('note', ['id' => $args['note_id']]);
89        Event::handle('NewLinkFromNote', [$link, $note]);
90        $obj = new self();
91        return parent::create($args, $obj);
92    }
93
94    // @codeCoverageIgnoreEnd
95    // }}} Autocode
96
97    public static function schemaDef(): array
98    {
99        return [
100            'name'   => 'note_to_link',
101            'fields' => [
102                'link_id'  => ['type' => 'int', 'foreign key' => true, 'target' => 'link.id', 'multiplicity' => 'one to one', 'name' => 'note_to_link_link_id_fkey', 'not null' => true, 'description' => 'id of link'],
103                'note_id'  => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'name' => 'note_to_link_note_id_fkey', 'not null' => true, 'description' => 'id of the note it belongs to'],
104                'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
105            ],
106            'primary key' => ['link_id', 'note_id'],
107            'indexes'     => [
108                'link_id_idx' => ['link_id'],
109                'note_id_idx' => ['note_id'],
110            ],
111        ];
112    }
113}