Elgg  Version 3.0
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)) {
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 $comment_count = $object->countComments();
31 
32 if ($comment_count) {
34  'type' => 'object',
35  'subtype' => 'comment',
36  'container_guid' => $object->getGUID(),
37  'limit' => 3,
38  'order_by' => [new OrderByClause('time_created', 'DESC')],
39  'distinct' => false,
40  ]);
41 
42  // why is this reversing it? because we're asking for the 3 latest
43  // comments by sorting desc and limiting by 3, but we want to display
44  // these comments with the latest at the bottom.
45  $comments = array_reverse($comments);
46 
47  echo elgg_view_entity_list($comments, [
48  'list_class' => 'elgg-river-comments',
49  'show_excerpt' => true,
50  'register_rss_link' => false,
51  ]);
52 
53  if ($comment_count > count($comments)) {
54  echo elgg_format_element('div', ['class' => 'elgg-river-more'], elgg_view('output/url', [
55  'href' => $object->getURL(),
56  'text' => elgg_echo('river:comments:all', [$comment_count]),
57  'is_trusted' => true,
58  ]));
59  }
60 }
61 
62 if (!$object->canComment()) {
63  return;
64 }
65 
66 // inline comment form
67 $form_vars = ['id' => "comments-add-{$object->guid}-{$item->id}", 'class' => 'hidden'];
68 $body_vars = ['entity' => $object, 'inline' => true];
69 echo elgg_view_form('comment/save', $form_vars, $body_vars);
if($comment_count) if(!$object->canComment()) $form_vars
Definition: responses.php:67
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
elgg_view_entity_list($entities, array $vars=[])
Returns a rendered list of entities with pagination.
Definition: views.php:996
$comments
$responses
Definition: responses.php:15
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
elgg_view_form($action, $form_vars=[], $body_vars=[])
Definition: views.php:1318
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg echo
Translates a string.
Definition: languages.js:43
if(isset($responses)) $item
Definition: responses.php:18
if($comment_count) if(!$object->canComment()) $body_vars
Definition: responses.php:68
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
Extends QueryBuilder with ORDER BY clauses.
$vars['type']
Definition: save.php:11
if(!empty($item->annotation_id)||!$object instanceof ElggEntity||$object instanceof ElggComment) $comment_count
Definition: responses.php:30
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246