2020-08-21 12:00:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-24 09:26:44 +01:00
|
|
|
namespace Drupal\opdavies_talks\Repository;
|
2020-08-21 12:00:00 +01:00
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityStorageInterface;
|
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
2021-02-10 02:30:10 +00:00
|
|
|
use Drupal\node\NodeInterface;
|
2021-02-10 07:54:43 +00:00
|
|
|
use Drupal\opdavies_talks\Collection\TalkCollection;
|
2020-08-21 12:00:00 +01:00
|
|
|
|
|
|
|
final class TalkRepository {
|
|
|
|
|
|
|
|
private EntityStorageInterface $nodeStorage;
|
|
|
|
|
|
|
|
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
|
|
|
|
$this->nodeStorage = $entityTypeManager->getStorage('node');
|
|
|
|
}
|
|
|
|
|
2021-02-10 07:54:43 +00:00
|
|
|
public function findAll(): TalkCollection {
|
2021-02-10 02:41:14 +00:00
|
|
|
$talks = $this->nodeStorage->loadByProperties($this->defaultProperties());
|
2020-08-21 12:00:00 +01:00
|
|
|
|
2021-02-10 07:54:43 +00:00
|
|
|
return new TalkCollection($talks);
|
2020-08-21 12:00:00 +01:00
|
|
|
}
|
|
|
|
|
2021-02-10 07:54:43 +00:00
|
|
|
public function findAllPublished(): TalkCollection {
|
2021-02-10 02:41:14 +00:00
|
|
|
$talks = $this->nodeStorage->loadByProperties(array_merge(
|
|
|
|
$this->defaultProperties(),
|
|
|
|
[
|
|
|
|
'status' => NodeInterface::PUBLISHED,
|
|
|
|
],
|
|
|
|
));
|
2021-02-10 02:30:10 +00:00
|
|
|
|
2021-02-10 07:54:43 +00:00
|
|
|
return new TalkCollection($talks);
|
2021-02-10 02:30:10 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 02:41:14 +00:00
|
|
|
private function defaultProperties(): array {
|
|
|
|
return [
|
|
|
|
'type' => 'talk',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-21 12:00:00 +01:00
|
|
|
}
|