*/
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.
}
/**
*/
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;
+ }
}
}
<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>
$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'));