当前位置: 首页>>代码示例>>PHP>>正文


PHP item::random_query方法代码示例

本文整理汇总了PHP中item::random_query方法的典型用法代码示例。如果您正苦于以下问题:PHP item::random_query方法的具体用法?PHP item::random_query怎么用?PHP item::random_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在item的用法示例。


在下文中一共展示了item::random_query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 /**
  * For items that are collections, you can specify the following additional query parameters to
  * query the collection.  You can specify them in any combination.
  *
  *   scope=direct
  *     only return items that are immediately under this one
  *   scope=all
  *     return items anywhere under this one
  *
  *   name=<substring>
  *     only return items where the name contains this substring
  *
  *   random=true
  *     return a single random item
  *
  *   type=<comma separate list of photo, movie or album>
  *     limit the type to types in this list.  eg, "type=photo,movie"
  */
 static function get($request)
 {
     $item = rest::resolve($request->url);
     access::required("view", $item);
     $p = $request->params;
     if (isset($p->random)) {
         $orm = item::random_query()->offset(0)->limit(1);
     } else {
         $orm = ORM::factory("item")->viewable();
     }
     if (empty($p->scope)) {
         $p->scope = "direct";
     }
     if (!in_array($p->scope, array("direct", "all"))) {
         throw new Rest_Exception("Bad Request", 400);
     }
     if ($p->scope == "direct") {
         $orm->where("parent_id", "=", $item->id);
     } else {
         $orm->where("left_ptr", ">", $item->left_ptr);
         $orm->where("right_ptr", "<", $item->right_ptr);
     }
     if (isset($p->name)) {
         $orm->where("name", "LIKE", "%{$p->name}%");
     }
     if (isset($p->type)) {
         $orm->where("type", "IN", explode(",", $p->type));
     }
     $members = array();
     foreach ($orm->find_all() as $child) {
         $members[] = rest::url("item", $child);
     }
     return array("url" => $request->url, "entity" => $item->as_array(), "members" => $members, "relationships" => rest::relationships("item", $item));
 }
开发者ID:joericochuyt,项目名称:gallery3,代码行数:52,代码来源:item_rest.php

示例2: get

 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "random_image":
             // The random_query approach is flawed and doesn't always return a
             // result when there actually is one. Retry a *few* times.
             // @todo Consider another fallback if further optimizations are necessary.
             $image_count = module::get_var("image_block", "image_count");
             $items = array();
             for ($i = 0; $i < $image_count; $i++) {
                 $attempts = 0;
                 $item = null;
                 do {
                     $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current();
                 } while (!$item && $attempts++ < 3);
                 if ($item) {
                     $items[] = $item;
                 }
             }
             if ($items) {
                 $block = new Block();
                 $block->css_id = "g-image-block";
                 $block->title = t2("Random image", "Random images", $image_count);
                 $block->content = new View("image_block_block.html");
                 $block->content->items = $items;
             }
             break;
     }
     return $block;
 }
开发者ID:Joe7,项目名称:gallery3,代码行数:31,代码来源:image_block_block.php

示例3: get

 static function get($block_id, $theme)
 {
     if (identity::active_user()->guest) {
         return;
     }
     $block = "";
     switch ($block_id) {
         case "untagged_photo":
             $attempts = 0;
             do {
                 $item = item::random_query()->join("items_tags", "items.id", "items_tags.item_id", "left")->where("items.type", "!=", "album")->where("items_tags.item_id", "IS", null)->find_all(1)->current();
             } while (!$item && $attempts++ < 3);
             if ($item && $item->loaded()) {
                 $block = new Block();
                 $block->css_id = "g-tag-it-block";
                 $block->title = t("Tag it");
                 $block->content = new View("tag_it_block.html");
                 $block->content->item = $item;
                 $form = new Forge("tags/create/{$item->id}", "", "post", array("id" => "g-tag-it-add-tag-form", "class" => "g-short-form"));
                 $label = $item->is_album() ? t("Add tag to album") : ($item->is_photo() ? t("Add tag to photo") : t("Add tag to movie"));
                 $group = $form->group("add_tag")->label("Add Tag");
                 $group->input("name")->label($label)->rules("required")->id("name");
                 $group->hidden("item_id")->value($item->id);
                 $group->submit("")->value(t("Add Tag"));
                 $block->content->form = $form;
             }
             break;
     }
     return $block;
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:30,代码来源:tag_it_block.php

示例4: get

 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "random_image":
             $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current();
             if ($item && $item->loaded()) {
                 $block = new Block();
                 $block->css_id = "g-image-block";
                 $block->title = t("Random image");
                 $block->content = new View("image_block_block.html");
                 $block->content->item = $item;
             }
             break;
     }
     return $block;
 }
