58 lines
1.0 KiB
PHP
58 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXF\Resource\Sort;
|
|
|
|
class Sort implements ISort {
|
|
|
|
protected array $attributes = [];
|
|
protected array $conditions = [];
|
|
|
|
public function __construct(array $attributes) {
|
|
$this->attributes = $attributes;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return array<string,bool>
|
|
*/
|
|
public function attributes(): array {
|
|
return $this->attributes;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @param string $attribute attribute name
|
|
* @param bool $direction true for ascending, false for descending
|
|
*/
|
|
public function condition(string $attribute, bool $direction): void {
|
|
if (isset($this->attributes[$attribute])) {
|
|
$this->conditions[$attribute] = [
|
|
'attribute' => $attribute,
|
|
'direction' => $direction,
|
|
];
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return array<string,array{attribute:string, direction:bool}>
|
|
*/
|
|
public function conditions(): array {
|
|
return $this->conditions;
|
|
}
|
|
|
|
}
|