| Total Complexity | 7 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class ArrayMethods |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * return an array of ids that can be ued for ORM filters... |
||
| 13 | * |
||
| 14 | * @param mixed $array - hopefully an array |
||
| 15 | */ |
||
| 16 | public static function filter_array($array): array |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * creates a sort string from a list of ID arrays... |
||
| 30 | * |
||
| 31 | * @param array $ids - list of product IDs |
||
| 32 | */ |
||
| 33 | public static function create_sort_statement_from_id_array(array $ids, ?string $className = ''): string |
||
| 34 | { |
||
| 35 | $ids = ArrayMethods::filter_array($ids); |
||
| 36 | $ifStatement = 'CASE '; |
||
| 37 | $count = 0; |
||
| 38 | $stage = self::get_stage(); |
||
| 39 | $dataClasses = ClassInfo::dataClassesFor($className); |
||
| 40 | $table = DataObject::getSchema()->tableName(array_shift($dataClasses)); |
||
| 41 | foreach ($ids as $id) { |
||
| 42 | $ifStatement .= ' WHEN "' . $table . $stage . "\".\"ID\" = {$id} THEN {$count}"; |
||
| 43 | ++$count; |
||
| 44 | } |
||
| 45 | |||
| 46 | return $ifStatement . ' END'; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Returns a versioned record stage table suffix (i.e "" or "_Live"). |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | protected static function get_stage() |
||
| 63 | } |
||
| 64 | } |
||
| 65 |