summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-15 08:44:01 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-15 08:44:01 +0000
commitdb6061096e23e77c4ea895fa3c1bd20d65c6db4c (patch)
tree68e7becf15c9419e4d712b846d627ebbe118d6fd /core
parent6dbf5ae172e8336caa0971024ffdfa0148bcf718 (diff)
Item / Owner changes.
* Hardcode the item has_one owner relationship again * Overload User_Model::__get to handle missing owners gracefully * Fix Item_Controller to take the owner_id from the session or from the parent album when adding new albums and photos.
Diffstat (limited to 'core')
-rw-r--r--core/controllers/item.php21
-rw-r--r--core/models/item.php17
2 files changed, 17 insertions, 21 deletions
diff --git a/core/controllers/item.php b/core/controllers/item.php
index 8bed14b4..e9ff03e6 100644
--- a/core/controllers/item.php
+++ b/core/controllers/item.php
@@ -32,28 +32,22 @@ class Item_Controller extends REST_Controller {
// 1) Add security checks
// 2) Support owner_ids properly
+ $user = Session::instance()->get("user");
+ $owner_id = $user ? $user->id : $item->owner_id;
+
switch ($this->input->post("type")) {
case "album":
$album = album::create(
$item->id,
$this->input->post("name"),
$this->input->post("title", $this->input->post("name")),
- $this->input->post("description"));
+ $this->input->post("description"),
+ $owner_id);
url::redirect("album/{$album->id}");
break;
case "photo":
if (is_array($_FILES["file"]["name"])) {
- $user = Session::instance()->get('user');
- if ($user) {
- $user_id = $user->id;
- } else {
- try {
- $user_id = ORM::factory("user")->find()->id;
- } catch (Exception $e) {
- $user_id = null;
- }
- }
for ($i = 0; $i < count($_FILES["file"]["name"]) - 1; $i++) {
if ($_FILES["file"]["error"][$i] == 0) {
$photo = photo::create(
@@ -61,7 +55,7 @@ class Item_Controller extends REST_Controller {
$_FILES["file"]["tmp_name"][$i],
$_FILES["file"]["name"][$i],
$_FILES["file"]["name"][$i],
- '', $user_id);
+ "", $owner_id);
} else {
// @todo return a reasonable error
throw new Exception("@todo ERROR_IN_UPLOAD_FILE");
@@ -74,7 +68,8 @@ class Item_Controller extends REST_Controller {
$_FILES["file"]["tmp_name"],
$_FILES["file"]["name"],
$this->input->post("title", $this->input->post("name")),
- $this->input->post("description"));
+ $this->input->post("description"),
+ $owner_id);
url::redirect("{$new_item->type}/{$new_item->id}");
}
break;
diff --git a/core/models/item.php b/core/models/item.php
index b592b706..485975cb 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -19,14 +19,7 @@
*/
class Item_Model extends ORM_MPTT {
protected $children = 'items';
-
- function __construct($id) {
- parent::__construct($id);
- $module = ORM::factory("module")->where("name", 'user')->find();
- if ($module->loaded) {
- $this->has_one = array('owner' => 'user');
- }
- }
+ protected $has_one = array("owner" => "user");
/**
* Is this item an album?
@@ -182,6 +175,14 @@ class Item_Model extends ORM_MPTT {
$real_column = substr($column, 0, strlen($column) - 5);
return "<span class=\"gInPlaceEdit gEditField-{$this->id}-{$real_column}\">" .
"{$this->$real_column}</span>";
+ } else if ($column == "owner") {
+ // This relationship depends on an outside module, which may not be present so handle
+ // failures gracefully.
+ try {
+ return parent::__get($column);
+ } catch (Exception $e) {
+ return null;
+ }
} else {
return parent::__get($column);
}