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) use ($owner_guid) {
31  $qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
32  return $qb->compare('ce.owner_guid', '=', $owner_guid, ELGG_VALUE_INTEGER);
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) use ($container_guid) {
40  $qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
41  return $qb->compare('ce.container_guid', '=', $container_guid, ELGG_VALUE_INTEGER);
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) use ($subtypes) {
49  $qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
50  return $qb->compare('ce.subtype', 'IN', $subtypes, ELGG_VALUE_STRING);
51  };
52 }
53 
54 $title = elgg_echo('generic_comments:latest');
56 if ($comments) {
57  $body = elgg_view('page/components/list', [
58  'items' => $comments,
59  'pagination' => false,
60  'list_class' => 'elgg-latest-comments',
61  'full_view' => false,
62  ]);
63 } else {
64  $body = '<p>' . elgg_echo('generic_comment:none') . '</p>';
65 }
66 
67 echo elgg_view_module('aside', $title, $body);
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:919
$comments
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:111
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
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_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:505
$body
Definition: useradd.php:55
$options
Display the latest related comments.
$vars
Definition: theme.php:5
const ELGG_VALUE_STRING
Definition: constants.php:112
$subtypes
$container_guid
$qb
Definition: queue.php:12
if($owner_guid) if($container_guid) if($subtypes) $title