]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Updated get_*() functions ot return false if an invalid subtype is specified.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 29 Jun 2009 19:30:54 +0000 (19:30 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Mon, 29 Jun 2009 19:30:54 +0000 (19:30 +0000)
git-svn-id: https://code.elgg.org/elgg/trunk@3360 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/entities.php
engine/lib/relationships.php

index c8457ca39477910c329d96d90aba84a9864f2744..42f131c8b8b9b722c08a4634df138df825d9d20f 100644 (file)
         * 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
index d98daffab0de4980bcedf6e39b96c5624c0b2075..d8541e5e662832acd724a2f79969cb29f3d73336 100644 (file)
                $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;