Add friends activity block
authorDuck (Jakob Munih) <duck@obala.net>
Wed, 25 Feb 2009 11:17:48 +0000 (12:17 +0100)
committerDuck (Jakob Munih) <duck@obala.net>
Wed, 25 Feb 2009 11:17:48 +0000 (12:17 +0100)
folks/lib/Block/activities.php [new file with mode: 0644]
folks/templates/block/activities.php [new file with mode: 0644]

diff --git a/folks/lib/Block/activities.php b/folks/lib/Block/activities.php
new file mode 100644 (file)
index 0000000..03295f6
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+
+$block_name = _("Friends activities");
+
+/**
+ * $Id: friends.php 1019 2008-10-31 08:18:10Z duck $
+ *
+ * @package Folks
+ * @author Duck <duck@obala.net>
+ */
+class Horde_Block_Folks_activities extends Horde_Block {
+
+    var $_app = 'folks';
+
+    /**
+     * The title to go in this block.
+     *
+     * @return string   The title text.
+     */
+    function _title()
+    {
+        return _("Friends activities");
+    }
+
+    /**
+     * The parameters of block
+     *
+     * @return array   The parameters
+     */
+    function _params()
+    {
+        return array('limit' => array('name' => _("Number of activities to display"),
+                                    'type' => 'int',
+                                    'default' => 10));
+    }
+
+    /**
+     * The content to go in this block.
+     *
+     * @return string   The content
+     */
+    function _content()
+    {
+        require_once dirname(__FILE__) . '/../base.php';
+        require_once FOLKS_BASE . '/lib/Friends.php';
+
+        $friends_driver = Folks_Friends::singleton();
+        $friend_list = $friends_driver->getFriends();
+        if ($friend_list instanceof PEAR_Error) {
+            return $friend_list;
+        }
+
+        // Get friends activities
+        $list = array();
+        foreach ($friend_list as $user) {
+            $activities = $GLOBALS['folks_driver']->getActivity($user);
+            if ($activities instanceof PEAR_Error) {
+                return $activities;
+            }
+            foreach ($activities as $activity) {
+                $list[$activity['activity_date']] = $activity;
+            }
+        }
+        krsort($list);
+        $list = array_slice($list, 0, $this->_params['limit']);
+
+        Horde::addScriptFile('stripe.js', 'horde', true);
+
+        ob_start();
+        require FOLKS_TEMPLATES . '/block/activities.php';
+        return ob_get_clean();
+    }
+}
\ No newline at end of file
diff --git a/folks/templates/block/activities.php b/folks/templates/block/activities.php
new file mode 100644 (file)
index 0000000..9599393
--- /dev/null
@@ -0,0 +1,14 @@
+<table id="activities" class="striped"  style="width: 100%">
+<tbody>
+<?php
+foreach ($list as $activity_date => $activity) {
+    echo '<tr>'
+            . '<td><a href="' . Folks::getUrlFor('user', $activity['user_uid']) . '">'
+            . '<img src="' . Folks::getImageUrl($activity['user_uid']) . '" class="userMiniIcon" style="float: left" /> '
+            . $activity['user_uid'] . '</a> - <span class="small">' . Folks::format_datetime($activity_date) . '</span>' . '<br />'
+            . $activity['activity_message'] . '<br />'
+            . '</td></tr>';
+}
+?>
+</tbody>
+</table>