Elgg  Version 4.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  '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 
$comments
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:126
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$owner_guid
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
elgg_view_module($type, $title, $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:944
$body
Definition: useradd.php:59
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
$options
Display the latest related comments.
const ELGG_VALUE_STRING
Definition: constants.php:127
$subtypes
elgg echo
Translates a string.
Definition: deprecated.js:530
$vars['head']
Definition: html.php:24
$container_guid
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
$qb
Definition: queue.php:11
if($owner_guid) if($container_guid) if($subtypes) $title