2008-11-05 07:42:52 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
|
|
|
|
* Copyright (C) 2000-2008 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.
|
|
|
|
|
*/
|
2008-11-19 00:12:25 +00:00
|
|
|
class Photos_Controller extends Items_Controller {
|
2008-11-11 06:18:45 +00:00
|
|
|
|
2008-11-16 07:14:12 +00:00
|
|
|
/**
|
2008-12-25 02:38:53 +00:00
|
|
|
* @see REST_Controller::_show($resource)
|
2008-11-16 07:14:12 +00:00
|
|
|
*/
|
2008-12-24 00:20:26 +00:00
|
|
|
public function _show($photo) {
|
|
|
|
|
access::required("view", $photo);
|
2008-12-09 10:14:09 +00:00
|
|
|
|
2008-12-31 07:06:10 +00:00
|
|
|
// We sort by id ascending so for now, find sibling info by doing id based queries.
|
|
|
|
|
$next_item = ORM::factory("item")
|
|
|
|
|
->viewable()
|
|
|
|
|
->where("parent_id", $photo->parent_id)
|
|
|
|
|
->where("id >", $photo->id)
|
|
|
|
|
->orderby("id", "ASC")
|
|
|
|
|
->find();
|
|
|
|
|
$previous_item = ORM::factory("item")
|
|
|
|
|
->viewable()
|
|
|
|
|
->where("parent_id", $photo->parent_id)
|
|
|
|
|
->where("id <", $photo->id)
|
|
|
|
|
->orderby("id", "DESC")
|
|
|
|
|
->find();
|
|
|
|
|
$position = ORM::factory("item")
|
|
|
|
|
->viewable()
|
|
|
|
|
->where("parent_id", $photo->parent_id)
|
|
|
|
|
->where("id <=", $photo->id)
|
|
|
|
|
->count_all();
|
|
|
|
|
|
2008-12-24 04:22:22 +00:00
|
|
|
$template = new Theme_View("page.html", "photo");
|
2008-12-31 06:44:38 +00:00
|
|
|
$template->set_global("item", $photo);
|
|
|
|
|
$template->set_global("children", array());
|
|
|
|
|
$template->set_global("children_count", $photo->children_count());
|
|
|
|
|
$template->set_global("parents", $photo->parents());
|
2008-12-31 07:22:35 +00:00
|
|
|
$template->set_global("next_item", $next_item->loaded ? $next_item : null);
|
|
|
|
|
$template->set_global("previous_item", $previous_item->loaded ? $previous_item : null);
|
2008-12-31 07:06:10 +00:00
|
|
|
$template->set_global("sibling_count", $photo->parent()->children_count());
|
|
|
|
|
$template->set_global("position", $position);
|
2008-11-27 16:19:07 +00:00
|
|
|
|
2008-11-09 19:20:23 +00:00
|
|
|
$template->content = new View("photo.html");
|
2008-12-20 20:04:57 +00:00
|
|
|
|
2008-12-24 00:20:26 +00:00
|
|
|
$photo->view_count++;
|
|
|
|
|
$photo->save();
|
2008-12-20 20:11:51 +00:00
|
|
|
|
|
|
|
|
print $template;
|
2008-11-05 07:42:52 +00:00
|
|
|
}
|
2008-12-06 21:14:36 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-12-25 02:38:53 +00:00
|
|
|
* @see REST_Controller::_update($resource)
|
2008-12-06 21:14:36 +00:00
|
|
|
*/
|
2008-12-24 00:20:26 +00:00
|
|
|
public function _update($photo) {
|
|
|
|
|
access::required("edit", $photo);
|
|
|
|
|
|
|
|
|
|
$form = photo::get_edit_form($photo);
|
|
|
|
|
if ($form->validate()) {
|
|
|
|
|
// @todo implement changing the name. This is not trivial, we have
|
|
|
|
|
// to check for conflicts and rename the album itself, etc. Needs an
|
|
|
|
|
// api method.
|
2009-01-08 02:39:21 +00:00
|
|
|
$orig = clone $photo;
|
2008-12-24 00:20:26 +00:00
|
|
|
$photo->title = $form->edit_photo->title->value;
|
|
|
|
|
$photo->description = $form->edit_photo->description->value;
|
|
|
|
|
$photo->save();
|
|
|
|
|
|
2009-01-15 02:52:42 +00:00
|
|
|
module::event("item_updated", $orig, $photo);
|
2008-12-06 21:14:36 +00:00
|
|
|
|
2008-12-25 23:43:44 +00:00
|
|
|
log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>");
|
2009-01-15 10:02:41 +00:00
|
|
|
message::success(t("Saved photo %photo_title", array("photo_title" => $photo->title)));
|
2008-12-24 00:20:26 +00:00
|
|
|
|
2008-12-25 05:12:46 +00:00
|
|
|
print json_encode(
|
|
|
|
|
array("result" => "success",
|
|
|
|
|
"location" => url::site("photos/$photo->id")));
|
2008-12-24 00:20:26 +00:00
|
|
|
} else {
|
2008-12-25 05:12:46 +00:00
|
|
|
print json_encode(
|
|
|
|
|
array("result" => "error",
|
|
|
|
|
"form" => $form->__toString()));
|
2008-12-24 00:20:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-25 02:38:53 +00:00
|
|
|
* @see REST_Controller::_form_edit($resource)
|
2008-12-24 00:20:26 +00:00
|
|
|
*/
|
|
|
|
|
public function _form_edit($photo) {
|
|
|
|
|
access::required("edit", $photo);
|
|
|
|
|
print photo::get_edit_form($photo);
|
2008-12-06 21:14:36 +00:00
|
|
|
}
|
2008-11-05 07:42:52 +00:00
|
|
|
}
|