Clean user / item relationship. Upload files gets the ownership of current user; and the views don't break if user module is not installed

This commit is contained in:
Felix Rabinovich
2008-11-15 08:19:14 +00:00
parent dc1090d005
commit 6dbf5ae172
3 changed files with 26 additions and 6 deletions
+13 -2
View File
@@ -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");