]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add group_order_by and group_order_direction parameters to objects endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 7 Jun 2023 09:05:37 +0000 (11:05 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 3 Jul 2023 08:46:57 +0000 (10:46 +0200)
gui/baculum/protected/API/Modules/ObjectManager.php
gui/baculum/protected/API/Pages/API/Objects.php

index b97f0b1e1dde7e7010aa489f5bd6ca642f02f4b2..7e6df27bb5bb1d751bc4db60f3e4e8072c1d07bf 100644 (file)
@@ -84,7 +84,7 @@ class ObjectManager extends APIModule
         * @param string $view job records view (basic, full)
         * @return array object list
         */
-       public function getObjects($criteria = [], $opts = [], $limit_val = null, $offset_val = 0, $sort_col = 'ObjectId', $sort_order = 'DESC', $group_by = null, $group_limit = 0, $group_offset = 0, $view = self::OBJ_RESULT_VIEW_FULL, $mode = self::OBJECT_RESULT_MODE_NORMAL) {
+       public function getObjects($criteria = [], $opts = [], $limit_val = null, $offset_val = 0, $sort_col = 'ObjectId', $sort_order = 'DESC', $group_by = null, $group_limit = 0, $group_offset = 0, $group_order_by = null, $group_order_direction = 'ASC', $view = self::OBJ_RESULT_VIEW_FULL, $mode = self::OBJECT_RESULT_MODE_NORMAL) {
                $db_params = $this->getModule('api_config')->getConfig('db');
                if ($db_params['type'] === Database::PGSQL_TYPE) {
                    $sort_col = strtolower($sort_col);
@@ -130,7 +130,15 @@ LEFT JOIN Client USING (ClientId) '
                        $result = array_values($result);
                        $result = array_map($func, $result);
                }
-               $overview = Database::groupBy($group_by, $result, $group_limit, $group_offset, 'objecttype');
+               $overview = Database::groupBy(
+                       $group_by,
+                       $result,
+                       $group_limit,
+                       $group_offset,
+                       'objecttype',
+                       $group_order_by,
+                       $group_order_direction
+               );
                if ($mode == self::OBJECT_RESULT_MODE_OVERVIEW) {
                        // Overview mode.
                        $result = [
index 47a6e2da85a24ef90caaf84dd01065f55f394a05..88bc7e7a1f9a1361e9abd7b91a9d8e58968c9a21 100644 (file)
@@ -54,6 +54,8 @@ class Objects extends BaculumAPIServer {
                $group_by = $this->Request->contains('groupby') && $misc->isValidColumn($this->Request['groupby']) ? strtolower($this->Request['groupby']) : null;
                $group_offset = $this->Request->contains('group_offset') ? intval($this->Request['group_offset']) : 0;
                $group_limit = $this->Request->contains('group_limit') ? intval($this->Request['group_limit']) : 0;
+               $group_order_by = $this->Request->contains('group_order_by') && $misc->isValidColumn($this->Request['group_order_by']) ? $this->Request['group_order_by']: 'ObjectId';
+               $group_order_direction = $this->Request->contains('group_order_direction') && $misc->isValidOrderDirection($this->Request['group_order_direction']) ? $this->Request['group_order_direction']: 'ASC';
 
                // UNIX timestamp values
                $schedtime_from = $this->Request->contains('schedtime_from') && $misc->isValidInteger($this->Request['schedtime_from']) ? (int)$this->Request['schedtime_from'] : null;
@@ -385,6 +387,8 @@ class Objects extends BaculumAPIServer {
                        $group_by,
                        $group_limit,
                        $group_offset,
+                       $group_order_by,
+                       $group_order_direction,
                        ObjectManager::OBJ_RESULT_VIEW_FULL,
                        $mode
                );