2022-01-04 22:22:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
// {{{ 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 Component\Circle\Controller;
|
|
|
|
|
|
|
|
use App\Core\Cache;
|
2022-03-27 15:19:09 +01:00
|
|
|
use App\Core\DB;
|
2022-03-27 16:43:59 +01:00
|
|
|
use App\Core\Router;
|
2022-01-04 22:22:48 +00:00
|
|
|
use App\Entity\Actor;
|
|
|
|
use App\Entity\LocalUser;
|
|
|
|
use Component\Circle\Entity\ActorCircle;
|
|
|
|
use Component\Collection\Util\Controller\MetaCollectionController;
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
/**
|
|
|
|
* @extends MetaCollectionController<Circles>
|
|
|
|
*/
|
2022-01-04 22:22:48 +00:00
|
|
|
class Circles extends MetaCollectionController
|
|
|
|
{
|
2022-02-26 14:09:41 +00:00
|
|
|
protected const SLUG = 'circle';
|
|
|
|
protected const PLURAL_SLUG = 'circles';
|
|
|
|
protected string $page_title = 'Actor circles';
|
2022-01-04 22:22:48 +00:00
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
public function createCollection(int $owner_id, string $name): bool
|
2022-01-04 22:22:48 +00:00
|
|
|
{
|
2022-10-19 22:39:17 +01:00
|
|
|
return !\is_null(\Component\Circle\Circle::createCircle($owner_id, $name));
|
2022-01-04 22:22:48 +00:00
|
|
|
}
|
2022-10-19 22:39:17 +01:00
|
|
|
|
2022-01-04 22:22:48 +00:00
|
|
|
public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string
|
|
|
|
{
|
|
|
|
return Router::url(
|
|
|
|
'actor_circle_view_by_circle_id',
|
|
|
|
['circle_id' => $collection_id],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
/**
|
|
|
|
* @return Circles[]
|
|
|
|
*/
|
|
|
|
public function getCollectionItems(int $owner_id, int $collection_id): array
|
2022-01-04 22:22:48 +00:00
|
|
|
{
|
2022-10-19 22:39:17 +01:00
|
|
|
return []; // TODO
|
2022-01-04 22:22:48 +00:00
|
|
|
}
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
/**
|
|
|
|
* @return Circles[]
|
|
|
|
*/
|
2022-01-04 22:22:48 +00:00
|
|
|
public function feedByCircleId(int $circle_id)
|
|
|
|
{
|
|
|
|
// Owner id isn't used
|
|
|
|
return $this->getCollectionItems(0, $circle_id);
|
|
|
|
}
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
/**
|
|
|
|
* @return Circles[]
|
|
|
|
*/
|
2022-01-04 22:22:48 +00:00
|
|
|
public function feedByTaggerIdAndTag(int $tagger_id, string $tag)
|
|
|
|
{
|
|
|
|
// Owner id isn't used
|
|
|
|
$circle_id = ActorCircle::getByPK(['tagger' => $tagger_id, 'tag' => $tag])->getId();
|
|
|
|
return $this->getCollectionItems($tagger_id, $circle_id);
|
|
|
|
}
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
/**
|
|
|
|
* @return Circles[]
|
|
|
|
*/
|
2022-01-04 22:22:48 +00:00
|
|
|
public function feedByTaggerNicknameAndTag(string $tagger_nickname, string $tag)
|
|
|
|
{
|
|
|
|
$tagger_id = LocalUser::getByNickname($tagger_nickname)->getId();
|
|
|
|
$circle_id = ActorCircle::getByPK(['tagger' => $tagger_id, 'tag' => $tag])->getId();
|
|
|
|
return $this->getCollectionItems($tagger_id, $circle_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCollectionsByActorId(int $owner_id): array
|
|
|
|
{
|
|
|
|
return DB::findBy(ActorCircle::class, ['tagger' => $owner_id], order_by: ['id' => 'desc']);
|
|
|
|
}
|
2022-10-19 22:39:17 +01:00
|
|
|
|
|
|
|
public function getCollectionBy(int $owner_id, int $collection_id): self
|
2022-01-04 22:22:48 +00:00
|
|
|
{
|
|
|
|
return DB::findOneBy(ActorCircle::class, ['id' => $collection_id, 'actor_id' => $owner_id]);
|
|
|
|
}
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
public function setCollectionName(int $actor_id, string $actor_nickname, ActorCircle $collection, string $name): void
|
2022-01-04 22:22:48 +00:00
|
|
|
{
|
|
|
|
foreach ($collection->getActorTags(db_reference: true) as $at) {
|
|
|
|
$at->setTag($name);
|
|
|
|
}
|
|
|
|
$collection->setTag($name);
|
|
|
|
Cache::delete(Actor::cacheKeys($actor_id)['circles']);
|
|
|
|
}
|
|
|
|
|
2022-10-19 22:39:17 +01:00
|
|
|
public function removeCollection(int $actor_id, string $actor_nickname, ActorCircle $collection): void
|
2022-01-04 22:22:48 +00:00
|
|
|
{
|
|
|
|
foreach ($collection->getActorTags(db_reference: true) as $at) {
|
|
|
|
DB::remove($at);
|
|
|
|
}
|
|
|
|
DB::remove($collection);
|
|
|
|
Cache::delete(Actor::cacheKeys($actor_id)['circles']);
|
|
|
|
}
|
|
|
|
}
|