3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Content\Conversation\Repository;
24 use Friendica\BaseCollection;
25 use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
26 use Friendica\Content\Conversation\Factory\Timeline;
27 use Friendica\Database\Database;
28 use Psr\Log\LoggerInterface;
30 class Channel extends \Friendica\BaseRepository
32 protected static $table_name = 'channel';
34 public function __construct(Database $database, LoggerInterface $logger, Timeline $factory)
36 parent::__construct($database, $logger, $factory);
40 * Fetch a single user channel
44 * @return TimelineEntity
45 * @throws \Friendica\Network\HTTPException\NotFoundException
47 public function selectById(int $id, int $uid): TimelineEntity
49 return $this->_selectOne(['id' => $id, 'uid' => $uid]);
53 * Checks if the provided channel id exists for this user
59 public function existsById(int $id, int $uid): bool
61 return $this->exists(['id' => $id, 'uid' => $uid]);
65 * Delete the given channel
71 public function deleteById(int $id, int $uid): bool
73 return $this->db->delete('channel', ['id' => $id, 'uid' => $uid]);
77 * Fetch all user channels
80 * @return BaseCollection
82 public function selectByUid(int $uid): BaseCollection
84 return $this->_select(['uid' => $uid]);
87 public function save(TimelineEntity $Channel): TimelineEntity
90 'label' => $Channel->label,
91 'description' => $Channel->description,
92 'access-key' => $Channel->accessKey,
93 'uid' => $Channel->uid,
94 'include-tags' => $Channel->includeTags,
95 'exclude-tags' => $Channel->excludeTags,
96 'full-text-search' => $Channel->fullTextSearch,
97 'media-type' => $Channel->mediaType,
100 if ($Channel->code) {
101 $this->db->update(self::$table_name, $fields, ['uid' => $Channel->uid, 'id' => $Channel->code]);
103 $this->db->insert(self::$table_name, $fields, Database::INSERT_IGNORE);
105 $newChannelId = $this->db->lastInsertId();
107 $Channel = $this->selectById($newChannelId, $Channel->uid);