From 4b50ab5ef56c657f41a7039c1967bd2777293c92 Mon Sep 17 00:00:00 2001 From: icewing Date: Mon, 17 Mar 2008 17:48:01 +0000 Subject: Marcus Povey * limit/offset the wrong way round git-svn-id: https://code.elgg.org/elgg/trunk@238 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index d42dbfd5f..9c1de36f0 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -326,6 +326,25 @@ return false; } + /** + * This function will register a new subtype, returning its ID as required. + * + * @param string $subtype + */ + function add_subtype($subtype) + { + global $CONFIG; + + $subtype = sanitise_string($subtype); + + $id = get_subtype_id($subtype); + + if (!$id) + return insert_data("insert into {$CONFIG->dbprefix}entity_subtypes (subtype) values ('$subtype')"); + + return $id; + } + /** * Update an existing entity. * @@ -360,9 +379,9 @@ function create_entity($type, $subtype, $owner_guid, $access_id) { global $CONFIG; - + $type = sanitise_string($type); - $subtype = get_subtype_id($subtype); + $subtype = add_subtype($subtype); $owner_guid = (int)$owner_guid; $access_id = (int)$access_id; $time = time(); @@ -397,7 +416,7 @@ { if (!($row instanceof stdClass)) return $row; - + switch ($row->type) { case 'object' : return new ElggObject($row); @@ -456,7 +475,7 @@ foreach ($where as $w) $query .= " $w and "; $query .= " (access_id in {$access} or (access_id = 0 and owner_guid = {$_SESSION['id']}))"; // Add access controls - $query .= " order by $order_by limit $offset,$limit"; // Add order and limit + $query .= " order by $order_by limit $limit, $offset"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } @@ -512,7 +531,7 @@ foreach ($where as $w) $query .= " $w and "; $query .= " (e.access_id in {$access} or (e.access_id = 0 and e.owner_guid = {$_SESSION['id']}))"; // Add access controls - $query .= " order by $order_by limit $offset,$limit"; // Add order and limit + $query .= " order by $order_by limit $limit, $offset"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } -- cgit v1.2.3