- function multiGet($cls, $keyCol, $keyVals, $skipNulls=true)
- {
- $result = self::pivotGet($cls, $keyCol, $keyVals);
-
- $values = array_values($result);
-
- if ($skipNulls) {
- $tmp = array();
- foreach ($values as $value) {
- if (!empty($value)) {
- $tmp[] = $value;
- }
- }
- $values = $tmp;
- }
-
- return new ArrayWrapper($values);
- }
-
+ static function multiGetClass($cls, $keyCol, array $keyVals)
+ {
+ $obj = new $cls;
+
+ // PHP compatible datatype for settype() below
+ $colType = $obj->columnType($keyCol);
+
+ if (!in_array($colType, array('integer', 'int'))) {
+ // This is because I'm afraid to escape strings incorrectly
+ // in the way we use them below in FIND_IN_SET for MariaDB
+ throw new ServerException('Cannot do multiGet on anything but integer columns');
+ }
+
+ $obj->whereAddIn($keyCol, $keyVals, $colType);
+
+ // Since we're inputting straight to a query: format and escape
+ foreach ($keyVals as $key=>$val) {
+ settype($val, $colType);
+ $keyVals[$key] = $obj->escape($val);
+ }
+
+ // FIND_IN_SET will make sure we keep the desired order
+ $obj->orderBy(sprintf("FIND_IN_SET(%s, '%s')", $keyCol, implode(',', $keyVals)));
+ $obj->find();
+
+ return $obj;
+ }
+