mirror of
https://github.com/friendica/friendica
synced 2025-04-29 11:44:24 +02:00
Channels can now be created by users
This commit is contained in:
parent
9ed97caf7b
commit
d68572ea44
14 changed files with 306 additions and 35 deletions
100
src/Content/Conversation/Repository/Channel.php
Normal file
100
src/Content/Conversation/Repository/Channel.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?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;
|
||||
use Friendica\Content\Conversation\Entity\Timeline as EntityTimeline;
|
||||
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
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $uid
|
||||
* @return EntityTimeline
|
||||
* @throws \Friendica\Network\HTTPException\NotFoundException
|
||||
*/
|
||||
public function selectById(int $id, int $uid): EntityTimeline
|
||||
{
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all user channels
|
||||
*
|
||||
* @param integer $uid
|
||||
* @return BaseCollection
|
||||
*/
|
||||
public function selectByUid(int $uid): BaseCollection
|
||||
{
|
||||
return $this->_select(['uid' => $uid]);
|
||||
}
|
||||
|
||||
public function save(EntityTimeline $Channel): EntityTimeline
|
||||
{
|
||||
$fields = [
|
||||
'label' => $Channel->label,
|
||||
'description' => $Channel->description,
|
||||
'access-key' => $Channel->accessKey,
|
||||
'uid' => $Channel->uid,
|
||||
'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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue