Elgg  Version master
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  'preload_owners' => true,
46  'preload_containers' => true,
47  ]);
48 
49  // why is this reversing it? because we're asking for the 3 latest
50  // comments by sorting desc and limiting by 3, but we want to display
51  // these comments with the latest at the bottom.
52  $comments = array_reverse($comments);
53 
55  'list_class' => 'elgg-river-comments',
56  'full_view' => false,
57  'register_rss_link' => false,
58  'show_responses' => false,
59  ]);
60 
62  $all_link = elgg_view_url($object->getURL(), elgg_echo('river:comments:all', [$comment_count]));
63  echo elgg_format_element('div', ['class' => 'elgg-river-more'], $all_link);
64  }
65 }
66 
67 if (!$object->canComment()) {
68  return;
69 }
70 
71 // inline comment form
72 $form_vars = ['id' => "comments-add-{$object->guid}-{$item->id}", 'class' => 'hidden'];
73 $body_vars = ['entity' => $object, 'inline' => true];
74 echo elgg_view_form('comment/save', $form_vars, $body_vars);
if($comment_count) if(!$object->canComment()) $form_vars
Definition: responses.php:72
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
elgg_view_form(string $action, array $form_vars=[], array $body_vars=[])
Definition: views.php:1033
$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:507
if(isset($responses)) $item
Definition: responses.php:18
if($comment_count) if(!$object->canComment()) $body_vars
Definition: responses.php:73
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:636
$vars
Definition: theme.php:5
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
Definition: views.php:1427
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
if($owner_guid) if($container_guid) if($subtypes) $comments