BundleCollection.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Plugin\Bundles\Controller;
  20. use App\Core\DB;
  21. use App\Core\Router;
  22. use Component\Collection\Util\Controller\MetaCollectionController;
  23. use Plugin\Bundles\Entity\BundleCollection as BundleCollectionEntity;
  24. /**
  25. * @extends MetaCollectionController<BundleCollectionEntity>
  26. */
  27. class BundleCollection extends MetaCollectionController
  28. {
  29. public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string
  30. {
  31. if (\is_null($owner_nickname)) {
  32. return Router::url(
  33. 'collection_notes_view_by_actor_id',
  34. ['id' => $owner_id, 'cid' => $collection_id],
  35. );
  36. }
  37. return Router::url(
  38. 'collection_notes_view_by_nickname',
  39. ['nickname' => $owner_nickname, 'cid' => $collection_id],
  40. );
  41. }
  42. // FIXME
  43. public function getCollectionItems(int $owner_id, int $collection_id): array
  44. {
  45. [$notes] = DB::dql(
  46. <<<'EOF'
  47. SELECT notice FROM \Plugin\BlogCollections\Entity\BlogCollectionEntry AS entry
  48. LEFT JOIN \App\Entity\Actor AS actor
  49. WITH entry.actor_id = :owner_id
  50. LEFT JOIN \App\Entity\Note AS notice
  51. WITH entry.note_id = notice.id
  52. WHERE entry.blog_collection_id = :collection_id
  53. EOF,
  54. ['collection_id' => $collection_id, 'owner_id' => $owner_id],
  55. );
  56. return [
  57. '_template' => 'BlogCollections/collection_entry_view.html.twig',
  58. 'bare_notes' => array_values($notes),
  59. ];
  60. }
  61. public function getCollectionsByActorId(int $owner_id): array
  62. {
  63. return DB::findBy(BundleCollectionEntity::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']);
  64. }
  65. public function getCollectionBy(int $owner_id, int $collection_id): BundleCollectionEntity
  66. {
  67. return DB::findOneBy(BundleCollectionEntity::class, ['id' => $collection_id]);
  68. }
  69. public function createCollection(int $owner_id, string $name): bool
  70. {
  71. DB::persist(BundleCollectionEntity::create([
  72. 'name' => $name,
  73. 'actor_id' => $owner_id,
  74. ]));
  75. return true;
  76. }
  77. }