Elgg  Version 3.0
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 ];
21 
22 $owner_guid = elgg_extract('owner_guid', $vars);
23 $container_guid = elgg_extract('container_guid', $vars);
24 $subtypes = elgg_extract('subtypes', $vars);
25 
26 // If owner is defined, view only the comments that have
27 // been posted on objects owned by that user
28 if ($owner_guid) {
29  $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($owner_guid) {
30  $qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
31  return $qb->compare('ce.owner_guid', '=', $owner_guid, ELGG_VALUE_INTEGER);
32  };
33 }
34 
35 // If container is defined, view only the comments that have
36 // been posted on objects placed inside that container
37 if ($container_guid) {
38  $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($container_guid) {
39  $qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
40  return $qb->compare('ce.container_guid', '=', $container_guid, ELGG_VALUE_INTEGER);
41  };
42 }
43 
44 // If subtypes are defined, view only the comments that have been
45 // posted on objects that belong to any of those subtypes
46 if ($subtypes) {
47  $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($subtypes) {
48  $qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
49  return $qb->compare('ce.subtype', 'IN', $subtypes, ELGG_VALUE_STRING);
50  };
51 }
52 
53 $title = elgg_echo('generic_comments:latest');
55 if ($comments) {
56  $body = elgg_view('page/components/list', [
57  'items' => $comments,
58  'pagination' => false,
59  'list_class' => 'elgg-latest-comments',
60  'full_view' => false,
61  ]);
62 } else {
63  $body = '<p>' . elgg_echo('generic_comment:none') . '</p>';
64 }
65 
$comments
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:138
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$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:1198
elgg echo
Translates a string.
Definition: languages.js:43
$body
Definition: useradd.php:60
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:1131
$options
Display the latest related comments.
const ELGG_VALUE_STRING
Definition: constants.php:139
$vars['type']
Definition: save.php:11
$subtypes
$container_guid
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
if($owner_guid) if($container_guid) if($subtypes) $title