* Return entities matching a given query, or the number thereof\r
* \r
* @param string $type The type of entity (eg "user", "object" etc)\r
- * @param string $subtype The arbitrary subtype of the entity\r
+ * @param string|array $subtype The arbitrary subtype of the entity or array(type1 => array('subtype1', ...'subtypeN'), ...)\r
* @param int $owner_guid The GUID of the owning user\r
* @param string $order_by The field to order by; by default, time_created desc\r
* @param int $limit The number of entities to return; 10 by default\r
\r
$where = array();\r
\r
- if (is_array($subtype)) { \r
+ if (is_array($subtype)) {\r
$tempwhere = "";\r
if (sizeof($subtype))\r
foreach($subtype as $typekey => $subtypearray) {\r
foreach($subtypearray as $subtypeval) {\r
$typekey = sanitise_string($typekey);\r
if (!empty($subtypeval)) {\r
- $subtypeval = (int) get_subtype_id($typekey, $subtypeval);\r
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))\r
+ return false;\r
} else {\r
+ // @todo: Setting subtype to 0 when $subtype = '' returns entities with\r
+ // no subtype. This is different to the non-array behavior\r
+ // but may be required in some cases.\r
$subtypeval = 0;\r
}\r
if (!empty($tempwhere)) $tempwhere .= " or ";\r
$tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";\r
- } \r
+ }\r
}\r
if (!empty($tempwhere)) $where[] = "({$tempwhere})";\r
\r
} else {\r
\r
$type = sanitise_string($type);\r
- if ($subtype !== "")\r
- $subtype = get_subtype_id($type, $subtype);\r
+ if ($subtype !== "" AND !$subtype = get_subtype_id($type, $subtype))\r
+ return false;\r
\r
if ($type != "")\r
$where[] = "type='$type'";\r
if ($subtype!=="")\r
$where[] = "subtype=$subtype";\r
- \r
}\r
- \r
+\r
if ($owner_guid != "") {\r
if (!is_array($owner_guid)) {\r
$owner_array = array($owner_guid);\r
foreach($subtypearray as $subtypeval) {\r
$typekey = sanitise_string($typekey);\r
if (!empty($subtypeval)) {\r
- $subtypeval = (int) get_subtype_id($typekey, $subtypeval);\r
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))\r
+ return false;\r
} else {\r
$subtypeval = 0;\r
}\r
if (!empty($tempwhere)) $where[] = "({$tempwhere})";\r
\r
} else {\r
- \r
- $subtype = get_subtype_id($type, $subtype);\r
- \r
- if ($subtype!=="")\r
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype)) {\r
+ return false;\r
+ } else {\r
$where[] = "subtype=$subtype";\r
- \r
+ }\r
}\r
\r
if ($container_guid !== 0) {\r
foreach($subtypearray as $subtypeval) {\r
$typekey = sanitise_string($typekey);\r
if (!empty($subtypeval)) {\r
- $subtypeval = (int) get_subtype_id($typekey, $subtypeval);\r
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {\r
+ return false;\r
+ }\r
} else {\r
$subtypeval = 0;\r
}\r
} else {\r
\r
$type = sanitise_string($type);\r
- $subtype = get_subtype_id($type, $subtype);\r
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype)) {\r
+ return false;\r
+ }\r
\r
if ($type != "")\r
$where[] = "e.type='$type'";\r
*\r
* @param string $name The name of the setting\r
* @param string $value The value of the setting\r
- * @param string $type The type of entity (eg "user", "object" etc)\r
+ * @param string|array $type The type of entity (eg "user", "object" etc) or array(type1 => array('subtype1', ...'subtypeN'), ...)\r
* @param string $subtype The arbitrary subtype of the entity\r
* @param int $owner_guid The GUID of the owning user\r
* @param string $order_by The field to order by; by default, time_created desc\r
\r
$where = array();\r
\r
- if (is_array($type)) { \r
+ if (is_array($type)) {\r
$tempwhere = "";\r
if (sizeof($type))\r
foreach($type as $typekey => $subtypearray) {\r
foreach($subtypearray as $subtypeval) {\r
$typekey = sanitise_string($typekey);\r
if (!empty($subtypeval)) {\r
- $subtypeval = (int) get_subtype_id($typekey, $subtypeval);\r
+ if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval)) {\r
+ return false;\r
+ }\r
} else {\r
$subtypeval = 0;\r
}\r
if (!empty($tempwhere)) $tempwhere .= " or ";\r
$tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";\r
- } \r
+ }\r
}\r
if (!empty($tempwhere)) $where[] = "({$tempwhere})";\r
\r
} else {\r
- \r
$type = sanitise_string($type);\r
- $subtype = get_subtype_id($type, $subtype);\r
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype))\r
+ return false;\r
\r
if ($type != "")\r
$where[] = "e.type='$type'";\r
$relationship_guid = (int)$relationship_guid;
$inverse_relationship = (bool)$inverse_relationship;
$type = sanitise_string($type);
- $subtype = get_subtype_id($type, $subtype);
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype))
+ return false;
$owner_guid = (int)$owner_guid;\r
if ($order_by == "") $order_by = "time_created desc";
$order_by = sanitise_string($order_by);
$relationship = sanitise_string($relationship);\r
$inverse_relationship = (bool)$inverse_relationship;\r
$type = sanitise_string($type);\r
- $subtype = get_subtype_id($type, $subtype);\r
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype))
+ return false;\r
$owner_guid = (int)$owner_guid;\r
$order_by = sanitise_string($order_by);\r
$limit = (int)$limit;\r
$inverse_relationship = (bool)$inverse_relationship;
$relationship_guid = (int)$relationship_guid;
$type = sanitise_string($type);
- if ($subtype)
- $subtype = get_subtype_id($type, $subtype);
+ if ($subtype AND !$subtype = get_subtype_id($type, $subtype))
+ return false;
$owner_guid = (int)$owner_guid;
$order_by = sanitise_string($order_by);
$limit = (int)$limit;