Elgg  Version 6.3
comments_block.php
Go to the documentation of this file.
1 <?php
14  'type' => 'object',
15  'subtype' => 'comment',
16  'limit' => elgg_extract('limit', $vars, 4),
17  'wheres' => [],
18  'preload_owners' => true,
19  'preload_containers' => true,
20  'distinct' => false,
21  'metadata_name_value_pairs' => ['level' => 1],
22 ];
23 
24 $owner_guid = elgg_extract('owner_guid', $vars);
25 $container_guid = elgg_extract('container_guid', $vars);
26 $subtypes = elgg_extract('subtypes', $vars);
27 
28 // If owner is defined, view only the comments that have
29 // been posted on objects owned by that user
30 if ($owner_guid) {
31  $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($owner_guid) {
32  $qb->joinEntitiesTable($main_alias, 'container_guid', 'inner', 'ce');
33  return $qb->compare('ce.owner_guid', '=', $owner_guid, ELGG_VALUE_GUID);
34  };
35 }
36 
37 // If container is defined, view only the comments that have
38 // been posted on objects placed inside that container
39 if ($container_guid) {
40  $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($container_guid) {
41  $qb->joinEntitiesTable($main_alias, 'container_guid', 'inner', 'ce');
42  return $qb->compare('ce.container_guid', '=', $container_guid, ELGG_VALUE_GUID);
43  };
44 }
45 
46 // If subtypes are defined, view only the comments that have been
47 // posted on objects that belong to any of those subtypes
48 if ($subtypes) {
49  $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($subtypes) {
50  $qb->joinEntitiesTable($main_alias, 'container_guid', 'inner', 'ce');
51  return $qb->compare('ce.subtype', 'IN', $subtypes, ELGG_VALUE_STRING);
52  };
53 }
54 
56 if (empty($comments)) {
57  return;
58 }
59 
61  'pagination' => false,
62  'full_view' => false,
63  'list_class' => 'elgg-latest-comments',
64  'item_view' => 'object/comment/sidebar',
65 ]);
66 
67 echo elgg_view_module('aside', elgg_echo('generic_comments:latest'), $body);
$vars
Definition: theme.php:3
$options
Display the latest related comments.
if($owner_guid) if($container_guid) if($subtypes) $comments
$owner_guid
$subtypes
if(empty($comments)) $body
$container_guid
const ELGG_VALUE_STRING
Definition: constants.php:112
const ELGG_VALUE_GUID
Definition: constants.php:113
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:240
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:922
elgg_view_entity_list(array $entities, array $vars=[])
Returns a rendered list of entities with pagination.
Definition: views.php:639
$qb
Definition: queue.php:14