summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-22 09:43:02 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-22 09:43:02 -0800
commiteea27c39f1cc7edb9ad0f9682bedfb2770661a7f (patch)
treee75974ba001fbaf1e71b534c23fc68a0b60e90dd /modules
parente56318d07fe3cabcace5c4597c660260f80a0e00 (diff)
Create symmetrical relationship collections: item_tags and tag_items
Now when we represent a relationship collection we can refer to it in proper semantic terms.
Diffstat (limited to 'modules')
-rw-r--r--modules/tag/helpers/item_tags_rest.php51
-rw-r--r--modules/tag/helpers/tag_items_rest.php48
-rw-r--r--modules/tag/helpers/tag_rest.php6
3 files changed, 104 insertions, 1 deletions
diff --git a/modules/tag/helpers/item_tags_rest.php b/modules/tag/helpers/item_tags_rest.php
new file mode 100644
index 00000000..385d06e8
--- /dev/null
+++ b/modules/tag/helpers/item_tags_rest.php
@@ -0,0 +1,51 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class item_tags_rest_Core {
+ static function get($request) {
+ $item = rest::resolve($request->url);
+ $tags = array();
+ foreach (tag::item_tags($item) as $tag) {
+ $tags[] = rest::url("tag_item", $tag, $item);
+ }
+
+ return array(
+ "url" => $request->url,
+ "members" => $tags);
+ }
+
+ static function delete($request) {
+ list ($tag, $item) = rest::resolve($request->url);
+ $tag->remove($item);
+ $tag->save();
+ }
+
+ static function resolve($id) {
+ $item = ORM::factory("item")->where("id", "=", $id)->find();
+ if (!access::can("view", $item)) {
+ throw new Kohana_404_Exception();
+ }
+
+ return $item;
+ }
+
+ static function url($item) {
+ return url::abs_site("rest/item_tags/{$item->id}");
+ }
+}
diff --git a/modules/tag/helpers/tag_items_rest.php b/modules/tag/helpers/tag_items_rest.php
new file mode 100644
index 00000000..2a00c565
--- /dev/null
+++ b/modules/tag/helpers/tag_items_rest.php
@@ -0,0 +1,48 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class tag_items_rest_Core {
+ static function get($request) {
+ $tag = rest::resolve($request->url);
+ $items = array();
+ foreach ($tag->items() as $item) {
+ if (access::can("view", $item)) {
+ $items[] = rest::url("tag_item", $tag, $item);
+ }
+ }
+
+ return array(
+ "url" => $request->url,
+ "members" => $items);
+ }
+
+ static function delete($request) {
+ list ($tag, $item) = rest::resolve($request->url);
+ $tag->remove($item);
+ $tag->save();
+ }
+
+ static function resolve($id) {
+ return ORM::factory("tag")->where("id", "=", $id)->find();
+ }
+
+ static function url($tag) {
+ return url::abs_site("rest/tag_items/{$tag->id}");
+ }
+}
diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php
index 5feeb756..4fe9bef9 100644
--- a/modules/tag/helpers/tag_rest.php
+++ b/modules/tag/helpers/tag_rest.php
@@ -31,6 +31,7 @@ class tag_rest_Core {
"url" => $request->url,
"resource" => $tag->as_array(),
"relationships" => array(
+ "url" => rest::url("tag_items", $tag),
"items" => $tag_items));
}
@@ -67,7 +68,10 @@ class tag_rest_Core {
foreach (tag::item_tags($resource) as $tag) {
$tags[] = rest::url("tag_item", $tag, $resource);
}
- return array("tags" => $tags);
+ return array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $resource),
+ "members" => $tags));
}
}