[COMPONENT][Collection] Make MetaCollectionPlugin a trait and abstract collection delete and name update
This commit is contained in:
parent
754135743e
commit
9df9c6a19c
|
@ -11,10 +11,10 @@ use Component\Feed\Feed;
|
|||
|
||||
class Collection extends Controller
|
||||
{
|
||||
public function query(string $query, ?string $language = null, ?Actor $actor = null)
|
||||
public function query(string $query, ?string $locale = null, ?Actor $actor = null)
|
||||
{
|
||||
$actor ??= Common::actor();
|
||||
$language ??= $actor->getTopLanguage()->getLocale();
|
||||
return Feed::query($query, $this->int('page') ?? 1, $language, $actor);
|
||||
$actor ??= Common::actor();
|
||||
$locale ??= Common::currentLanguage()->getLocale();
|
||||
return Feed::query($query, $this->int('page') ?? 1, $locale, $actor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ abstract class MetaCollectionController extends FeedController
|
|||
$collections = $this->getCollectionsByActorId($id);
|
||||
|
||||
$create_title = _m('Create a ' . mb_strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $this->slug)));
|
||||
$collections_title = _m('Your ' . mb_strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $this->plural_slug)));
|
||||
$collections_title = _m('The ' . mb_strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $this->plural_slug)));
|
||||
// create collection form
|
||||
$create = null;
|
||||
if (Common::user()?->getId() === $id) {
|
||||
|
@ -127,7 +127,7 @@ abstract class MetaCollectionController extends FeedController
|
|||
$this->parent = $parent;
|
||||
$this->slug = $slug;
|
||||
}
|
||||
// there's already a injected function called path,
|
||||
// there's already an injected function called path,
|
||||
// that maps to Router::url(name, args), but since
|
||||
// I want to preserve nicknames, I think it's better
|
||||
// to use that getUrl function
|
||||
|
@ -159,8 +159,7 @@ abstract class MetaCollectionController extends FeedController
|
|||
]);
|
||||
$edit->handleRequest($this->request);
|
||||
if ($edit->isSubmitted() && $edit->isValid()) {
|
||||
$collection->setName($edit->getData()['name']);
|
||||
DB::persist($collection);
|
||||
$this->parent->setCollectionName($this->id, $this->nick, $collection, $edit->getData()['name']);
|
||||
DB::flush();
|
||||
throw new RedirectException();
|
||||
}
|
||||
|
@ -181,7 +180,7 @@ abstract class MetaCollectionController extends FeedController
|
|||
]);
|
||||
$rm->handleRequest($this->request);
|
||||
if ($rm->isSubmitted()) {
|
||||
DB::remove($collection);
|
||||
$this->parent->removeCollection($this->id, $this->nick, $collection);
|
||||
DB::flush();
|
||||
throw new RedirectException();
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ use App\Core\DB\DB;
|
|||
use App\Core\Event;
|
||||
use App\Core\Form;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Core\Modules\Plugin;
|
||||
use App\Entity\Actor;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\RedirectException;
|
||||
|
@ -45,10 +44,10 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
abstract class MetaCollectionPlugin extends Plugin
|
||||
trait MetaCollectionTrait
|
||||
{
|
||||
protected string $slug = 'collection';
|
||||
protected string $plural_slug = 'collections';
|
||||
//protected string $slug = 'collection';
|
||||
//protected string $plural_slug = 'collections';
|
||||
|
||||
abstract protected function createCollection(Actor $owner, array $vars, string $name);
|
||||
abstract protected function removeItems(Actor $owner, array $vars, $items, array $collections);
|
|
@ -34,20 +34,24 @@ namespace Plugin\AttachmentCollections;
|
|||
use App\Core\DB\DB;
|
||||
use App\Core\Event;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Core\Modules\Plugin;
|
||||
use App\Core\Router\RouteLoader;
|
||||
use App\Core\Router\Router;
|
||||
use App\Entity\Actor;
|
||||
use App\Entity\Feed;
|
||||
use App\Entity\LocalUser;
|
||||
use App\Util\Nickname;
|
||||
use Component\Collection\Util\MetaCollectionPlugin;
|
||||
use Component\Collection\Util\MetaCollectionTrait;
|
||||
use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController;
|
||||
use Plugin\AttachmentCollections\Entity\AttachmentCollection;
|
||||
use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AttachmentCollections extends MetaCollectionPlugin
|
||||
class AttachmentCollections extends Plugin
|
||||
{
|
||||
use MetaCollectionTrait;
|
||||
protected string $slug = 'collection';
|
||||
protected string $plural_slug = 'collections';
|
||||
protected function createCollection(Actor $owner, array $vars, string $name)
|
||||
{
|
||||
$col = AttachmentCollection::create([
|
||||
|
|
|
@ -77,4 +77,15 @@ class AttachmentCollections extends MetaCollectionController
|
|||
{
|
||||
return DB::findOneBy(AttachmentCollection::class, ['id' => $collection_id]);
|
||||
}
|
||||
|
||||
public function setCollectionName(int $actor_id, string $actor_nickname, AttachmentCollection $collection, string $name)
|
||||
{
|
||||
$collection->setName($name);
|
||||
DB::persist($collection);
|
||||
}
|
||||
|
||||
public function removeCollection(int $actor_id, string $actor_nickname, AttachmentCollection $collection)
|
||||
{
|
||||
DB::remove($collection);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user