diff options
-rw-r--r-- | engine/lib/annotations.php | 24 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 43 | ||||
-rw-r--r-- | views/default/navigation/pagination.php | 7 |
3 files changed, 73 insertions, 1 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 0507cba09..4dcf9b588 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -278,6 +278,30 @@ return get_data($query, "row_to_elggannotation");
}
+
+ /**
+ * Returns a human-readable list of annotations on a particular entity.
+ *
+ * @param int $entity_guid The entity GUID
+ * @param string $name The name of the kind of annotation
+ * @param int $limit The number of annotations to display at once
+ * @param true|false $asc Whether or not the annotations are displayed in ascending order. (Default: true)
+ * @return string HTML (etc) version of the annotation list
+ */
+ function list_annotations($entity_guid, $name = "", $limit = 25, $asc = true) {
+
+ if ($asc) {
+ $asc = "asc";
+ } else {
+ $asc = "desc";
+ }
+ $count = count_annotations($entity_guid, "", "", $name);
+ $offset = (int) get_input("annoff",0);
+ $annotations = get_annotations($entity_guid, "", "", $name, "", "", $limit, $offset, $asc);
+
+ return elgg_view_annotation_list($annotations, $count, $offset, $limit);
+
+ }
/**
* Return the sum of a given integer annotation.
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index f1ddb2472..b39f83417 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -381,6 +381,49 @@ return $html;
}
+
+ /**
+ * Returns a view of a list of annotations, plus navigation. It is intended that this function
+ * be called from other wrapper functions.
+ *
+ * @param array $annotations List of annotations
+ * @param int $count The total number of annotations across all pages
+ * @param int $offset The current indexing offset
+ * @param int $limit The number of annotations to display per page
+ * @return string The list of annotations
+ */
+
+ function elgg_view_annotation_list($annotations, $count, $offset, $limit) {
+
+ $count = (int) $count;
+ $offset = (int) $offset;
+ $limit = (int) $limit;
+
+ $html = "";
+
+ $nav = elgg_view('navigation/pagination',array(
+
+ 'baseurl' => $_SERVER['REQUEST_URI'],
+ 'offset' => $offset,
+ 'count' => $count,
+ 'word' => 'annoff',
+
+ ));
+
+ $html .= $nav;
+
+ if (is_array($annotations) && sizeof($annotations) > 0) {
+ foreach($annotations as $annotation) {
+ $html .= elgg_view_annotation($annotation, "", false);
+ }
+ }
+
+ if ($count)
+ $html .= $nav;
+
+ return $html;
+
+ }
/**
* Displays an internal layout for the use of a plugin canvas.
diff --git a/views/default/navigation/pagination.php b/views/default/navigation/pagination.php index b96ce32d1..d2a2eca51 100644 --- a/views/default/navigation/pagination.php +++ b/views/default/navigation/pagination.php @@ -27,11 +27,16 @@ } else {
$count = $vars['count'];
}
+ if (!isset($vars['word'])) {
+ $word = "offset";
+ } else {
+ $word = $vars['word'];
+ }
$totalpages = ceil($count / $limit);
$currentpage = ceil($offset / $limit) + 1;
- $baseurl = preg_replace('/[\&\?]offset\=[0-9]*/',"",$vars['baseurl']);
+ $baseurl = preg_replace('/[\&\?]'.$word.'\=[0-9]*/',"",$vars['baseurl']);
?>
|