comparison core/modules/aggregator/src/ItemStorage.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\aggregator;
4
5 use Drupal\Core\Entity\Query\QueryInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
7
8 /**
9 * Controller class for aggregators items.
10 *
11 * This extends the Drupal\Core\Entity\Sql\SqlContentEntityStorage class, adding
12 * required special handling for feed item entities.
13 */
14 class ItemStorage extends SqlContentEntityStorage implements ItemStorageInterface {
15
16 /**
17 * {@inheritdoc}
18 */
19 public function getItemCount(FeedInterface $feed) {
20 $query = \Drupal::entityQuery('aggregator_item')
21 ->condition('fid', $feed->id())
22 ->count();
23
24 return $query->execute();
25 }
26
27 /**
28 * {@inheritdoc}
29 */
30 public function loadAll($limit = NULL) {
31 $query = \Drupal::entityQuery('aggregator_item');
32 return $this->executeFeedItemQuery($query, $limit);
33 }
34
35 /**
36 * {@inheritdoc}
37 */
38 public function loadByFeed($fid, $limit = NULL) {
39 $query = \Drupal::entityQuery('aggregator_item')
40 ->condition('fid', $fid);
41 return $this->executeFeedItemQuery($query, $limit);
42 }
43
44 /**
45 * Helper method to execute an item query.
46 *
47 * @param \Drupal\Core\Entity\Query\QueryInterface $query
48 * The query to execute.
49 * @param int $limit
50 * (optional) The number of items to return.
51 *
52 * @return \Drupal\aggregator\ItemInterface[]
53 * An array of the feed items.
54 */
55 protected function executeFeedItemQuery(QueryInterface $query, $limit) {
56 $query->sort('timestamp', 'DESC')
57 ->sort('iid', 'DESC');
58 if (!empty($limit)) {
59 $query->pager($limit);
60 }
61
62 return $this->loadMultiple($query->execute());
63 }
64
65 }