Elgg  Version master
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  foreach ($comments as $comment) {
36  $guids[] = $comment->guid;
37  $container_guid = $comment->container_guid;
38  }
39 
41  'type' => 'object',
42  'subtype' => 'comment',
43  'limit' => false,
44  'batch' => true,
45  'container_guid' => $container_guid,
46  'metadata_name_value_pairs' => [
47  'thread_guid' => $guids,
48  ],
49  'order_by' => new OrderByClause('e.time_created', 'ASC'),
50  'preload_owners' => true,
51  ]);
52 
53  /* @var $comment \ElggComment */
54  foreach ($batch as $comment) {
55  $parent_guid = (int) $comment->parent_guid;
56  if (!isset($this->children[$parent_guid])) {
57  $this->children[$parent_guid] = [];
58  }
59 
60  $this->children[$parent_guid][] = $comment;
61  }
62  }
63 
71  public function getChildren(int $comment_guid): array {
72  if (!isset($this->children)) {
73  $comment = get_entity($comment_guid);
74  if ($comment instanceof \ElggComment) {
75  $this->preloadThreads([$comment->getThreadEntity()]);
76  }
77  }
78 
79  return elgg_extract($comment_guid, $this->children, []);
80  }
81 }
if(parse_url(elgg_get_site_url(), PHP_URL_PATH)!== '/') if(file_exists(elgg_get_root_path(). 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
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
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
getChildren(int $comment_guid)
Get the children of a comment.
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
if(!$entity instanceof\ElggEntity) if(!$entity->canComment()) $comment
Definition: save.php:42
Extends QueryBuilder with ORDER BY clauses.
$guids
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
if($owner_guid) if($container_guid) if($subtypes) $comments
$container_guid
preloadThreads(array $comments)
Preload the comment threads for the given comments.