r2941 - maintenance->trunk sync of changeset 2938
[racktables] / inc / database.php
index f2e19b1..b27626d 100644 (file)
@@ -1620,6 +1620,71 @@ function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn =
        return $ret;
 }
 
+// This function will eventually merge the functionality of the "older"
+// searching function. Both ones are used at the moment, and they do
+// search in different value spaces.
+function getObjectSearchResults_new ($what)
+{
+       $ret = array();
+       foreach (getStickerSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_sticker'] = $objRecord['by_sticker'];
+       }
+       foreach (getPortRsvSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_portrsv'] = $objRecord['by_portrsv'];
+       }
+       return $ret;
+}
+
+// Look for EXACT value in stickers and return a list of pairs "object_id-attribute_id",
+// which matched. A partilar object_id could be returned more, than once, if it has
+// multiple matching stickers. Search is only performed on "string" attributes.
+function getStickerSearchResults ($what, $exactness = 0)
+{
+       $stickers = getSearchResultByField
+       (
+               'AttributeValue',
+               array ('object_id', 'attr_id'),
+               'string_value',
+               $what,
+               'object_id',
+               $exactness
+       );
+       $map = getAttrMap();
+       $ret = array();
+       foreach ($stickers as $sticker)
+               if ($map[$sticker['attr_id']]['type'] == 'string')
+               {
+                       $ret[$sticker['object_id']]['id'] = $sticker['object_id'];
+                       $ret[$sticker['object_id']]['by_sticker'][] = $sticker['attr_id'];
+               }
+       return $ret;
+}
+
+// search in port "reservation comment" column
+function getPortRsvSearchResults ($what)
+{
+       $ports = getSearchResultByField
+       (
+               'Port',
+               array ('object_id', 'id'),
+               'reservation_comment',
+               $what,
+               'object_id',
+               0
+       );
+       $ret = array();
+       foreach ($ports as $port)
+       {
+               $ret[$port['object_id']]['id'] = $port['object_id'];
+               $ret[$port['object_id']]['by_portrsv'][] = $port['id'];
+       }
+       return $ret;
+}
+
 // This function returns either port ID or NULL for specified arguments.
 function getPortID ($object_id, $port_name)
 {