return $result;
}
- /**
- * Get object categories based on criterias.
- *
- * @param array $criteria SQL criteria to get job list
- * @return array category list or empty list if no category found
- */
- public function getObjectCategories($criteria = []) {
- $where = Database::getWhere($criteria);
-
- $sql = 'SELECT DISTINCT ObjectCategory as objectcategory
-FROM Object
-JOIN Job USING (JobId) '
-. $where['where'];
- $statement = Database::runQuery($sql, $where['params']);
- return $statement->fetchAll(\PDO::FETCH_ASSOC);
- }
-
public function getObjectById($objectid) {
$params = [
'Object.ObjectId' => [[
$values = array_keys($result);
return $values;
}
+
+ /**
+ * Get existing object categories.
+ *
+ * @param integer $limit_val maximum number of elements to return
+ * @return array object names
+ */
+ public function getObjectCategories($limit_val = null) {
+ $limit = '';
+ if(is_int($limit_val) && $limit_val > 0) {
+ $limit = sprintf(
+ ' LIMIT %d',
+ $limit_val
+ );
+ }
+ $sql = 'SELECT DISTINCT ObjectCategory as objectcategory
+ FROM Object
+ ORDER BY ObjectCategory ' . $limit;
+ $statement = Database::runQuery($sql);
+ $result = $statement->fetchAll(PDO::FETCH_COLUMN);
+ return $result;
+ }
}
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\ObjectError;
+
+/**
+ * Available object categories endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class ObjectCategories extends BaculumAPIServer {
+
+ public function get() {
+ $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : null;
+
+ $this->output = $this->getModule('object')->getObjectCategories(
+ $limit
+ );
+ $this->error = ObjectError::ERROR_NO_ERRORS;
+ }
+}
<url ServiceParameter="ObjectVersions" pattern="api/v2/objects/versions/{uuid}" parameters.uuid="[a-zA-Z0-9:.\-_ ]+" />
<url ServiceParameter="ObjectTypes" pattern="api/v2/objects/types/" />
<url ServiceParameter="ObjectNames" pattern="api/v2/objects/names/" />
+ <url ServiceParameter="ObjectCategories" pattern="api/v2/objects/categories/" />
<url ServiceParameter="ObjectStatsCategorySum" pattern="api/v2/objects/stats/category-sum/" />
<url ServiceParameter="ObjectStatsCategoryStatus" pattern="api/v2/objects/stats/category-status/" />
<url ServiceParameter="ObjectStatsSizeSum" pattern="api/v2/objects/stats/size-sum/" />
]
}
},
+ "/api/v2/objects/categories": {
+ "get": {
+ "tags": ["objects"],
+ "summary": "Object categories",
+ "description": "Get object categories.",
+ "responses": {
+ "200": {
+ "description": "Object categories.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "description": "Object category"
+ }
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 1, 2, 3, 6, 7, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/Limit"
+ }
+ ]
+ }
+ },
"/api/v2/objects/types": {
"get": {
"tags": ["objects"],