Elgg  Version master
Go to the documentation of this file.
1 <?php
3 namespace Elgg\Comments;
11 class DataService {
16  protected $counts = [];
26  public function setCommentsCount(int $guid, int $num): void {
27  $this->counts[$guid] = $num;
28  }
37  public function getCommentsCount(\ElggEntity $entity): int {
38  $guid = $entity->guid;
39  if (!isset($this->counts[$guid])) {
40  $this->counts[$guid] = elgg_count_entities([
41  'type' => 'object',
42  'subtype' => 'comment',
43  'container_guid' => $entity->guid,
44  'distinct' => false,
45  ]);
46  }
48  return $this->counts[$guid];
49  }
58  public function filterGuids(array $guids): array {
59  foreach ($guids as $key => $guid) {
60  if (!isset($this->counts[$guid])) {
61  continue;
62  }
64  unset($guids[$key]);
65  }
67  return array_values($guids);
68  }
75  public static function instance(): self {
76  static $inst;
77  if ($inst === null) {
78  $inst = new self();
79  }
81  return $inst;
82  }
83 }
setCommentsCount(int $guid, int $num)
Set number of comments.
Definition: DataService.php:26
Comments dataservice.
Definition: DataService.php:11
static instance()
Get a DataService instance.
Definition: DataService.php:75
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
getCommentsCount(\ElggEntity $entity)
Get the number of comments for an entity.
Definition: DataService.php:37
filterGuids(array $guids)
Removes already counted comments from list of guids.
Definition: DataService.php:58
Definition: reset.php:8
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
Reset an ElggUpgrade.
Definition: reset.php:6