开发者ID:joericochuyt,项目名称:gallery3,代码行数:17,代码来源:image_block_block.php

示例5: get

 /**
  * For items that are collections, you can specify the following additional query parameters to
  * query the collection.  You can specify them in any combination.
  *
  *   scope=direct
  *     Only return items that are immediately under this one
  *   scope=all
  *     Return items anywhere under this one
  *
  *   name=<substring>
  *     Only return items where the name contains this substring
  *
  *   random=true
  *     Return a single random item
  *
  *   type=<comma separate list of photo, movie or album>
  *     Limit the type to types in this list, eg: "type=photo,movie".
  *     Also limits the types returned in the member collections (same behaviour as item_rest).
  */
 static function get($request)
 {
     $item = rest::resolve($request->url);
     access::required("view", $item);
     $p = $request->params;
     if (isset($p->random)) {
         $orm = item::random_query()->offset(0)->limit(1);
     } else {
         $orm = ORM::factory("item")->viewable();
     }
     if (empty($p->scope)) {
         $p->scope = "direct";
     }
     if (!in_array($p->scope, array("direct", "all"))) {
         throw new Rest_Exception("Bad Request", 400);
     }
     if ($p->scope == "direct") {
         $orm->where("parent_id", "=", $item->id);
     } else {
         $orm->where("left_ptr", ">", $item->left_ptr);
         $orm->where("right_ptr", "<", $item->right_ptr);
     }
     if (isset($p->name)) {
         $orm->where("name", "LIKE", "%" . Database::escape_for_like($p->name) . "%");
     }
     if (isset($p->type)) {
         $orm->where("type", "IN", explode(",", $p->type));
     }
     // Apply the item's sort order, using id as the tie breaker.
     // See Item_Model::children()
     $order_by = array($item->sort_column => $item->sort_order);
     if ($item->sort_column != "id") {
         $order_by["id"] = "ASC";
     }
     $orm->order_by($order_by);
     $result = array("url" => $request->url, "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item));
     if ($item->is_album()) {
         $result["members"] = array();
         foreach ($orm->find_all() as $child) {
             $result["members"][] = rest::url("item", $child);
         }
     }
     return $result;
 }
开发者ID:HarriLu,项目名称:gallery3,代码行数:63,代码来源:item_rest.php

示例6: get

 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "random_image":
             // The random_query approach is flawed and doesn't always return a
             // result when there actually is one. Retry a *few* times.
             // @todo Consider another fallback if further optimizations are necessary.
             $attempts = 0;
             do {
                 $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current();
             } while (!$item && $attempts++ < 3);
             if ($item && $item->loaded()) {
                 $block = new Block();
                 $block->css_id = "g-image-block";
                 $block->title = t("Random image");
                 $block->content = new View("image_block_block.html");
                 $block->content->item = $item;
             }
             break;
     }
     return $block;
 }
开发者ID:andyst,项目名称:gallery3,代码行数:23,代码来源:image_block_block.php

