]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2189 created the object/list view with semantic markup
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 8 Dec 2010 02:37:26 +0000 (02:37 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 8 Dec 2010 02:37:26 +0000 (02:37 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7560 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/views.php
mod/blog/views/default/blog/sidebar_menu.php
views/default/annotation/generic_comment.php
views/default/annotation/list.php [deleted file]
views/default/layout/elements/comments.php [moved from views/default/comments/list.php with 100% similarity]
views/default/layout/objects/list.php [new file with mode: 0644]

index 6fd6cfb8cd1d807ac19751d605a484d486b82d24..5b98214cb39baef54b3764042183bf4587820af2 100644 (file)
@@ -783,13 +783,13 @@ function elgg_view_annotation(ElggAnnotation $annotation, $full = true, $bypass
  * @see elgg_list_entities_from_relationships()
  * @see elgg_list_entities_from_annotations()
  *
- * @param array $entities       List of entities
- * @param int   $count          The total number of entities across all pages
- * @param int   $offset         The current indexing offset
- * @param int   $limit          The number of entities to display per page
- * @param bool  $fullview       Whether or not to display the full view (default: true)
- * @param bool  $listtypetoggle Whether or not to allow users to toggle to gallery view
- * @param bool  $pagination     Whether pagination is offered.
+ * @param array $entities         List of entities
+ * @param int   $count            The total number of entities across all pages
+ * @param int   $offset           The current indexing offset
+ * @param int   $limit            The number of entities to display per page
+ * @param bool  $full_view        Whether or not to display the full view (default: true)
+ * @param bool  $list_type_toggle Whether or not to allow users to toggle to gallery view
+ * @param bool  $pagination       Whether pagination is offered.
  *
  * @return string The list of entities
  * @access private
@@ -801,23 +801,23 @@ $list_type_toggle = true, $pagination = true) {
        $limit = (int) $limit;
 
        // do not require views to explicitly pass in the offset
-       if (!$offset = (int) $offset) {
-               $offset = sanitise_int(get_input('offset', 0));
+       if (!is_int($offset)) {
+               $offset = (int)get_input('offset', 0);
        }
 
        $context = elgg_get_context();
 
-       $html = elgg_view('entities/list', array(
-               'entities' => $entities,
+       $html = elgg_view('layout/objects/list', array(
+               'items' => $entities,
                'count' => $count,
                'offset' => $offset,
                'limit' => $limit,
-               'baseurl' => $_SERVER['REQUEST_URI'],
-               'fullview' => $full_view,
+               'full_view' => $full_view,
                'context' => $context,
-               'listtypetoggle' => $list_type_toggle,
-               'listtype' => get_input('listtype', 'list'),
-               'pagination' => $pagination
+               'pagination' => $pagination,
+               'list_type_toggle' => $list_type_toggle,
+               'list_type' => get_input('listtype', 'list'),
+               'list_class' => 'elgg-entity-list',
        ));
 
        return $html;
@@ -837,13 +837,15 @@ $list_type_toggle = true, $pagination = true) {
  */
 function elgg_view_annotation_list($annotations, $count, $offset, $limit) {
        $params = array(
-               'annotations' => $annotations,
+               'items' => $annotations,
                'count' => (int) $count,
                'offset' => (int) $offset,
                'limit' => (int) $limit,
+               'list-class' => 'elgg-annotation-list',
+               'full_view' => true,
        );
 
-       return elgg_view('annotation/list', $params);
+       return elgg_view('layout/objects/list', $params);
 }
 
 /**
@@ -943,19 +945,35 @@ function elgg_view_comments($entity, $add_comment = true) {
                        'entity' => $entity,
                        'show_add_form' => $add_comment,
                );
-               $comments = elgg_view('comments/list', $params);
-       /*
-               $comments = list_annotations($entity->getGUID(), 'generic_comment');
+               $output = elgg_view('layout/elements/comments', $params);
 
-               //display the new comment form if required
-               if ($add_comment) {
-                       $comments .= elgg_view('comments/forms/edit', array('entity' => $entity));
-               }
-*/
-               return $comments;
+               return $output;
        }
 }
 
+/**
+ * View the latest comments on a user's content
+ *
+ * @todo - get_annotations is due to be rewritten so update code and possibly parameters
+ *
+ * @param <type> $owner_guid
+ * @param <type> $type
+ * @param <type> $subtype
+ * @param <type> $number
+ *
+ * @return string
+ * @since 1.8.0
+ */
+function elgg_view_latest_comments($owner_guid, $type = 'object', $subtype = '', $number = 4) {
+       $title = elgg_echo('generic_comments:latest');
+       $comments = get_annotations(0, $type, $subtype, "generic_comment", "", $owner_guid, 4, 0, "desc");
+       $body = elgg_view('layout/objects/list', array(
+               'items' => $comments,
+               'pagination' => false,
+               'list_class' => 'elgg-latest-comments',
+       ));
+       echo elgg_view('layout/objects/module', array('title' => $title, 'body' => $body));
+}
 /**
  * Wrapper function for the media display pattern.
  *
@@ -988,7 +1006,7 @@ function elgg_view_media($icon, $body, $vars = array()) {
  */
 function elgg_view_listing($icon, $info) {
        elgg_deprecated_notice('elgg_view_listing deprecated by elgg_view_media', 1.8);
-       return elgg_view('entities/entity_listing', array('icon' => $icon, 'info' => $info));
+       return elgg_view('layout/objects/media', array('icon' => $icon, 'body' => $info));
 }
 
 /**
@@ -1032,6 +1050,25 @@ function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
        return elgg_view('input/form', array_merge($defaults, $form_vars));
 }
 
+/**
+ * View an item in a list
+ *
+ * @param object $item      ElggEntity or ElggAnnotation
+ * @param bool   $full_view Whether to render the full view of the object
+ * @param array  $vars      Additional parameters for the rendering
+ *
+ * @return string
+ * @since 1.8.0
+ * @access private
+ */
+function elgg_view_list_item($item, $full_view, $vars) {
+       if (elgg_instanceof($item)) {
+               return elgg_view_entity($item, $full_view);
+       } else {
+               return elgg_view_annotation($item, $full_view);
+       }
+}
+
 /**
  * Registers a function to handle templates.
  *
index 3d343d80e8fe6d7a385c731e1fbc12b8ae42f391..7dfbeb1bc9f29c06a64d9600cab7b6e5901f9423 100644 (file)
@@ -28,10 +28,7 @@ $page_owner = elgg_get_page_owner();
 echo elgg_view("blogs/sidebar", array("object_type" => 'blog'));
 
 // fetch & display latest comments on all blog posts
-$comments = get_annotations(0, "object", "blog", "generic_comment", "", 0, 4, 0, "desc");
-$title = elgg_echo('generic_comments:latest');
-$body = elgg_view('comments/latest', array('comments' => $comments));
-echo elgg_view('layout/objects/module', array('title' => $title, 'body' => $body));
+echo elgg_view_latest_comments(0, 'object', 'blog');
 
 // only show archives for users or groups.
 // This is a limitation of the URL schema.
index 63633d3b5700f4c86317c34af1d02b0a7ba51d78..c6fea8b41cd91db41838be1486bd6c398c9f450c 100644 (file)
@@ -53,7 +53,7 @@ if ($full_view) {
 </p>
 HTML;
 
-       echo elgg_view_media($commenter_icon, $body, array('id' => "comment-$comment->id"));
+       echo elgg_view_media($commenter_icon, $body);
 
 } else {
        // brief view
diff --git a/views/default/annotation/list.php b/views/default/annotation/list.php
deleted file mode 100644 (file)
index f432ad6..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/**
- * Annotation list
- *
- * @uses $vars['annotations']
- * @uses $vars['limit']
- * @uses $vars['offset']
- * @uses $vars['count']
- * @uses $vars['pagination']
- */
-
-$offset = $vars['offset'];
-$limit = $vars['limit'];
-$count = $vars['count'];
-$annotations = $vars['annotations'];
-$pagination = elgg_get_array_value('pagination', $vars, true);
-
-$html = "";
-$nav = "";
-
-if ($pagination) {
-       $nav .= elgg_view('navigation/pagination', array(
-               'baseurl' => $_SERVER['REQUEST_URI'],
-               'offset' => $offset,
-               'count' => $count,
-               'limit' => $limit,
-               'word' => 'annoff',
-               'nonefound' => false,
-       ));
-}
-
-if (is_array($annotations) && count($annotations) > 0) {
-       $html .= '<ul class="elgg-annotation-list elgg-list">';
-       foreach ($annotations as $annotation) {
-                       $html .= '<li>';
-                       $html .= elgg_view_annotation($annotation, true);
-                       $html .= '</li>';
-       }
-       $html .= '</ul>';
-}
-
-if ($count) {
-       $html .= $nav;
-}
-
-echo $html;
diff --git a/views/default/layout/objects/list.php b/views/default/layout/objects/list.php
new file mode 100644 (file)
index 0000000..b65e791
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+/**
+ * View a list of items
+ *
+ * @package Elgg
+ *
+ * @uses $vars['items']       Array of ElggEntity or ElggAnnotation objects
+ * @uses $vars['offset']      Index of the first list item in complete list
+ * @uses $vars['limit']       Number of items per page
+ * @uses $vars['count']       Number of items in the complete list
+ * @uses $vars['base_url']    Base URL of list (optional)
+ * @uses $vars['pagination']  Show pagination? (default: true)
+ * @uses $vars['full_view']   Show the full view of the items (default: false)
+ * @uses $vars['list_class']  Additional CSS class for the <ul> element
+ * @uses $vars['item_class']  Additional CSS class for the <li> elements
+ */
+
+$items = $vars['items'];
+$offset = $vars['offset'];
+$limit = $vars['limit'];
+$count = $vars['count'];
+$base_url = $vars['base_url'];
+$pagination = elgg_get_array_value('pagination', $vars, true);
+$full_view = elgg_get_array_value('full_view', $vars, false);
+
+$list_class = 'elgg-list';
+if (isset($vars['list_class'])) {
+       $list_class = "{$vars['list_class']} $list_class";
+}
+
+$item_class = 'elgg-list-item';
+if (isset($vars['item_class'])) {
+       $item_class = "{$vars['item_class']} $item_class";
+}
+
+$html = "";
+$nav = "";
+
+if ($pagination) {
+       $nav .= elgg_view('navigation/pagination', array(
+               'baseurl' => $base_url,
+               'offset' => $offset,
+               'count' => $count,
+               'limit' => $limit,
+       ));
+}
+
+if (is_array($items) && count($items) > 0) {
+       $html .= "<ul class=\"$list_class\">";
+       foreach ($items as $item) {
+               if (elgg_instanceof($item)) {
+                       $id = "item-{$item->getGUID()}";
+               } else {
+                       $id = "item-{$item->id}";
+               }
+               $html .= "<li id=\"$id\" class=\"$item_class\">";
+               $html .= elgg_view_list_item($item, $full_view);
+               $html .= '</li>';
+       }
+       $html .= '</ul>';
+}
+
+if ($count) {
+       $html .= $nav;
+}
+
+echo $html;