diff options
author | Felix Rabinovich <virshu@users.sourceforge.net> | 2008-11-15 08:19:14 +0000 |
---|---|---|
committer | Felix Rabinovich <virshu@users.sourceforge.net> | 2008-11-15 08:19:14 +0000 |
commit | 6dbf5ae172e8336caa0971024ffdfa0148bcf718 (patch) | |
tree | 9d8f8d00ab4539a242e4865d8b610fd59920b738 /core/controllers | |
parent | dc1090d005d4d565e2989dee94be3fcc1a6190a7 (diff) |
Clean user / item relationship. Upload files gets the ownership of current user; and the views don't break if user module is not installed
Diffstat (limited to 'core/controllers')
-rw-r--r-- | core/controllers/item.php | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/core/controllers/item.php b/core/controllers/item.php index 78ee7b0b..8bed14b4 100644 --- a/core/controllers/item.php +++ b/core/controllers/item.php @@ -44,13 +44,24 @@ class Item_Controller extends REST_Controller { case "photo": if (is_array($_FILES["file"]["name"])) { - for ($i = 0; $i < count($_FILES["file"]["name"]); $i++) { + $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( $item->id, $_FILES["file"]["tmp_name"][$i], $_FILES["file"]["name"][$i], - $_FILES["file"]["name"][$i]); + $_FILES["file"]["name"][$i], + '', $user_id); } else { // @todo return a reasonable error throw new Exception("@todo ERROR_IN_UPLOAD_FILE"); |