2021-11-01 21:19:20 +00:00
< ? php
declare ( strict_types = 1 );
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
2021-12-10 02:45:31 +00:00
namespace Plugin\RepeatNote\Entity ;
2021-11-01 21:19:20 +00:00
2021-11-15 17:11:27 +00:00
use App\Core\DB\DB ;
2021-11-01 21:19:20 +00:00
use App\Core\Entity ;
2021-11-15 17:11:27 +00:00
use App\Entity\Note ;
2021-11-01 21:19:20 +00:00
/**
* Entity for notices
*
* @ category DB
* @ package GNUsocial
*
* @ author Eliseu Amaro < mail @ eliseuama . ro >
* @ copyright 2020 - 2021 Free Software Foundation , Inc http :// www . fsf . org
* @ license https :// www . gnu . org / licenses / agpl . html GNU AGPL v3 or later
*/
class NoteRepeat extends Entity
{
2021-11-15 17:11:27 +00:00
private int $note_id ;
2021-11-01 21:19:20 +00:00
private int $actor_id ;
private int $repeat_of ;
2021-11-15 17:11:27 +00:00
public function setNoteId ( int $note_id ) : self
2021-11-01 21:19:20 +00:00
{
2021-11-15 17:11:27 +00:00
$this -> note_id = $note_id ;
2021-11-01 21:19:20 +00:00
return $this ;
}
2021-11-15 17:11:27 +00:00
public function getNoteId () : int
2021-11-01 21:19:20 +00:00
{
2021-11-15 17:11:27 +00:00
return $this -> note_id ;
2021-11-01 21:19:20 +00:00
}
public function setActorId ( int $actor_id ) : self
{
$this -> actor_id = $actor_id ;
return $this ;
}
public function getActorId () : ? int
{
return $this -> actor_id ;
}
public function setRepeatOf ( int $repeat_of ) : self
{
$this -> repeat_of = $repeat_of ;
return $this ;
}
public function getRepeatOf () : int
{
return $this -> repeat_of ;
}
2021-11-15 17:11:27 +00:00
public static function getNoteRepeats ( Note $note ) : array
{
return DB :: sql (
<<< 'EOF'
select { select } from note n
inner join note_repeat nr
on nr . note_id = n . id
where repeat_of = : note_id
order by n . created DESC
EOF ,
[ 'note_id' => $note -> getId ()]
);
}
2021-11-01 21:19:20 +00:00
public static function schemaDef () : array
{
return [
'name' => 'note_repeat' ,
'fields' => [
2021-11-15 17:11:27 +00:00
'note_id' => [ 'type' => 'int' , 'not null' => true , 'foreign key' => true , 'target' => 'Note.id' , 'multiplicity' => 'one to one' , 'description' => 'The id of the repeat itself' ],
2021-11-01 21:19:20 +00:00
'actor_id' => [ 'type' => 'int' , 'not null' => true , 'foreign key' => true , 'target' => 'Actor.id' , 'multiplicity' => 'one to one' , 'description' => 'Who made this repeat' ],
'repeat_of' => [ 'type' => 'int' , 'not null' => true , 'foreign key' => true , 'target' => 'Note.id' , 'multiplicity' => 'one to one' , 'description' => 'Note this is a repeat of' ],
],
2021-12-10 02:45:31 +00:00
'primary key' => [ 'note_id' ],
2021-11-01 21:19:20 +00:00
'foreign keys' => [
2021-11-15 17:11:27 +00:00
'note_id_to_id_fkey' => [ 'note' , [ 'note_id' => 'id' ]],
2021-11-01 21:19:20 +00:00
'note_repeat_of_id_fkey' => [ 'note' , [ 'repeat_of' => 'id' ]],
2021-11-15 17:11:27 +00:00
'actor_reply_to_id_fkey' => [ 'actor' , [ 'actor_id' => 'id' ]],
],
2021-12-10 02:45:31 +00:00
'indexes' => [
2021-11-15 17:11:27 +00:00
'note_repeat_of_idx' => [ 'repeat_of' ],
2021-11-01 21:19:20 +00:00
],
];
}
}