mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-08-04 22:20:57 -04:00
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:
@@ -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");
|
||||
|
||||
@@ -19,7 +19,14 @@
|
||||
*/
|
||||
class Item_Model extends ORM_MPTT {
|
||||
protected $children = 'items';
|
||||
protected $has_one = array('owner' => 'user');
|
||||
|
||||
function __construct($id) {
|
||||
parent::__construct($id);
|
||||
$module = ORM::factory("module")->where("name", 'user')->find();
|
||||
if ($module->loaded) {
|
||||
$this->has_one = array('owner' => 'user');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this item an album?
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
<h2><?= $child->title_edit ?></h2>
|
||||
<ul class="gMetadata">
|
||||
<li>Views: 321</li>
|
||||
<? if ($child->owner): ?>
|
||||
<li><?= _("By: ") ?><a href="#"><?= $child->owner->name ?></a></li>
|
||||
<? endif ?>
|
||||
<?
|
||||
try {
|
||||
echo "<li>" . _("By: ") . '<a href="#">' . $child->owner->name . "</a></li>";
|
||||
} catch(Exception $e) {}
|
||||
?>
|
||||
</ul>
|
||||
</li>
|
||||
<? endforeach ?>
|
||||
|
||||
Reference in New Issue
Block a user