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