* @param array $criteria SQL criteria to get volume overview
* @param integer $limit_val item limit
* @param integer $offset_val offset value
+ * @param array $sort order by and order direction in form [[by1, direction1], [by2, direction2]...etc.]
* @return array volume overview
*/
- public function getMediaOverview($criteria = [], $limit_val = 0, $offset_val = 0) {
+ public function getMediaOverview($criteria = [], $limit_val = 0, $offset_val = 0, $sort = [['VolStatus', 'ASC'],['LastWritten', 'DESC']]) {
$limit = '';
if(is_int($limit_val) && $limit_val > 0) {
$limit = " LIMIT $limit_val ";
$offset = ' OFFSET ' . $offset_val;
}
+ $order = Database::getOrder($sort);
+
$where = Database::getWhere($criteria);
// get volume type count
JOIN Storage USING (StorageId)
JOIN Pool USING (PoolId)
' . (!empty($where['where']) ? $where['where'] . ' AND ' : ' WHERE ') . ' VolType IN (' . implode(',', $vt_disk) . ')
- ORDER BY VolStatus ASC, LastWritten DESC' . $limit . $offset;
+ ' . $order . $limit . $offset;
$statement = Database::runQuery($sql, $where['params']);
$voltype_disk = $statement->fetchAll(PDO::FETCH_OBJ);
JOIN Storage USING (StorageId)
JOIN Pool USING (PoolId)
' . (!empty($where['where']) ? $where['where'] . ' AND ' : ' WHERE ') . ' VolType IN (' . implode(',', $vt_tape) . ')
- ORDER BY VolStatus ASC, LastWritten DESC' . $limit . $offset;
+ ' . $order . $limit . $offset;
$statement = Database::runQuery($sql, $where['params']);
$voltype_tape = $statement->fetchAll(PDO::FETCH_OBJ);
JOIN Storage USING (StorageId)
JOIN Pool USING (PoolId)
' . (!empty($where['where']) ? $where['where'] . ' AND ' : ' WHERE ') . ' VolType IN (' . implode(',', $vt_cloud) . ')
- ORDER BY VolStatus ASC, LastWritten DESC' . $limit . $offset;
+ ' . $order . $limit . $offset;
$statement = Database::runQuery($sql, $where['params']);
$voltype_cloud = $statement->fetchAll(PDO::FETCH_OBJ);
use Baculum\API\Modules\BaculumAPIServer;
use Baculum\Common\Modules\Errors\PoolError;
+use Baculum\Common\Modules\Errors\VolumeError;
/**
* Media/Volumes overview endpoint.
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
+ $order_by = $this->Request->contains('order_by') && $misc->isValidColumn($this->Request['order_by']) ? $this->Request['order_by']: 'VolStatus';
+ $order_direction = $this->Request->contains('order_direction') && $misc->isValidOrderDirection($this->Request['order_direction']) ? $this->Request['order_direction'] : 'ASC';
+ $sec_order_by = $this->Request->contains('sec_order_by') && $misc->isValidColumn($this->Request['sec_order_by']) ? $this->Request['sec_order_by']: 'LastWritten';
+ $sec_order_direction = $this->Request->contains('sec_order_direction') && $misc->isValidOrderDirection($this->Request['sec_order_direction']) ? $this->Request['sec_order_direction'] : 'DESC';
+ $order = [
+ [
+ $order_by,
+ $order_direction
+ ],
+ [
+ $sec_order_by,
+ $sec_order_direction
+ ]
+ ];
+ $jr = new \ReflectionClass('Baculum\API\Modules\VolumeRecord');
+ $sort_cols = $jr->getProperties();
+ $columns = [];
+ foreach ($sort_cols as $cols) {
+ $columns[] = $cols->getName();
+ }
+ $col_err = null;
+ for ($i = 0; $i < count($order); $i++) {
+ $order_by_lc = strtolower($order[$i][0]);
+ if (!in_array($order_by_lc, $columns)) {
+ $col_err = $order[$i][0];
+ break;
+ }
+ }
+ if ($col_err) {
+ $this->output = VolumeError::MSG_ERROR_INVALID_PROPERTY . ' Prop=>' . $col_err;
+ $this->error = VolumeError::ERROR_INVALID_PROPERTY;
+ return;
+ }
+
$pools = $this->getModule('pool')->getPools();
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
$ret = $this->getModule('volume')->getMediaOverview(
$params,
$limit,
- $offset
+ $offset,
+ $order
);
$this->output = $ret;
- $this->error = PoolError::ERROR_NO_ERRORS;
+ $this->error = VolumeError::ERROR_NO_ERRORS;
} else {
$this->output = PoolError::MSG_ERROR_POOL_DOES_NOT_EXISTS;
$this->error = PoolError::ERROR_POOL_DOES_NOT_EXISTS;
}
} else {
- $this->output = PoolError::MSG_ERROR_WRONG_EXITCODE;
- $this->error = PoolError::ERROR_WRONG_EXITCODE . ' Exitcode=> ' . $result->exitcode;
+ $this->output = PoolError::MSG_ERROR_WRONG_EXITCODE . ' Exitcode=> ' . $result->exitcode;
+ $this->error = PoolError::ERROR_WRONG_EXITCODE;
}
}
}
},
{
"$ref": "#/components/parameters/Offset"
+ },
+ {
+ "name": "order_by",
+ "in": "query",
+ "required": false,
+ "description": "Sort by selected volume property (default volstatus). There can be any volume property (mediaid, volumename...etc.)",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "order_direction",
+ "in": "query",
+ "required": false,
+ "description": "Order direction. It can be 'asc' (ascending order - default) or 'desc' (descending order)",
+ "schema": {
+ "type": "string",
+ "enum": ["asc", "desc"]
+ }
+ },
+ {
+ "name": "sec_order_by",
+ "in": "query",
+ "required": false,
+ "description": "Second dimension sort by selected volume property (default lastwritten). There can be any volume property (mediaid, volumename ...etc.)",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "name": "sec_order_direction",
+ "in": "query",
+ "required": false,
+ "description": "Direction for second dimension of sorting. It can be 'asc' (ascending order) or 'desc' (descending order - default)",
+ "schema": {
+ "type": "string",
+ "enum": ["asc", "desc"]
+ }
}
]
}