2023-09-19 09:05:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Content\Conversation\Repository;
|
|
|
|
|
|
|
|
use Friendica\BaseCollection;
|
2023-10-05 05:36:12 +00:00
|
|
|
use Friendica\Content\Conversation\Entity\UserDefinedChannel;
|
2023-09-19 09:05:28 +00:00
|
|
|
use Friendica\Content\Conversation\Factory\Timeline;
|
|
|
|
use Friendica\Database\Database;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class Channel extends \Friendica\BaseRepository
|
|
|
|
{
|
|
|
|
protected static $table_name = 'channel';
|
|
|
|
|
|
|
|
public function __construct(Database $database, LoggerInterface $logger, Timeline $factory)
|
|
|
|
{
|
|
|
|
parent::__construct($database, $logger, $factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a single user channel
|
2023-09-19 09:09:20 +00:00
|
|
|
*
|
2023-09-26 05:05:51 +00:00
|
|
|
* @param int $id The id of the user defined channel
|
|
|
|
* @param int $uid The user that this channel belongs to. (Not part of the primary key)
|
2023-10-05 05:36:12 +00:00
|
|
|
* @return UserDefinedChannel
|
2023-09-19 09:05:28 +00:00
|
|
|
* @throws \Friendica\Network\HTTPException\NotFoundException
|
|
|
|
*/
|
2023-10-05 05:36:12 +00:00
|
|
|
public function selectById(int $id, int $uid): UserDefinedChannel
|
2023-09-19 09:05:28 +00:00
|
|
|
{
|
|
|
|
return $this->_selectOne(['id' => $id, 'uid' => $uid]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the provided channel id exists for this user
|
|
|
|
*
|
|
|
|
* @param integer $id
|
|
|
|
* @param integer $uid
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function existsById(int $id, int $uid): bool
|
|
|
|
{
|
|
|
|
return $this->exists(['id' => $id, 'uid' => $uid]);
|
2023-09-20 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the given channel
|
|
|
|
*
|
|
|
|
* @param integer $id
|
|
|
|
* @param integer $uid
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function deleteById(int $id, int $uid): bool
|
|
|
|
{
|
|
|
|
return $this->db->delete('channel', ['id' => $id, 'uid' => $uid]);
|
2023-09-19 09:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch all user channels
|
|
|
|
*
|
|
|
|
* @param integer $uid
|
|
|
|
* @return BaseCollection
|
|
|
|
*/
|
|
|
|
public function selectByUid(int $uid): BaseCollection
|
|
|
|
{
|
|
|
|
return $this->_select(['uid' => $uid]);
|
|
|
|
}
|
|
|
|
|
2023-10-05 05:36:12 +00:00
|
|
|
public function save(UserDefinedChannel $Channel): UserDefinedChannel
|
2023-09-19 09:05:28 +00:00
|
|
|
{
|
|
|
|
$fields = [
|
|
|
|
'label' => $Channel->label,
|
|
|
|
'description' => $Channel->description,
|
|
|
|
'access-key' => $Channel->accessKey,
|
|
|
|
'uid' => $Channel->uid,
|
2023-09-24 00:45:07 +00:00
|
|
|
'circle' => $Channel->circle,
|
2023-09-19 09:05:28 +00:00
|
|
|
'include-tags' => $Channel->includeTags,
|
|
|
|
'exclude-tags' => $Channel->excludeTags,
|
|
|
|
'full-text-search' => $Channel->fullTextSearch,
|
|
|
|
'media-type' => $Channel->mediaType,
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($Channel->code) {
|
|
|
|
$this->db->update(self::$table_name, $fields, ['uid' => $Channel->uid, 'id' => $Channel->code]);
|
|
|
|
} else {
|
|
|
|
$this->db->insert(self::$table_name, $fields, Database::INSERT_IGNORE);
|
|
|
|
|
|
|
|
$newChannelId = $this->db->lastInsertId();
|
|
|
|
|
|
|
|
$Channel = $this->selectById($newChannelId, $Channel->uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $Channel;
|
|
|
|
}
|
|
|
|
}
|