本文整理汇总了PHP中rest::relationships方法的典型用法代码示例。如果您正苦于以下问题:PHP rest::relationships方法的具体用法?PHP rest::relationships怎么用?PHP rest::relationships使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest
的用法示例。
在下文中一共展示了rest::relationships方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* The tree is rooted in a single item and can have modifiers which adjust what data is shown
* for items inside the given tree, up to the depth that you want. The entity for this resource
* is a series of items.
*
* depth=<number>
* Only traverse this far down into the tree. If there are more albums
* below this depth, provide RESTful urls to other tree resources in
* the members section. Default is infinite.
*
* type=<album|photo|movie>
* Restrict the items displayed to the given type. Default is all types.
*
* fields=<comma separated list of field names>
* In the entity section only return these fields for each item.
* Default is all fields.
*/
static function get($request)
{
$item = rest::resolve($request->url);
access::required("view", $item);
$query_params = array();
$p = $request->params;
$where = array();
if (isset($p->type)) {
$where[] = array("type", "=", $p->type);
$query_params[] = "type={$p->type}";
}
if (isset($p->depth)) {
$lowest_depth = $item->level + $p->depth;
$where[] = array("level", "<=", $lowest_depth);
$query_params[] = "depth={$p->depth}";
}
$fields = array();
if (isset($p->fields)) {
$fields = explode(",", $p->fields);
$query_params[] = "fields={$p->fields}";
}
$entity = array(array("url" => rest::url("item", $item), "entity" => $item->as_restful_array($fields)));
$members = array();
foreach ($item->viewable()->descendants(null, null, $where) as $child) {
$entity[] = array("url" => rest::url("item", $child), "entity" => $child->as_restful_array($fields));
if (isset($lowest_depth) && $child->level == $lowest_depth) {
$members[] = url::merge_querystring(rest::url("tree", $child), $query_params);
}
}
$result = array("url" => $request->url, "entity" => $entity, "members" => $members, "relationships" => rest::relationships("tree", $item));
return $result;
}
示例2: 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));
}
示例3: _format_restful_item
private static function _format_restful_item($item, $types)
{
$item_rest = array("url" => rest::url("item", $item), "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item));
if ($item->type == "album") {
$members = array();
foreach ($item->viewable()->children() as $child) {
if (empty($types) || in_array($child->type, $types)) {
$members[] = rest::url("item", $child);
}
}
$item_rest["members"] = $members;
}
return $item_rest;
}
示例4: 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;
}
示例5: get
static function get($request)
{
$items = array();
if (isset($request->params->url)) {
foreach ($request->params->url as $url) {
$item = rest::resolve($url);
if (access::can("view", $item)) {
$members = array();
if ($item->type == "album") {
foreach ($item->children() as $child) {
$members[] = rest::url("item", $child);
}
}
$items[] = array("url" => $url, "entity" => $item->as_restful_array(), "members" => $members, "relationship" => rest::relationships("item", $item));
}
}
}
return $items;
}
示例6: get
static function get($request)
{
$comment = rest::resolve($request->url);
access::required("view", $comment->item());
return array("url" => $request->url, "entity" => $comment->as_restful_array(), "relationships" => rest::relationships("comment", $comment));
}
示例7: get_ancestors_test
public function get_ancestors_test()
{
$album1 = test::random_album();
$photo1 = test::random_photo($album1);
$album2 = test::random_album($album1);
$photo2 = test::random_photo($album2);
$album1->reload();
$album2->reload();
$root = ORM::factory("item", 1);
$restful_root = array("url" => rest::url("item", $root), "entity" => $root->as_restful_array(), "relationships" => rest::relationships("item", $root));
$restful_root["members"] = array();
foreach ($root->children() as $child) {
$restful_root["members"][] = rest::url("item", $child);
}
$request = new stdClass();
$request->params = new stdClass();
$request->params->ancestors_for = rest::url("item", $photo2);
$this->assert_equal_array(array($restful_root, array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $album1)), "tags" => array("url" => rest::url("item_tags", $album1), "members" => array())), "members" => array(rest::url("item", $photo1), rest::url("item", $album2))), array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $album2)), "tags" => array("url" => rest::url("item_tags", $album2), "members" => array())), "members" => array(rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), "entity" => $photo2->as_restful_array(), "relationships" => array("comments" => array("url" => rest::url("item_comments", $photo2)), "tags" => array("url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request));
}