mirror of
https://github.com/friendica/friendica
synced 2025-04-30 13:04:26 +02:00
User Repository\UserDefinedChannel->selectByUid instead of Factory\UserDefinedChannel->getForUser
- Rename Repository\Channel to Repository\UserDefinedChannel - Add new Collection\UserDefinedChannels class - Move Factory\Timeline->createFromTableRow to Factory\UserDefinedChannel
This commit is contained in:
parent
8ac6d0ef04
commit
710f9eecb2
12 changed files with 108 additions and 80 deletions
26
src/Content/Conversation/Collection/UserDefinedChannels.php
Normal file
26
src/Content/Conversation/Collection/UserDefinedChannels.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?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\Collection;
|
||||
|
||||
class UserDefinedChannels extends Timelines
|
||||
{
|
||||
}
|
|
@ -23,21 +23,21 @@ namespace Friendica\Content\Conversation\Factory;
|
|||
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
|
||||
use Friendica\Content\Conversation\Repository\Channel;
|
||||
use Friendica\Content\Conversation\Repository\UserDefinedChannel;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Timeline extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
||||
class Timeline extends \Friendica\BaseFactory
|
||||
{
|
||||
/** @var L10n */
|
||||
protected $l10n;
|
||||
/** @var IManageConfigValues The config */
|
||||
protected $config;
|
||||
/** @var Channel */
|
||||
/** @var UserDefinedChannel */
|
||||
protected $channelRepository;
|
||||
|
||||
public function __construct(Channel $channel, L10n $l10n, LoggerInterface $logger, IManageConfigValues $config)
|
||||
public function __construct(UserDefinedChannel $channel, L10n $l10n, LoggerInterface $logger, IManageConfigValues $config)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
|
@ -45,21 +45,4 @@ class Timeline extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
|||
$this->l10n = $l10n;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function createFromTableRow(array $row): TimelineEntity
|
||||
{
|
||||
return new TimelineEntity(
|
||||
$row['id'] ?? null,
|
||||
$row['label'],
|
||||
$row['description'] ?? null,
|
||||
$row['access-key'] ?? null,
|
||||
null,
|
||||
$row['uid'],
|
||||
$row['include-tags'] ?? null,
|
||||
$row['exclude-tags'] ?? null,
|
||||
$row['full-text-search'] ?? null,
|
||||
$row['media-type'] ?? null,
|
||||
$row['circle'] ?? null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,28 +21,31 @@
|
|||
|
||||
namespace Friendica\Content\Conversation\Factory;
|
||||
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Content\Conversation\Collection\Timelines;
|
||||
use Friendica\Content\Conversation\Entity;
|
||||
|
||||
final class UserDefinedChannel extends Timeline
|
||||
final class UserDefinedChannel extends Timeline implements ICanCreateFromTableRow
|
||||
{
|
||||
/**
|
||||
* List of available user defined channels
|
||||
*
|
||||
* @param integer $uid
|
||||
* @return Timelines
|
||||
*/
|
||||
public function getForUser(int $uid): Timelines
|
||||
{
|
||||
$tabs = [];
|
||||
foreach ($this->channelRepository->selectByUid($uid) as $channel) {
|
||||
$tabs[] = $channel;
|
||||
}
|
||||
|
||||
return new Timelines($tabs);
|
||||
}
|
||||
|
||||
public function isTimeline(string $selectedTab, int $uid): bool
|
||||
{
|
||||
return is_numeric($selectedTab) && $uid && $this->channelRepository->existsById($selectedTab, $uid);
|
||||
}
|
||||
|
||||
public function createFromTableRow(array $row): Entity\UserDefinedChannel
|
||||
{
|
||||
return new Entity\UserDefinedChannel(
|
||||
$row['id'] ?? null,
|
||||
$row['label'],
|
||||
$row['description'] ?? null,
|
||||
$row['access-key'] ?? null,
|
||||
null,
|
||||
$row['uid'],
|
||||
$row['include-tags'] ?? null,
|
||||
$row['exclude-tags'] ?? null,
|
||||
$row['full-text-search'] ?? null,
|
||||
$row['media-type'] ?? null,
|
||||
$row['circle'] ?? null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,30 +22,48 @@
|
|||
namespace Friendica\Content\Conversation\Repository;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\Content\Conversation\Entity\Timeline as TimelineEntity;
|
||||
use Friendica\Content\Conversation\Entity\UserDefinedChannel;
|
||||
use Friendica\Content\Conversation\Factory\Timeline;
|
||||
use Friendica\Content\Conversation\Collection\UserDefinedChannels;
|
||||
use Friendica\Content\Conversation\Entity;
|
||||
use Friendica\Content\Conversation\Factory;
|
||||
use Friendica\Database\Database;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Channel extends \Friendica\BaseRepository
|
||||
class UserDefinedChannel extends \Friendica\BaseRepository
|
||||
{
|
||||
protected static $table_name = 'channel';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Timeline $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\UserDefinedChannel $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return UserDefinedChannels
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _select(array $condition, array $params = []): BaseCollection
|
||||
{
|
||||
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
|
||||
|
||||
$Entities = new UserDefinedChannels();
|
||||
foreach ($rows as $fields) {
|
||||
$Entities[] = $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
return $Entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a single user channel
|
||||
*
|
||||
* @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)
|
||||
* @return TimelineEntity
|
||||
* @return Entity\UserDefinedChannel
|
||||
* @throws \Friendica\Network\HTTPException\NotFoundException
|
||||
*/
|
||||
public function selectById(int $id, int $uid): TimelineEntity
|
||||
public function selectById(int $id, int $uid): Entity\UserDefinedChannel
|
||||
{
|
||||
return $this->_selectOne(['id' => $id, 'uid' => $uid]);
|
||||
}
|
||||
|
@ -78,14 +96,15 @@ class Channel extends \Friendica\BaseRepository
|
|||
* Fetch all user channels
|
||||
*
|
||||
* @param integer $uid
|
||||
* @return BaseCollection
|
||||
* @return UserDefinedChannels
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function selectByUid(int $uid): BaseCollection
|
||||
public function selectByUid(int $uid): UserDefinedChannels
|
||||
{
|
||||
return $this->_select(['uid' => $uid]);
|
||||
}
|
||||
|
||||
public function save(UserDefinedChannel $Channel): UserDefinedChannel
|
||||
public function save(Entity\UserDefinedChannel $Channel): Entity\UserDefinedChannel
|
||||
{
|
||||
$fields = [
|
||||
'label' => $Channel->label,
|
|
@ -574,7 +574,7 @@ class Widget
|
|||
}
|
||||
}
|
||||
|
||||
foreach (DI::UserDefinedChannelFactory()->getForUser($uid) as $channel) {
|
||||
foreach (DI::userDefinedChannel()->selectByUid($uid) as $channel) {
|
||||
if (empty($enabled) || in_array($channel->code, $enabled)) {
|
||||
$channels[] = ['ref' => $channel->code, 'name' => $channel->label];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue