本文整理汇总了PHP中item::get_position方法的典型用法代码示例。如果您正苦于以下问题:PHP item::get_position方法的具体用法?PHP item::get_position怎么用?PHP item::get_position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::get_position方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_display_context
static function get_display_context($item)
{
$where = array(array("type", "!=", "album"));
$position = item::get_position($item, $where);
if ($position > 1) {
list($previous_item, $ignore, $next_item) = $item->parent()->viewable()->children(3, $position - 2, $where);
} else {
$previous_item = null;
list($next_item) = $item->parent()->viewable()->children(1, $position, $where);
}
return array("position" => $position, "previous_item" => $previous_item, "next_item" => $next_item, "sibling_count" => $item->parent()->viewable()->children_count($where), "siblings_callback" => array("Albums_Controller::get_siblings", array($item)), "parents" => $item->parents()->as_array(), "breadcrumbs" => Breadcrumb::array_from_item_parents($item));
}
示例2: show
public function show($album)
{
if (!is_object($album)) {
// show() must be public because we route to it in url::parse_url(), so make
// sure that we're actually receiving an object
throw new Kohana_404_Exception();
}
access::required("view", $album);
$page_size = module::get_var("gallery", "page_size", 9);
$input = Input::instance();
$show = $input->get("show");
if ($show) {
$child = ORM::factory("item", $show);
$index = item::get_position($child);
if ($index) {
$page = ceil($index / $page_size);
if ($page == 1) {
url::redirect($album->abs_url());
} else {
url::redirect($album->abs_url("page={$page}"));
}
}
}
$page = $input->get("page", "1");
$children_count = $album->viewable()->children_count();
$offset = ($page - 1) * $page_size;
$max_pages = max(ceil($children_count / $page_size), 1);
// Make sure that the page references a valid offset
if ($page < 1) {
url::redirect($album->abs_url());
} else {
if ($page > $max_pages) {
url::redirect($album->abs_url("page={$max_pages}"));
}
}
$template = new Theme_View("page.html", "collection", "album");
$template->set_global(array("page" => $page, "page_title" => null, "max_pages" => $max_pages, "page_size" => $page_size, "item" => $album, "children" => $album->viewable()->children($page_size, $offset), "parents" => $album->parents()->as_array(), "children_count" => $children_count));
$template->content = new View("album.html");
$album->increment_view_count();
print $template;
}
示例3: show
public function show($photo)
{
if (!is_object($photo)) {
// show() must be public because we route to it in url::parse_url(), so make
// sure that we're actually receiving an object
throw new Kohana_404_Exception();
}
access::required("view", $photo);
$where = array(array("type", "!=", "album"));
$position = item::get_position($photo, $where);
if ($position > 1) {
list($previous_item, $ignore, $next_item) = $photo->parent()->viewable()->children(3, $position - 2, $where);
} else {
$previous_item = null;
list($next_item) = $photo->parent()->viewable()->children(1, $position, $where);
}
$template = new Theme_View("page.html", "item", "photo");
$template->set_global(array("item" => $photo, "children" => array(), "children_count" => 0, "parents" => $photo->parents()->as_array(), "next_item" => $next_item, "previous_item" => $previous_item, "sibling_count" => $photo->parent()->viewable()->children_count($where), "position" => $position));
$template->content = new View("photo.html");
$photo->increment_view_count();
print $template;
}
示例4: get_position
/**
* Find the position of the given child id in this album. The resulting value is 1-indexed, so
* the first child in the album is at position 1.
*
* This method stands as a backward compatibility for gallery 3.0, and will
* be deprecated in version 3.1.
*/
public function get_position($child, $where = array())
{
return item::get_position($child, $where);
}
示例5: delete
public function delete($id)
{
access::verify_csrf();
$item = model_cache::get("item", $id);
access::required("view", $item);
access::required("edit", $item);
if ($item->is_album()) {
$msg = t("Deleted album <b>%title</b>", array("title" => html::purify($item->title)));
} else {
$msg = t("Deleted photo <b>%title</b>", array("title" => html::purify($item->title)));
}
$redirect = $item->parent();
// redirect to this item, if current item was deleted
if ($item->is_album()) {
// Album delete will trigger deletes for all children. Do this in a batch so that we can be
// smart about notifications, album cover updates, etc.
batch::start();
$item->delete();
batch::stop();
} else {
$where = array(array("type", "!=", "album"));
// evaluate redirect item before delete of current item
$position = item::get_position($item, $where);
if ($position > 1) {
list($previous_item, $ignore, $next_item) = $item->parent()->viewable()->children(3, $position - 2, $where);
} else {
$previous_item = null;
list($next_item) = $item->parent()->viewable()->children(1, $position, $where);
}
if ($next_item) {
$redirect = $next_item;
} else {
if ($previous_item) {
$redirect = $previous_item;
}
}
$item->delete();
}
message::success($msg);
$from_id = Input::instance()->get("from_id");
if (Input::instance()->get("page_type") == "collection" && $from_id != $id) {
json::reply(array("result" => "success", "reload" => 1));
} else {
json::reply(array("result" => "success", "location" => $redirect->url()));
}
}