add recent tags action
authorChuck Hagenbuch <chuck@horde.org>
Tue, 20 Jan 2009 04:09:45 +0000 (23:09 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 20 Jan 2009 05:20:39 +0000 (00:20 -0500)
content/app/controllers/TagController.php
content/app/views/Tag/recentTags.html.php [new file with mode: 0644]
content/app/views/Tag/searchTags.html.php
content/config/routes.php

index 0e14c1e..ce4764c 100644 (file)
@@ -12,39 +12,51 @@ class TagController extends Content_ApplicationController
      */
     public function searchTags()
     {
-        $this->tags = $this->tagger->getTags(array(
+        $this->results = $this->tagger->getTags(array(
             'q' => $this->params->q,
             'typeId' => $this->params->typeId,
             'userId' => $this->params->userId,
             'objectId' => $this->params->objectId,
         ));
 
-        switch ((string)$this->_request->getFormat()) {
-        case 'html':
-            $this->render();
-            break;
+        $this->_render();
+    }
 
-        case 'json':
-        default:
-            $this->renderText(json_encode($this->tags));
-            break;
-        }
+    /**
+     */
+    public function recentTags()
+    {
+        $this->results = $this->tagger->getRecentTags(array(
+            'limit' => 10,
+            'typeId' => $this->params->typeId,
+            'objectId' => $this->params->objectId,
+        ));
+
+        $this->_render();
     }
 
     public function searchUsers()
     {
     }
 
+    public function recentUsers()
+    {
+    }
+
     public function searchObjects()
     {
     }
 
+    public function recentObjects()
+    {
+    }
+
     /**
      * Add a tag
      */
     public function tag()
     {
-        // Enforce POST only
+        // Routes enforce POST or PUT only, but double-check here.
     }
 
     /**
@@ -52,7 +64,22 @@ class TagController extends Content_ApplicationController
      */
     public function untag()
     {
-        // Enforce POST only
+        // Routes enforce POST or DELETE only, but double-check here.
+    }
+
+
+    protected function _render()
+    {
+        switch ((string)$this->_request->getFormat()) {
+        case 'html':
+            $this->render();
+            break;
+
+        case 'json':
+        default:
+            $this->renderText(json_encode($this->results));
+            break;
+        }
     }
 
 }
diff --git a/content/app/views/Tag/recentTags.html.php b/content/app/views/Tag/recentTags.html.php
new file mode 100644 (file)
index 0000000..d069cec
--- /dev/null
@@ -0,0 +1,5 @@
+<ul>
+<?php foreach ($this->results as $tag): ?>
+ <li value="<?= $this->escape($tag['tag_id']) ?>" created="<?= $this->escape($tag['created']) ?>"><?= $this->escape($tag['tag_name']) ?></li>
+<?php endforeach ?>
+</ul>
index 1fa37e0..5aeaf2e 100644 (file)
@@ -1,5 +1,5 @@
 <ul>
-<?php foreach ($this->tags as $tag_id => $tag_text): ?>
- <li value="<?= $this->escape($tag_id) ?>"><?= $this->escape($tag_text) ?></li>
+<?php foreach ($this->results as $tag_id => $tag_name): ?>
+ <li value="<?= $this->escape($tag_id) ?>"><?= $this->escape($tag_name) ?></li>
 <?php endforeach ?>
 </ul>
index 5d08243..1356835 100644 (file)
 $mapper->connect('tags', array('controller' => 'tag', 'action' => 'searchTags'));
 $mapper->connect('tags.:(format)', array('controller' => 'tag', 'action' => 'searchTags'));
 
+// Most recent tags. Available query parameters:
+//   typeId:    restrict matches to tags that have been applied to objects with type $typeId
+//   userId:    restrict matches to tags that have been applied by $userId
+$mapper->connect('tags/recent', array('controller' => 'tag', 'action' => 'recentTags'));
+$mapper->connect('tags/recent.:(format)', array('controller' => 'tag', 'action' => 'recentTags'));
+
 // List objects. At least a content type, or more specific parameters, are
 // required; listing all objects is not allowed.
 $mapper->connect('objects', array('controller' => 'tag', 'action' => 'searchObjects'));