@@ -410,11 +410,40 @@ public function getAccessToken()
410410 /**
411411 * Query units from the server.
412412 *
413+ * @param array $options Includes: 'lang', 'filter', and 'sortBy'.
414+ * @return array
415+ */
416+ public function queryUnits (array $ options = []): array
417+ {
418+ $ request = [
419+ 'contentType ' => 'units ' ,
420+ 'lang ' => $ options ['lang ' ] ?? 'en ' ,
421+ 'filter ' => $ options ['filter ' ] ?? null
422+ ];
423+
424+ $ units = $ this ->read ($ request );
425+
426+ $ sortBy = $ options ['sortBy ' ] ?? false ;
427+
428+ if ($ sortBy ) {
429+ usort ($ units , function ($ u1 , $ u2 ) use ($ sortBy ) {
430+ $ a = $ u1 [$ sortBy ];
431+ $ b = $ u2 [$ sortBy ];
432+ return ($ a == $ b ) ? 0 : ($ a < $ b ? -1 : 1 );
433+ });
434+ }
435+
436+ return $ units ;
437+ }
438+
439+ /**
440+ * Query unit profiles from the server.
441+ *
413442 * @param string|null $unitType Filter response by type.
414443 * @param string|null $lang Localize to selected language code ('en, 'fr).
415444 * @return array
416445 */
417- public function queryUnits (string $ unitType = null , string $ lang = null ): array
446+ public function queryUnitProfiles (string $ unitType = null , string $ lang = null ): array
418447 {
419448 $ request = [
420449 'contentType ' => 'units ' ,
@@ -483,9 +512,9 @@ public static function assertValidRequest($request)
483512 self ::throwError ('Invalid request parameters ' );
484513 }
485514
486- if (empty ($ request ['resources ' ])) {
487- self ::throwError ('Empty "resources" property in request ' );
488- }
515+ // if (empty($request['resources'])) {
516+ // self::throwError('Empty "resources" property in request');
517+ // }
489518 }
490519
491520 /**
0 commit comments