Elgg  Version 1.11
comments_block.php
Go to the documentation of this file.
1 <?php
13 $options = array(
14  'type' => 'object',
15  'subtype' => 'comment',
16  'limit' => elgg_extract('limit', $vars, 4),
17  'wheres' => array(),
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 
27  $db_prefix = elgg_get_config('dbprefix');
28 
29  // Join on the entities table to check container subtype and/or owner
30  $options['joins'] = array("JOIN {$db_prefix}entities ce ON e.container_guid = ce.guid");
31 }
32 
33 // If owner is defined, view only the comments that have
34 // been posted on objects owned by that user
35 if ($owner_guid) {
36  $options['wheres'][] = "ce.owner_guid = $owner_guid";
37 }
38 
39 // If container is defined, view only the comments that have
40 // been posted on objects placed inside that container
41 if ($container_guid) {
42  $options['wheres'][] = "ce.container_guid = $container_guid";
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  if (is_array($subtypes)) {
49  $subtype_ids = array();
50  foreach ($subtypes as $subtype) {
51  $id = (int)get_subtype_id('object', $subtype);
52  if ($id) {
53  $subtype_ids[] = $id;
54  }
55  }
56  if ($subtype_ids) {
57  $subtype_string = implode(',', $subtype_ids);
58  $options['wheres'][] = "ce.subtype IN ($subtype_string)";
59  } else {
60  // subtype ids do not exist so cannot display comments
61  $options['wheres'][] = "1 = -1";
62  }
63  } else {
64  $subtype_id = (int)get_subtype_id('object', $subtypes);
65  $options['wheres'][] = "ce.subtype = $subtype_id";
66  }
67 }
68 
69 $title = elgg_echo('generic_comments:latest');
71 if ($comments) {
72  $body = elgg_view('page/components/list', array(
73  'items' => $comments,
74  'pagination' => false,
75  'list_class' => 'elgg-latest-comments',
76  'full_view' => false,
77  ));
78 } else {
79  $body = '<p>' . elgg_echo('generic_comment:none') . '</p>';
80 }
81 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_view_module($type, $title, $body, array $vars=array())
Wrapper function for the module display pattern.
Definition: views.php:1217
$comments
get_subtype_id($type, $subtype)
Return the id for a given subtype.
Definition: entities.php:157
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
$owner_guid
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg echo
Translates a string.
Definition: languages.js:43
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:490
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
$options
Display the latest related comments.
$subtypes
$container_guid
$subtype
Definition: river.php:12
if(!$collection_name) $id
Definition: add.php:17
if($owner_guid||$container_guid||$subtypes) if($owner_guid) if($container_guid) if($subtypes) $title
if(!$num_display) $db_prefix
Definition: content.php:12
if(file_exists($welcome)) $vars
Definition: upgrade.php:93