Elgg  Version 4.3
ThreadPreloaderService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Comments;
4 
6 
13 
17  protected $children;
18 
26  public function preloadThreads(array $comments): void {
27  if (empty($comments)) {
28  return;
29  }
30 
31  $this->children = [];
32 
33  $guids = [];
34  $container_guid = 0;
35  /* @var $comment \ElggComment */
36  foreach ($comments as $comment) {
37  $guids[] = $comment->guid;
38  $container_guid = $comment->container_guid;
39  }
40 
42  'type' => 'object',
43  'subtype' => 'comment',
44  'limit' => false,
45  'batch' => true,
46  'container_guid' => $container_guid,
47  'metadata_name_value_pairs' => [
48  'thread_guid' => $guids,
49  ],
50  'order_by' => new OrderByClause('e.time_created', 'ASC'),
51  'preload_owners' => true,
52  ]);
53 
54  /* @var $comment \ElggComment */
55  foreach ($batch as $comment) {
56  $parent_guid = (int) $comment->parent_guid;
57  if (!isset($this->children[$parent_guid])) {
58  $this->children[$parent_guid] = [];
59  }
60 
61  $this->children[$parent_guid][] = $comment;
62  }
63  }
64 
72  public function getChildren(int $comment_guid): array {
73  if (!isset($this->children)) {
74  $comment = get_entity($comment_guid);
75  if ($comment instanceof \ElggComment) {
76  $this->preloadThreads([$comment->getThreadEntity()]);
77  }
78  }
79 
80  return elgg_extract($comment_guid, $this->children, []);
81  }
82 }
if(!$entity) if(!$entity->canComment()) $comment
Definition: save.php:42
$comments
if(!$enabled) if(PHP_SAPI!== 'cli')
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
$comment_guid
Definition: save.php:7
getChildren(int $comment_guid)
Get the children of a comment.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
Extends QueryBuilder with ORDER BY clauses.
$guids
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
$container_guid
preloadThreads(array $comments)
Preload the comment threads for the given comments.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69