Elgg  Version 5.1
responses.php
Go to the documentation of this file.
1 <?php
10 
11 // allow river views to override the response content
12 $responses = elgg_extract('responses', $vars);
13 if (isset($responses)) {
14  echo $responses;
15  return;
16 }
17 
19 if (!$item instanceof ElggRiverItem) {
20  return;
21 }
22 
23 $object = $item->getObjectEntity();
24 
25 // annotations and comments do not have responses
26 if (!empty($item->annotation_id) || !$object instanceof ElggEntity || $object instanceof ElggComment) {
27  return;
28 }
29 
30 if (!$object->hasCapability('commentable')) {
31  return;
32 }
33 
34 $comment_count = $object->countComments();
35 
36 if ($comment_count) {
38  'type' => 'object',
39  'subtype' => 'comment',
40  'container_guid' => $object->guid,
41  'limit' => 3,
42  'order_by' => [new OrderByClause('time_created', 'DESC')],
43  'distinct' => false,
44  'metadata_name_value_pairs' => ['level' => 1],
45  ]);
46 
47  // why is this reversing it? because we're asking for the 3 latest
48  // comments by sorting desc and limiting by 3, but we want to display
49  // these comments with the latest at the bottom.
50  $comments = array_reverse($comments);
51 
53  'list_class' => 'elgg-river-comments',
54  'show_excerpt' => true,
55  'register_rss_link' => false,
56  'show_responses' => false,
57  ]);
58 
60  $all_link = elgg_view_url($object->getURL(), elgg_echo('river:comments:all', [$comment_count]));
61  echo elgg_format_element('div', ['class' => 'elgg-river-more'], $all_link);
62  }
63 }
64 
65 if (!$object->canComment()) {
66  return;
67 }
68 
69 // inline comment form
70 $form_vars = ['id' => "comments-add-{$object->guid}-{$item->id}", 'class' => 'hidden'];
71 $body_vars = ['entity' => $object, 'inline' => true];
72 echo elgg_view_form('comment/save', $form_vars, $body_vars);
if($comment_count) if(!$object->canComment()) $form_vars
Definition: responses.php:70
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
elgg_view_form(string $action, array $form_vars=[], array $body_vars=[])
Definition: views.php:1054
$comments
$responses
Definition: responses.php:16
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
if(!empty($item->annotation_id)||!$object instanceof ElggEntity||$object instanceof ElggComment) if(!$object->hasCapability('commentable')) $comment_count
Definition: responses.php:34
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:504
if(isset($responses)) $item
Definition: responses.php:18
if($comment_count) if(!$object->canComment()) $body_vars
Definition: responses.php:71
Extends QueryBuilder with ORDER BY clauses.
elgg_view_entity_list(array $entities, array $vars=[])
Returns a rendered list of entities with pagination.
Definition: views.php:657
$vars
Definition: theme.php:5
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
Definition: views.php:1481
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145