code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for groups a user is in
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class Group extends Entity
{
    // {{{ Autocode

    private int $id;
    private int $gsactor_id;
    private ?string $nickname;
    private ?string $fullname;
    private ?string $homepage;
    private ?string $description;
    private ?bool $is_local;
    private ?string $location;
    private ?string $original_logo;
    private ?string $homepage_logo;
    private ?string $stream_logo;
    private ?string $mini_logo;
    private ?string $uri;
    private ?string $mainpage;
    private ?int $join_policy;
    private ?int $force_scope;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setId(int $id): self
    {
        $this->id = $id;
        return $this;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function setGsactorId(int $gsactor_id): self
    {
        $this->gsactor_id = $gsactor_id;
        return $this;
    }

    public function getGsactorId(): int
    {
        return $this->gsactor_id;
    }

    public function setNickname(?string $nickname): self
    {
        $this->nickname = $nickname;
        return $this;
    }

    public function getNickname(): ?string
    {
        return $this->nickname;
    }

    public function setFullname(?string $fullname): self
    {
        $this->fullname = $fullname;
        return $this;
    }

    public function getFullname(): ?string
    {
        return $this->fullname;
    }

    public function setHomepage(?string $homepage): self
    {
        $this->homepage = $homepage;
        return $this;
    }

    public function getHomepage(): ?string
    {
        return $this->homepage;
    }

    public function setDescription(?string $description): self
    {
        $this->description = $description;
        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setIsLocal(?bool $is_local): self
    {
        $this->is_local = $is_local;
        return $this;
    }

    public function getIsLocal(): ?bool
    {
        return $this->is_local;
    }

    public function setLocation(?string $location): self
    {
        $this->location = $location;
        return $this;
    }

    public function getLocation(): ?string
    {
        return $this->location;
    }

    public function setOriginalLogo(?string $original_logo): self
    {
        $this->original_logo = $original_logo;
        return $this;
    }

    public function getOriginalLogo(): ?string
    {
        return $this->original_logo;
    }

    public function setHomepageLogo(?string $homepage_logo): self
    {
        $this->homepage_logo = $homepage_logo;
        return $this;
    }

    public function getHomepageLogo(): ?string
    {
        return $this->homepage_logo;
    }

    public function setStreamLogo(?string $stream_logo): self
    {
        $this->stream_logo = $stream_logo;
        return $this;
    }

    public function getStreamLogo(): ?string
    {
        return $this->stream_logo;
    }

    public function setMiniLogo(?string $mini_logo): self
    {
        $this->mini_logo = $mini_logo;
        return $this;
    }

    public function getMiniLogo(): ?string
    {
        return $this->mini_logo;
    }

    public function setUri(?string $uri): self
    {
        $this->uri = $uri;
        return $this;
    }

    public function getUri(): ?string
    {
        return $this->uri;
    }

    public function setMainpage(?string $mainpage): self
    {
        $this->mainpage = $mainpage;
        return $this;
    }

    public function getMainpage(): ?string
    {
        return $this->mainpage;
    }

    public function setJoinPolicy(?int $join_policy): self
    {
        $this->join_policy = $join_policy;
        return $this;
    }

    public function getJoinPolicy(): ?int
    {
        return $this->join_policy;
    }

    public function setForceScope(?int $force_scope): self
    {
        $this->force_scope = $force_scope;
        return $this;
    }

    public function getForceScope(): ?int
    {
        return $this->force_scope;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'group',
            'fields' => [
                'id'            => ['type' => 'serial',   'not null' => true],
                'gsactor_id'    => ['type' => 'int',      'not null' => true, 'description' => 'foreign key to gsactor table'],
                'nickname'      => ['type' => 'varchar',  'length' => 64, 'description' => 'nickname for addressing'],
                'fullname'      => ['type' => 'varchar',  'length' => 191, 'description' => 'display name'],
                'homepage'      => ['type' => 'varchar',  'length' => 191, 'description' => 'URL, cached so we dont regenerate'],
                'description'   => ['type' => 'text',     'description' => 'group description'],
                'is_local'      => ['type' => 'bool',     'description' => 'whether this group was created in this instance'],
                'location'      => ['type' => 'varchar',  'length' => 191, 'description' => 'related physical location, if any'],
                'original_logo' => ['type' => 'varchar',  'length' => 191, 'description' => 'original size logo'],
                'homepage_logo' => ['type' => 'varchar',  'length' => 191, 'description' => 'homepage (gsactor) size logo'],
                'stream_logo'   => ['type' => 'varchar',  'length' => 191, 'description' => 'stream-sized logo'],
                'mini_logo'     => ['type' => 'varchar',  'length' => 191, 'description' => 'mini logo'],
                'uri'           => ['type' => 'varchar',  'length' => 191, 'description' => 'universal identifier'],
                'mainpage'      => ['type' => 'varchar',  'length' => 191, 'description' => 'page for group info to link to'],
                'join_policy'   => ['type' => 'int', 'size' => 'tiny', 'description' => '0=open; 1=requires admin approval'],
                'force_scope'   => ['type' => 'int', 'size' => 'tiny', 'description' => '0=never,1=sometimes,-1=always'],
                'created'       => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'      => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key' => ['id'],
            'unique keys' => [
                'user_group_uri_key'  => ['uri'],
                'user_gsactor_id_key' => ['gsactor_id'],
            ],
            'foreign keys' => [
                'user_group_id_fkey' => ['gsactor', ['gsactor_id' => 'id']],
            ],
            'indexes' => [
                'user_group_nickname_idx'   => ['nickname'],
                'user_group_gsactor_id_idx' => ['gsactor_id'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Group Alias
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class GroupAlias extends Entity
{
    // {{{ Autocode

    private string $alias;
    private int $group_id;
    private DateTimeInterface $modified;

    public function setAlias(string $alias): self
    {
        $this->alias = $alias;
        return $this;
    }

    public function getAlias(): string
    {
        return $this->alias;
    }

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'group_alias',
            'fields' => [
                'alias'    => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'additional nickname for the group'],
                'group_id' => ['type' => 'int', 'not null' => true, 'description' => 'group id which this is an alias of'],
                'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['alias'],
            'foreign keys' => [
                'group_alias_group_id_fkey' => ['group', ['group_id' => 'id']],
            ],
            'indexes' => [
                'group_alias_group_id_idx' => ['group_id'],
            ],
        ];
    }
}

repo_name: ksuudilla/gnu

license: mit


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Group Block
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class GroupBlock extends Entity
{
    // {{{ Autocode

    private int $group_id;
    private int $blocked_gsactor;
    private int $blocker_user;
    private DateTimeInterface $modified;

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setBlockedGsactor(int $blocked_gsactor): self
    {
        $this->blocked_gsactor = $blocked_gsactor;
        return $this;
    }

    public function getBlockedGsactor(): int
    {
        return $this->blocked_gsactor;
    }

    public function setBlockerUser(int $blocker_user): self
    {
        $this->blocker_user = $blocker_user;
        return $this;
    }

    public function getBlockerUser(): int
    {
        return $this->blocker_user;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'group_block',
            'fields' => [
                'group_id'        => ['type' => 'int', 'not null' => true, 'description' => 'group gsactor is blocked from'],
                'blocked_gsactor' => ['type' => 'int', 'not null' => true, 'description' => 'gsactor that is blocked'],
                'blocker_user'    => ['type' => 'int', 'not null' => true, 'description' => 'user making the block'],
                'modified'        => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['group_id', 'blocked_gsactor'],
            'foreign keys' => [
                'group_block_group_id_fkey' => ['group', ['group_id' => 'id']],
                'group_block_blocked_fkey'  => ['gsactor', ['blocked_gsactor' => 'id']],
                'group_block_blocker_fkey'  => ['user', ['blocker_user' => 'id']],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Group's inbox
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class GroupInbox extends Entity
{
    // {{{ Autocode

    private int $group_id;
    private int $activity_id;
    private DateTimeInterface $created;

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setActivityId(int $activity_id): self
    {
        $this->activity_id = $activity_id;
        return $this;
    }

    public function getActivityId(): int
    {
        return $this->activity_id;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'        => 'group_inbox',
            'description' => 'Many-many table listing activities posted to a given group, or which groups a given activity was posted to',
            'fields'      => [
                'group_id'    => ['type' => 'int', 'not null' => true, 'description' => 'group receiving the message'],
                'activity_id' => ['type' => 'int', 'not null' => true, 'description' => 'activity received'],
                'created'     => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
            ],
            'primary key'  => ['group_id', 'activity_id'],
            'foreign keys' => [
                'group_inbox_group_id_fkey'    => ['group', ['group_id' => 'id']],
                'group_inbox_activity_id_fkey' => ['activity', ['activity_id' => 'id']],
            ],
            'indexes' => [
                'group_inbox_activity_id_idx'                  => ['activity_id'],
                'group_inbox_group_id_created_activity_id_idx' => ['group_id', 'created', 'activity_id'],
                'group_inbox_created_idx'                      => ['created'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Queue on joining a group
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class GroupJoinQueue extends Entity
{
    // {{{ Autocode

    private int $gsactor_id;
    private int $group_id;
    private DateTimeInterface $created;

    public function setGsactorId(int $gsactor_id): self
    {
        $this->gsactor_id = $gsactor_id;
        return $this;
    }

    public function getGsactorId(): int
    {
        return $this->gsactor_id;
    }

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'        => 'group_join_queue',
            'description' => 'Holder for group join requests awaiting moderation.',
            'fields'      => [
                'gsactor_id' => ['type' => 'int', 'not null' => true, 'description' => 'remote or local gsactor making the request'],
                'group_id'   => ['type' => 'int', 'not null' => true, 'description' => 'remote or local group to join, if any'],
                'created'    => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
            ],
            'primary key' => ['gsactor_id', 'group_id'],
            'indexes'     => [
                'group_join_queue_gsactor_id_created_idx' => ['gsactor_id', 'created'],
                'group_join_queue_group_id_created_idx'   => ['group_id', 'created'],
            ],
            'foreign keys' => [
                'group_join_queue_gsactor_id_fkey' => ['gsactor', ['gsactor_id' => 'id']],
                'group_join_queue_group_id_fkey'   => ['group', ['group_id' => 'id']],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for a Group Member
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class GroupMember extends Entity
{
    // {{{ Autocode

    private int $group_id;
    private int $gsactor_id;
    private ?bool $is_admin;
    private ?string $uri;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setGsactorId(int $gsactor_id): self
    {
        $this->gsactor_id = $gsactor_id;
        return $this;
    }

    public function getGsactorId(): int
    {
        return $this->gsactor_id;
    }

    public function setIsAdmin(?bool $is_admin): self
    {
        $this->is_admin = $is_admin;
        return $this;
    }

    public function getIsAdmin(): ?bool
    {
        return $this->is_admin;
    }

    public function setUri(?string $uri): self
    {
        $this->uri = $uri;
        return $this;
    }

    public function getUri(): ?string
    {
        return $this->uri;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'group_member',
            'fields' => [
                'group_id'   => ['type' => 'int', 'not null' => true,  'description' => 'foreign key to group table'],
                'gsactor_id' => ['type' => 'int', 'not null' => true,  'description' => 'foreign key to gsactor table'],
                'is_admin'   => ['type' => 'bool', 'default' => false, 'description' => 'is this user an admin?'],
                'uri'        => ['type' => 'varchar', 'length' => 191, 'description' => 'universal identifier'],
                'created'    => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'   => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key' => ['group_id', 'gsactor_id'],
            'unique keys' => [
                'group_member_uri_key' => ['uri'],
            ],
            'foreign keys' => [
                'group_member_group_id_fkey'   => ['group', ['group_id' => 'id']],
                'group_member_gsactor_id_fkey' => ['gsactor', ['gsactor_id' => 'id']],
            ],
            'indexes' => [
                'group_member_gsactor_id_idx'         => ['gsactor_id'],
                'group_member_created_idx'            => ['created'],
                'group_member_gsactor_id_created_idx' => ['gsactor_id', 'created'],
                'group_member_group_id_created_idx'   => ['group_id', 'created'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for user invitations
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class Invitation extends Entity
{
    // {{{ Autocode

    private string $code;
    private int $user_id;
    private string $address;
    private string $address_type;
    private ?int $registered_user_id;
    private DateTimeInterface $created;

    public function setCode(string $code): self
    {
        $this->code = $code;
        return $this;
    }

    public function getCode(): string
    {
        return $this->code;
    }

    public function setUserId(int $user_id): self
    {
        $this->user_id = $user_id;
        return $this;
    }

    public function getUserId(): int
    {
        return $this->user_id;
    }

    public function setAddress(string $address): self
    {
        $this->address = $address;
        return $this;
    }

    public function getAddress(): string
    {
        return $this->address;
    }

    public function setAddressType(string $address_type): self
    {
        $this->address_type = $address_type;
        return $this;
    }

    public function getAddressType(): string
    {
        return $this->address_type;
    }

    public function setRegisteredUserId(?int $registered_user_id): self
    {
        $this->registered_user_id = $registered_user_id;
        return $this;
    }

    public function getRegisteredUserId(): ?int
    {
        return $this->registered_user_id;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'invitation',
            'fields' => [
                'code'               => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'random code for an invitation'],
                'user_id'            => ['type' => 'int', 'not null' => true, 'description' => 'who sent the invitation'],
                'address'            => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'invitation sent to'],
                'address_type'       => ['type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'],
                'registered_user_id' => ['type' => 'int', 'not null' => false, 'description' => 'if the invitation is converted, who the new user is'],
                'created'            => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
            ],
            'primary key'  => ['code'],
            'foreign keys' => [
                'invitation_user_id_fkey'            => ['user', ['user_id' => 'id']],
                'invitation_registered_user_id_fkey' => ['user', ['registered_user_id' => 'id']],
            ],
            'indexes' => [
                'invitation_address_idx'            => ['address', 'address_type'],
                'invitation_user_id_idx'            => ['user_id'],
                'invitation_registered_user_id_idx' => ['registered_user_id'],
            ],
        ];
    }
}


code:
<?php

// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/soci
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as publ
// 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 Li
// along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for local groups
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class LocalGroup extends Entity
{
    // {{{ Autocode

    private int $group_id;
    private ?string $nickname;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setNickname(?string $nickname): self
    {
        $this->nickname = $nickname;
        return $this;
    }

    public function getNickname(): ?string
    {
        return $this->nickname;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'        => 'local_group',
            'description' => 'Record for a user group on the local site, with some additional info not in user_group',
            'fields'      => [
                'group_id' => ['type' => 'int', 'not null' => true, 'description' => 'group represented'],
                'nickname' => ['type' => 'varchar', 'length' => 64, 'description' => 'group represented'],
                'created'  => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['group_id'],
            'foreign keys' => [
                'local_group_group_id_fkey' => ['user_group', ['group_id' => 'id']],
            ],
            'unique keys' => [
                'local_group_nickname_key' => ['nickname'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.

// }}}

namespace App\Entity;

use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\UserRoles;
use App\Util\Common;
use DateTimeInterface;
use Exception;
use libphonenumber\PhoneNumber;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Entity for users
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class LocalUser extends Entity implements UserInterface
{
    // {{{ Autocode

    private int $id;
    private string $nickname;
    private ?string $password;
    private ?string $outgoing_email;
    private ?string $incoming_email;
    private ?bool $is_email_verified;
    private ?string $language;
    private ?string $timezone;
    private ?PhoneNumber $phone_number;
    private ?int $sms_carrier;
    private ?string $sms_email;
    private ?string $uri;
    private ?bool $auto_follow_back;
    private ?int $follow_policy;
    private ?bool $is_stream_private;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setId(int $id): self
    {
        $this->id = $id;
        return $this;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function setNickname(string $nickname): self
    {
        $this->nickname = $nickname;
        return $this;
    }

    public function getNickname(): string
    {
        return $this->nickname;
    }

    public function setPassword(?string $password): self
    {
        $this->password = $password;
        return $this;
    }

    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function setOutgoingEmail(?string $outgoing_email): self
    {
        $this->outgoing_email = $outgoing_email;
        return $this;
    }

    public function getOutgoingEmail(): ?string
    {
        return $this->outgoing_email;
    }

    public function setIncomingEmail(?string $incoming_email): self
    {
        $this->incoming_email = $incoming_email;
        return $this;
    }

    public function getIncomingEmail(): ?string
    {
        return $this->incoming_email;
    }

    public function setIsEmailVerified(?bool $is_email_verified): self
    {
        $this->is_email_verified = $is_email_verified;
        return $this;
    }

    public function getIsEmailVerified(): ?bool
    {
        return $this->is_email_verified;
    }

    public function setLanguage(?string $language): self
    {
        $this->language = $language;
        return $this;
    }

    public function getLanguage(): ?string
    {
        return $this->language;
    }

    public function setTimezone(?string $timezone): self
    {
        $this->timezone = $timezone;
        return $this;
    }

    public function getTimezone(): ?string
    {
        return $this->timezone;
    }

    public function setPhoneNumber(?PhoneNumber $phone_number): self
    {
        $this->phone_number = $phone_number;
        return $this;
    }

    public function getPhoneNumber(): ?PhoneNumber
    {
        return $this->phone_number;
    }

    public function setSmsCarrier(?int $sms_carrier): self
    {
        $this->sms_carrier = $sms_carrier;
        return $this;
    }

    public function getSmsCarrier(): ?int
    {
        return $this->sms_carrier;
    }

    public function setSmsEmail(?string $sms_email): self
    {
        $this->sms_email = $sms_email;
        return $this;
    }

    public function getSmsEmail(): ?string
    {
        return $this->sms_email;
    }

    public function setUri(?string $uri): self
    {
        $this->uri = $uri;
        return $this;
    }

    public function getUri(): ?string
    {
        return $this->uri;
    }

    public function setAutoFollowBack(?bool $auto_follow_back): self
    {
        $this->auto_follow_back = $auto_follow_back;
        return $this;
    }

    public function getAutoFollowBack(): ?bool
    {
        return $this->auto_follow_back;
    }

    public function setFollowPolicy(?int $follow_policy): self
    {
        $this->follow_policy = $follow_policy;
        return $this;
    }

    public function getFollowPolicy(): ?int
    {
        return $this->follow_policy;
    }

    public function setIsStreamPrivate(?bool $is_stream_private): self
    {
        $this->is_stream_private = $is_stream_private;
        return $this;
    }

    public function getIsStreamPrivate(): ?bool
    {
        return $this->is_stream_private;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public function getActor()
    {
        return DB::find('gsactor', ['id' => $this->id]);
    }

    /**
     * Returns the roles granted to the user
     */
    public function getRoles()
    {
        return UserRoles::toArray($this->getActor()->getRoles());
    }

    /**
     * Returns the password used to authenticate the user.
     *
     * Implemented in the auto code
     */

    /**
     * Returns the salt that was originally used to encode the password.
     * BCrypt and Argon2 generate their own salts
     */
    public function getSalt()
    {
        return null;
    }

    /**
     * Returns the username used to authenticate the user.
     */
    public function getUsername()
    {
        return $this->nickname;
    }

    /**
     * Removes sensitive data from the user.
     *
     * This is important if, at any given point, sensitive information like
     * the plain-text password is stored on this object.
     */
    public function eraseCredentials()
    {
    }

    public function checkPassword(string $new_password): bool
    {
        // Timing safe password verification
        if (password_verify($new_password, $this->password)) {
            // Update old formats
            if (password_needs_rehash($this->password,
                                      self::algoNameToConstant(Common::config('security', 'algorithm')),
                                      Common::config('security', 'options'))
            ) {
                $this->changePassword($new_password, true);
            }
            return true;
        }
        return false;
    }

    public function changePassword(string $new_password, bool $override = false): void
    {
        if ($override || $this->checkPassword($new_password)) {
            $this->setPassword(self::hashPassword($new_password));
            DB::flush();
        }
    }

    public static function hashPassword(string $password)
    {
        $algorithm = self::algoNameToConstant(Common::config('security', 'algorithm'));
        $options   = Common::config('security', 'options');

        return password_hash($password, $algorithm, $options);
    }

    private static function algoNameToConstant(string $algo)
    {
        switch ($algo) {
        case 'bcrypt':
            return PASSWORD_BCRYPT;
        case 'argon2i':
        case 'argon2d':
        case 'argon2id':
            $c = 'PASSWORD_' . strtoupper($algo);
            if (defined($c)) {
                return constant($c);
            }
            // fallthrough
            // no break
        default:
            throw new Exception('Unsupported or unsafe hashing algorithm requested');
        }
    }

    public static function schemaDef(): array
    {
        return [
            'name'        => 'local_user',
            'description' => 'local users, bots, etc',
            'fields'      => [
                'id'                => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to gsactor table'],
                'nickname'          => ['type' => 'varchar', 'not null' => true, 'length' => 64,  'description' => 'nickname or username, foreign key to gsactor'],
                'password'          => ['type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for users with federated authentication'],
                'outgoing_email'    => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery, notifications, etc.'],
                'incoming_email'    => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'],
                'is_email_verified' => ['type' => 'bool', 'default' => false, 'description' => 'Whether the user opened the comfirmation email'],
                'language'          => ['type' => 'varchar', 'length' => 50,  'description' => 'preferred language'],
                'timezone'          => ['type' => 'varchar', 'length' => 50,  'description' => 'timezone'],
                'phone_number'      => ['type' => 'phone_number', 'description' => 'phone number'],
                'sms_carrier'       => ['type' => 'int', 'description' => 'foreign key to sms_carrier'],
                'sms_email'         => ['type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier (see sms_carrier)'],
                'uri'               => ['type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'],
                'auto_follow_back'  => ['type' => 'bool', 'default' => false, 'description' => 'automatically follow users who follow us'],
                'follow_policy'     => ['type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can follow; 1 = require approval'],
                'is_stream_private' => ['type' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'],
                'created'           => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'          => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key' => ['id'],
            'unique keys' => [
                'user_nickname_key'       => ['nickname'],
                'user_outgoing_email_key' => ['outgoing_email'],
                'user_incoming_email_key' => ['incoming_email'],
                'user_phone_number_key'   => ['phone_number'],
                'user_uri_key'            => ['uri'],
            ],
            'foreign keys' => [
                'user_id_fkey'      => ['gsactor', ['id' => 'id']],
                'user_carrier_fkey' => ['sms_carrier', ['sms_carrier' => 'id']],
            ],
            'indexes' => [
                'user_nickname_idx'  => ['nickname'],
                'user_created_idx'   => ['created'],
                'user_sms_email_idx' => ['sms_email'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for location namespace
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class LocationService extends Entity
{
    // {{{ Autocode

    private int $id;
    private ?string $description;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setId(int $id): self
    {
        $this->id = $id;
        return $this;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function setDescription(?string $description): self
    {
        $this->description = $description;
        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'location_service',
            'fields' => [
                'id'          => ['type' => 'int', 'size' => 'tiny', 'not null' => true, 'description' => 'identifier for the location service'],
                'description' => ['type' => 'varchar', 'length' => 191, 'description' => 'description of the service'],
                'created'     => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'    => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key' => ['id'],
        ];
    }
}


code:
<?php

// {{{ 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/>.

// }}}

namespace App\Entity;

use App\Core\Cache;
use App\Core\DB\DB;
use App\Core\Entity;
use App\Core\Event;
use App\Core\NoteScope;
use DateTimeInterface;

/**
 * Entity for notices
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class Note extends Entity
{
    // {{{ Autocode

    private int $id;
    private int $gsactor_id;
    private ?string $content;
    private ?string $rendered;
    private ?int $reply_to;
    private ?bool $is_local;
    private ?string $source;
    private ?int $conversation;
    private ?int $repeat_of;
    private int $scope = 1;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setId(int $id): self
    {
        $this->id = $id;
        return $this;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function setGsactorId(int $gsactor_id): self
    {
        $this->gsactor_id = $gsactor_id;
        return $this;
    }

    public function getGsactorId(): int
    {
        return $this->gsactor_id;
    }

    public function setContent(?string $content): self
    {
        $this->content = $content;
        return $this;
    }

    public function getContent(): ?string
    {
        return $this->content;
    }

    public function setRendered(?string $rendered): self
    {
        $this->rendered = $rendered;
        return $this;
    }

    public function getRendered(): ?string
    {
        return $this->rendered;
    }

    public function setReplyTo(?int $reply_to): self
    {
        $this->reply_to = $reply_to;
        return $this;
    }

    public function getReplyTo(): ?int
    {
        return $this->reply_to;
    }

    public function setIsLocal(?bool $is_local): self
    {
        $this->is_local = $is_local;
        return $this;
    }

    public function getIsLocal(): ?bool
    {
        return $this->is_local;
    }

    public function setSource(?string $source): self
    {
        $this->source = $source;
        return $this;
    }

    public function getSource(): ?string
    {
        return $this->source;
    }

    public function setConversation(?int $conversation): self
    {
        $this->conversation = $conversation;
        return $this;
    }

    public function getConversation(): ?int
    {
        return $this->conversation;
    }

    public function setRepeatOf(?int $repeat_of): self
    {
        $this->repeat_of = $repeat_of;
        return $this;
    }

    public function getRepeatOf(): ?int
    {
        return $this->repeat_of;
    }

    public function setScope(int $scope): self
    {
        $this->scope = $scope;
        return $this;
    }

    public function getScope(): int
    {
        return $this->scope;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public function getActorNickname()
    {
        return GSActor::getNicknameFromId($this->gsactor_id);
    }

    public function getAvatarUrl()
    {
        $url = null;
        Event::handle('GetAvatarUrl', [$this->getActorNickname(), &$url]);
        return $url;
    }

    public function getAttachments(): array
    {
        return Cache::get('note-attachments-' . $this->id, function () {
            return DB::dql(
                    'select f from App\Entity\File f ' .
                    'join App\Entity\FileToNote ftn with ftn.file_id = f.id ' .
                    'where ftn.note_id = :note_id',
                    ['note_id' => $this->id]
                );
        });
    }

    public function getReplies(): array
    {
        return Cache::getList('note-replies-' . $this->id, function () {
            return DB::dql('select n from App\Entity\Note n where n.reply_to = :id', ['id' => $this->id]);
        });
    }

    public function getReplyToNickname(): ?string
    {
        if (!empty($this->reply_to)) {
            return Cache::get('note-reply-to-' . $this->id, function () {
                return DB::dql('select g from App\Entity\Note n join ' .
                                   'App\Entity\GSActor g with n.gsactor_id = g.id where n.reply_to = :reply',
                                   ['reply' => $this->reply_to])[0]->getNickname();
            });
        }
        return null;
    }

    /**
     * Whether this note is visible to the given actor
     *
     * @param mixed $a
     */
    public function isVisibleTo(/* GSActor|LocalUser */ $a): bool
    {
        $scope = NoteScope::create($this->scope);
        return $scope->public
            || ($scope->follower
                && null != DB::find('follow', ['follower' => $a->getId(), 'followed' => $this->gsactor_id]))
            || ($scope->addressee
                && null != DB::find('notification', ['activity_id' => $this->id, 'gsactor_id' => $a->getId()]))
            || ($scope->group
                && [] != DB::sql('select m.gsactor_id from group_member m ' .
                                   'inner join group_inbox i on m.group_id = i.group_id ' .
                                   'inner join note n on i.activity_id = n.id where n.id = :id',
                                   [], ['id' => $this->id]));
    }

    public static function schemaDef(): array
    {
        return [
            'name'   => 'note',
            'fields' => [
                'id'           => ['type' => 'serial', 'not null' => true],
                'gsactor_id'   => ['type' => 'int', 'not null' => true, 'description' => 'who made the note'],
                'content'      => ['type' => 'text', 'description' => 'note content'],
                'rendered'     => ['type' => 'text', 'description' => 'rendered note content if not local, so we can keep the microtags'],
                'reply_to'     => ['type' => 'int', 'description' => 'note replied to, null if root of a conversation'],
                'is_local'     => ['type' => 'bool', 'description' => 'was this note generated by a local actor'],
                'source'       => ['type' => 'varchar', 'length' => 32, 'description' => 'source of note, like "web", "im", or "clientname"'],
                'conversation' => ['type' => 'int', 'description' => 'the local conversation id'],
                'repeat_of'    => ['type' => 'int', 'description' => 'note this is a repeat of'],
                'scope'        => ['type' => 'int', 'not null' => true, 'default' => NoteScope::PUBLIC, 'description' => 'bit map for distribution scope; 0 = everywhere; 1 = this server only; 2 = addressees; 4 = groups; 8 = followers; 16 = messages; null = default'],
                'created'      => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'     => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['id'],
            'foreign keys' => [
                'note_gsactor_id_fkey'   => ['gsactor',      ['gsactor_id' => 'id']],
                'note_reply_to_fkey'     => ['note',         ['reply_to' => 'id']],
                'note_note_source_fkey'  => ['note_source',  ['source' => 'code']],
                'note_conversation_fkey' => ['conversation', ['conversation' => 'id']],
                'note_repeat_of_fkey'    => ['note',         ['repeat_of' => 'id']],
            ],
            'indexes' => [
                'note_created_id_is_local_idx'      => ['created', 'is_local'],
                'note_gsactor_created_idx'          => ['gsactor_id', 'created'],
                'note_is_local_created_gsactor_idx' => ['is_local', 'created', 'gsactor_id'],
                'note_repeat_of_created_idx'        => ['repeat_of', 'created'],
                'note_conversation_created_idx'     => ['conversation', 'created'],
                'note_reply_to_idx'                 => ['reply_to'],
            ],
            'fulltext indexes' => ['notice_fulltext_idx' => ['content']],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Notice Tag
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class NoteHashtag extends Entity
{
    // {{{ Autocode

    private string $tag;
    private int $note_id;
    private DateTimeInterface $created;

    public function setTag(string $tag): self
    {
        $this->tag = $tag;
        return $this;
    }

    public function getTag(): string
    {
        return $this->tag;
    }

    public function setNoteId(int $note_id): self
    {
        $this->note_id = $note_id;
        return $this;
    }

    public function getNoteId(): int
    {
        return $this->note_id;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'        => 'note_hashtag',
            'description' => 'Hash tags on notes',
            'fields'      => [
                'tag'     => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this note'],
                'note_id' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to tagged note'],
                'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['tag', 'note_id'],
            'foreign keys' => [
                'note_hashtag_note_id_fkey' => ['note', ['note_id' => 'id']],
            ],
            'indexes' => [
                'note_tag_created_idx'             => ['created'],
                'note_tag_note_id_idx'             => ['note_id'],
                'note_tag_tag_created_note_id_idx' => ['tag', 'created', 'note_id'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Note's location
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class NoteLocation extends Entity
{
    // {{{ Autocode

    private int $note_id;
    private ?float $lat;
    private ?float $lon;
    private ?int $location_id;
    private ?int $location_service;
    private DateTimeInterface $modified;

    public function setNoteId(int $note_id): self
    {
        $this->note_id = $note_id;
        return $this;
    }

    public function getNoteId(): int
    {
        return $this->note_id;
    }

    public function setLat(?float $lat): self
    {
        $this->lat = $lat;
        return $this;
    }

    public function getLat(): ?float
    {
        return $this->lat;
    }

    public function setLon(?float $lon): self
    {
        $this->lon = $lon;
        return $this;
    }

    public function getLon(): ?float
    {
        return $this->lon;
    }

    public function setLocationId(?int $location_id): self
    {
        $this->location_id = $location_id;
        return $this;
    }

    public function getLocationId(): ?int
    {
        return $this->location_id;
    }

    public function setLocationService(?int $location_service): self
    {
        $this->location_service = $location_service;
        return $this;
    }

    public function getLocationService(): ?int
    {
        return $this->location_service;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'activity_location',
            'fields' => [
                'note_id'          => ['type' => 'int', 'not null' => true, 'description' => 'activity this refers to'],
                'lat'              => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'],
                'lon'              => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'],
                'location_id'      => ['type' => 'int', 'description' => 'location id if possible'],
                'location_service' => ['type' => 'int', 'size' => 'tiny', 'description' => 'service used to retrieve location information'],
                'modified'         => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['note_id'],
            'foreign keys' => [
                'note_location_note_id_fkey' => ['note', ['note_id' => 'id']],
            ],
            'indexes' => [
                'note_location_location_id_idx' => ['location_id'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for Notices sources
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class NoteSource extends Entity
{
    // {{{ Autocode

    private string $code;
    private string $name;
    private string $url;
    private DateTimeInterface $modified;

    public function setCode(string $code): self
    {
        $this->code = $code;
        return $this;
    }

    public function getCode(): string
    {
        return $this->code;
    }

    public function setName(string $name): self
    {
        $this->name = $name;
        return $this;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function setUrl(string $url): self
    {
        $this->url = $url;
        return $this;
    }

    public function getUrl(): string
    {
        return $this->url;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'note_source',
            'fields' => [
                'code'     => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'code identifier'],
                'name'     => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'name of the source'],
                'url'      => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'url to link to'],
                'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key' => ['code'],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for attentions
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class Notification extends Entity
{
    // {{{ Autocode

    private int $activity_id;
    private int $gsactor_id;
    private ?string $reason;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setActivityId(int $activity_id): self
    {
        $this->activity_id = $activity_id;
        return $this;
    }

    public function getActivityId(): int
    {
        return $this->activity_id;
    }

    public function setGsactorId(int $gsactor_id): self
    {
        $this->gsactor_id = $gsactor_id;
        return $this;
    }

    public function getGsactorId(): int
    {
        return $this->gsactor_id;
    }

    public function setReason(?string $reason): self
    {
        $this->reason = $reason;
        return $this;
    }

    public function getReason(): ?string
    {
        return $this->reason;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'        => 'notification',
            'description' => 'Activity notification for gsactors (that are not a mention and not result of a subscription)',
            'fields'      => [
                'activity_id' => ['type' => 'int', 'not null' => true,  'description' => 'activity_id to give attention'],
                'gsactor_id'  => ['type' => 'int', 'not null' => true,  'description' => 'gsactor_id for feed receiver'],
                'reason'      => ['type' => 'varchar', 'length' => 191, 'description' => 'Optional reason why this was brought to the attention of gsactor_id'],
                'created'     => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'    => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['activity_id', 'gsactor_id'],
            'foreign keys' => [
                'attention_activity_id_fkey' => ['activity', ['activity_id' => 'id']],
                'attention_gsactor_id_fkey'  => ['gsactor', ['gsactor_id' => 'id']],
            ],
            'indexes' => [
                'attention_activity_id_idx' => ['activity_id'],
                'attention_gsactor_id_idx'  => ['gsactor_id'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for related groups
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class RelatedGroup extends Entity
{
    // {{{ Autocode

    private int $group_id;
    private int $related_group_id;
    private DateTimeInterface $created;

    public function setGroupId(int $group_id): self
    {
        $this->group_id = $group_id;
        return $this;
    }

    public function getGroupId(): int
    {
        return $this->group_id;
    }

    public function setRelatedGroupId(int $related_group_id): self
    {
        $this->related_group_id = $related_group_id;
        return $this;
    }

    public function getRelatedGroupId(): int
    {
        return $this->related_group_id;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name' => 'related_group',
            // @fixme description for related_group?
            'fields' => [
                'group_id'         => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'],
                'related_group_id' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'],
                'created'          => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
            ],
            'primary key'  => ['group_id', 'related_group_id'],
            'foreign keys' => [
                'related_group_group_id_fkey'         => ['group', ['group_id' => 'id']],
                'related_group_related_group_id_fkey' => ['group', ['related_group_id' => 'id']],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.

// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for the remember_me token
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class RememberMeToken extends Entity
{
    // {{{ Autocode

    private string $series;
    private string $value;
    private DateTimeInterface $lastUsed;
    private string $class;
    private string $username;

    public function setSeries(string $series): self
    {
        $this->series = $series;
        return $this;
    }

    public function getSeries(): string
    {
        return $this->series;
    }

    public function setValue(string $value): self
    {
        $this->value = $value;
        return $this;
    }

    public function getValue(): string
    {
        return $this->value;
    }

    public function setLastUsed(DateTimeInterface $lastUsed): self
    {
        $this->lastUsed = $lastUsed;
        return $this;
    }

    public function getLastUsed(): DateTimeInterface
    {
        return $this->lastUsed;
    }

    public function setClass(string $class): self
    {
        $this->class = $class;
        return $this;
    }

    public function getClass(): string
    {
        return $this->class;
    }

    public function setUsername(string $username): self
    {
        $this->username = $username;
        return $this;
    }

    public function getUsername(): string
    {
        return $this->username;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        $def = [
            'name'   => 'rememberme_token',
            'fields' => [
                'series'   => ['type' => 'char', 'length' => 88, 'not null' => true],
                'value'    => ['type' => 'char', 'length' => 88, 'not null' => true],
                'lastUsed' => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP'],
                'class'    => ['type' => 'varchar', 'length' => 100, 'not null' => true],
                'username' => ['type' => 'varchar', 'length' => 64, 'not null' => true],
            ],
            'primary key' => ['series'],
        ];

        return $def;
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity that Keeps a list of unavailable status network names
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class ReservedNickname extends Entity
{
    // {{{ Autocode

    private string $nickname;
    private DateTimeInterface $created;

    public function setNickname(string $nickname): self
    {
        $this->nickname = $nickname;
        return $this;
    }

    public function getNickname(): string
    {
        return $this->nickname;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'        => 'reserved_nickname',
            'description' => 'A reserved nickname',
            'fields'      => [
                'nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname not to use'],
                'created'  => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
            ],
            'primary key' => ['nickname'],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for SMS carriers
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Zach Copley <zach@status.net>
 * @copyright 2010 StatusNet Inc.
 * @author    Mikael Nordfeldth <mmn@hethane.se>
 * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class SmsCarrier extends Entity
{
    // {{{ Autocode

    private int $id;
    private ?string $name;
    private string $email_pattern;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setId(int $id): self
    {
        $this->id = $id;
        return $this;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;
        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setEmailPattern(string $email_pattern): self
    {
        $this->email_pattern = $email_pattern;
        return $this;
    }

    public function getEmailPattern(): string
    {
        return $this->email_pattern;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'sms_carrier',
            'fields' => [
                'id'            => ['type' => 'int', 'not null' => true, 'description' => 'primary key for SMS carrier'],
                'name'          => ['type' => 'varchar', 'length' => 64, 'description' => 'name of the carrier'],
                'email_pattern' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'sprintf pattern for making an email address from a phone number'],
                'created'       => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'      => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key' => ['id'],
            'unique keys' => [
                'sms_carrier_name_key' => ['name'],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for user location preferences
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2009 StatusNet Inc.
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class UserLocationPrefs extends Entity
{
    // {{{ Autocode

    private int $user_id;
    private ?bool $share_location;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setUserId(int $user_id): self
    {
        $this->user_id = $user_id;
        return $this;
    }

    public function getUserId(): int
    {
        return $this->user_id;
    }

    public function setShareLocation(?bool $share_location): self
    {
        $this->share_location = $share_location;
        return $this;
    }

    public function getShareLocation(): ?bool
    {
        return $this->share_location;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'user_location_prefs',
            'fields' => [
                'user_id'        => ['type' => 'int', 'not null' => true, 'description' => 'user who has the preference'],
                'share_location' => ['type' => 'bool', 'default' => true, 'description' => 'Whether to share location data'],
                'created'        => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'       => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['user_id'],
            'foreign keys' => [
                'user_location_prefs_user_id_fkey' => ['user', ['user_id' => 'id']],
            ],
        ];
    }
}


code:
<?php

// {{{ 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/>.
// }}}

namespace App\Entity;

use App\Core\Entity;
use DateTimeInterface;

/**
 * Entity for user notification preferences
 *
 * @category  DB
 * @package   GNUsocial
 *
 * @author    Hugo Sales <hugo@fc.up.pt>
 * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
 * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
 */
class UserNotificationPrefs extends Entity
{
    // {{{ Autocode

    private int $user_id;
    private string $transport;
    private ?int $target_gsactor_id;
    private bool $activity_by_followed  = true;
    private bool $mention               = true;
    private bool $reply                 = true;
    private bool $follow                = true;
    private bool $favorite              = true;
    private bool $nudge                 = false;
    private bool $dm                    = true;
    private bool $post_on_status_change = false;
    private ?bool $enable_posting;
    private DateTimeInterface $created;
    private DateTimeInterface $modified;

    public function setUserId(int $user_id): self
    {
        $this->user_id = $user_id;
        return $this;
    }

    public function getUserId(): int
    {
        return $this->user_id;
    }

    public function setTransport(string $transport): self
    {
        $this->transport = $transport;
        return $this;
    }

    public function getTransport(): string
    {
        return $this->transport;
    }

    public function setTargetGsactorId(?int $target_gsactor_id): self
    {
        $this->target_gsactor_id = $target_gsactor_id;
        return $this;
    }

    public function getTargetGsactorId(): ?int
    {
        return $this->target_gsactor_id;
    }

    public function setActivityByFollowed(bool $activity_by_followed): self
    {
        $this->activity_by_followed = $activity_by_followed;
        return $this;
    }

    public function getActivityByFollowed(): bool
    {
        return $this->activity_by_followed;
    }

    public function setMention(bool $mention): self
    {
        $this->mention = $mention;
        return $this;
    }

    public function getMention(): bool
    {
        return $this->mention;
    }

    public function setReply(bool $reply): self
    {
        $this->reply = $reply;
        return $this;
    }

    public function getReply(): bool
    {
        return $this->reply;
    }

    public function setFollow(bool $follow): self
    {
        $this->follow = $follow;
        return $this;
    }

    public function getFollow(): bool
    {
        return $this->follow;
    }

    public function setFavorite(bool $favorite): self
    {
        $this->favorite = $favorite;
        return $this;
    }

    public function getFavorite(): bool
    {
        return $this->favorite;
    }

    public function setNudge(bool $nudge): self
    {
        $this->nudge = $nudge;
        return $this;
    }

    public function getNudge(): bool
    {
        return $this->nudge;
    }

    public function setDm(bool $dm): self
    {
        $this->dm = $dm;
        return $this;
    }

    public function getDm(): bool
    {
        return $this->dm;
    }

    public function setPostOnStatusChange(bool $post_on_status_change): self
    {
        $this->post_on_status_change = $post_on_status_change;
        return $this;
    }

    public function getPostOnStatusChange(): bool
    {
        return $this->post_on_status_change;
    }

    public function setEnablePosting(?bool $enable_posting): self
    {
        $this->enable_posting = $enable_posting;
        return $this;
    }

    public function getEnablePosting(): ?bool
    {
        return $this->enable_posting;
    }

    public function setCreated(DateTimeInterface $created): self
    {
        $this->created = $created;
        return $this;
    }

    public function getCreated(): DateTimeInterface
    {
        return $this->created;
    }

    public function setModified(DateTimeInterface $modified): self
    {
        $this->modified = $modified;
        return $this;
    }

    public function getModified(): DateTimeInterface
    {
        return $this->modified;
    }

    // }}} Autocode

    public static function schemaDef(): array
    {
        return [
            'name'   => 'user_notification_prefs',
            'fields' => [
                'user_id'               => ['type' => 'int', 'not null' => true],
                'transport'             => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex email. xmpp, aim)'],
                'target_gsactor_id'     => ['type' => 'int',  'default' => null,  'description' => 'If not null, settings are specific only to a given gsactors'],
                'activity_by_followed'  => ['type' => 'bool', 'not null' => true, 'default' => true,  'description' => 'Notify when a new activity by someone we follow is made'],
                'mention'               => ['type' => 'bool', 'not null' => true, 'default' => true,  'description' => 'Notify when mentioned by someone we do not follow'],
                'reply'                 => ['type' => 'bool', 'not null' => true, 'default' => true,  'description' => 'Notify when someone replies to a notice made by us'],
                'follow'                => ['type' => 'bool', 'not null' => true, 'default' => true,  'description' => 'Notify someone follows us'],
                'favorite'              => ['type' => 'bool', 'not null' => true, 'default' => true,  'description' => 'Notify someone favorites a notice by us'],
                'nudge'                 => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify someone nudges us'],
                'dm'                    => ['type' => 'bool', 'not null' => true, 'default' => true,  'description' => 'Notify someone sends us a direct message'],
                'post_on_status_change' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Post a notice when our status in service changes'],
                'enable_posting'        => ['type' => 'bool', 'default' => true,  'description' => 'Enable posting from this service'],
                'created'               => ['type' => 'datetime',  'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
                'modified'              => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
            ],
            'primary key'  => ['user_id', 'transport'],
            'foreign keys' => [
                'user_notification_prefs_user_id_fkey'   => ['user', ['user_id' => 'id']],
                'user_notification_prefs_target_gsactor' => ['gsactor', ['target_gsactor_id' => 'id']],
            ],
            'indexes' => [
                'user_notification_prefs_user_target_gsactor_idx' => ['user_id', 'target_gsactor_id'],
            ],
        ];
    }
}