示例7: get_thumb_element

 public function get_thumb_element($item, $addcontext = FALSE, $linkonly = FALSE)
 {
     $thumb_item = $item;
     if ($this->thumb_random) {
         if ($item->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $item->id)->find()) && $rnd->loaded()) {
             $thumb_item = $rnd;
         }
     }
     $item_class = $item->is_album() ? "g-album" : "g-photo";
     $content = '<li id="g-item-id-' . $item->id . '" class="g-item ' . $item_class . ' ' . $this->thumb_type;
     if ($item->is_album()) {
         $_thumb_descmode = $this->thumb_descmode_a;
     } else {
         $_thumb_descmode = $this->thumb_descmode;
     }
     $content .= $_thumb_descmode == "bottom" ? " g-expanded" : " g-default";
     if ($thumb_item->has_thumb()) {
         $is_portrait = $thumb_item->thumb_height > $thumb_item->thumb_width;
         $_shift = "";
         switch ($this->thumb_imgalign) {
             case "center":
                 if ($this->crop_factor == 1 and !$is_portrait) {
                     $_shift = 'style="margin-top: ' . intval(($this->_thumb_size_y - $thumb_item->thumb_height) / 2) . 'px;"';
                 } elseif ($this->crop_factor > 0) {
                     $_shift = 'style="margin-top: -' . intval(($thumb_item->thumb_height - $this->_thumb_size_y) / 2) . 'px;"';
                 }
                 break;
             case "bottom":
                 if ($this->crop_factor == 1 and !$is_portrait) {
                     $_shift = 'style="margin-top: ' . intval($this->_thumb_size_y - $thumb_item->thumb_height) . 'px;"';
                 } elseif ($this->crop_factor > 0) {
                     $_shift = 'style="margin-top: -' . intval($thumb_item->thumb_height - $this->_thumb_size_y) . 'px;"';
                 }
                 break;
             case "fit":
                 break;
             case "top":
             default:
                 break;
         }
     } else {
         $is_portrait = FALSE;
         $_shift = 'style="margin-top: 0px;"';
     }
     $content .= $is_portrait ? " g-portrait" : " g-landscape";
     $content .= '">' . $this->thumb_top($item);
     $content .= '<div class="g-thumbslide">';
     $thumb_content = '<p class="g-thumbcrop">';
     $use_direct_link = $this->disablephotopage && !$item->is_album();
     $class_name = "g-thumblink";
     if ($use_direct_link) {
         $class_name .= ' g-sb-preview" rel="g-preview';
         if (access::can("view_full", $item)) {
             $direct_link = $item->file_url();
         } else {
             $direct_link = $item->resize_url();
         }
     } else {
         $direct_link = $item->url();
     }
     if ($use_direct_link && module::is_active("exif") && module::info("exif")) {
         $thumb_content .= '<a class="g-meta-exif-link g-dialog-link" href="' . url::site("exif/show/{$item->id}") . '" title="' . t("Photo details")->for_html_attr() . '">&nbsp;</a>';
     }
     $thumb_content .= '<a title="' . $this->get_item_title($item) . '" ' . $_shift . ' class="' . $class_name . '" href="' . $direct_link . '">';
     if ($thumb_item->has_thumb()) {
         if ($this->crop_factor > 1 && $this->thumb_imgalign == "fit") {
             if ($thumb_item->thumb_height > $this->_thumb_size_y) {
                 if ($is_portrait) {
                     $_max = $this->_thumb_size_y;
                 } else {
                     $_max = intval($this->_thumb_size_x * ($this->_thumb_size_y / $thumb_item->thumb_height));
                 }
             } else {
                 $_max = $this->_thumb_size_x;
             }
             $_max = min($thumb_item->thumb_width, $_max);
             $thumb_content .= $thumb_item->thumb_img(array(), $_max);
         } else {
             $thumb_content .= $thumb_item->thumb_img();
         }
     } else {
         $thumb_content .= '<img title="No Image" alt="No Image" src="' . $this->url("images/missing-img.png") . '"/>';
     }
     $thumb_content .= '</a></p>';
     if ($this->thumb_metamode != "hide" and $_thumb_descmode == "overlay_bottom") {
         $_thumb_metamode = "merged";
     } else {
         $_thumb_metamode = $this->thumb_metamode;
     }
     if ($_thumb_descmode == "overlay" or $_thumb_descmode == "overlay_top" or $_thumb_descmode == "overlay_bottom") {
         $thumb_content .= '<ul class="g-description ';
         if ($_thumb_descmode == "overlay_top") {
             $thumb_content .= 'g-overlay-top';
         }
         if ($_thumb_descmode == "overlay_bottom") {
             $thumb_content .= 'g-overlay-bottom';
         }
         $thumb_content .= '"><li class="g-title">' . $this->get_item_title($item, FALSE, $this->visible_title_length) . '</li>';
         if ($_thumb_metamode == "merged") {
             $thumb_content .= $this->thumb_info($item);
//.........这里部分代码省略.........
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:101,代码来源:MY_Theme_View.php


注:本文中的item::random_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。