Skip to content

Commit

Permalink
sort fields implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 17, 2024
1 parent 4a60577 commit 5055e8d
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function userFilter(ActiveQuery $query, ?Model $form): ActiveQuery
*/
protected function userOrder(ActiveQuery $query, ?Model $form): ActiveQuery
{
return $query->orderBy(['title' => SORT_ASC]);
return $query->orderBy(['sort' => SORT_ASC, 'title' => SORT_ASC]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ApiGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function userFilter(ActiveQuery $query, ?Model $form): ActiveQuery
*/
protected function userOrder(ActiveQuery $query, ?Model $form): ActiveQuery
{
return $query->orderBy(['title' => SORT_ASC]);
return $query->orderBy(['sort' => SORT_ASC, 'title' => SORT_ASC]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/RuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function userFilter(ActiveQuery $query, ?Model $form): ActiveQuery
*/
protected function userOrder(ActiveQuery $query, ?Model $form): ActiveQuery
{
return $query->orderBy(['title' => SORT_ASC]);
return $query->orderBy(['sort' => SORT_ASC, 'title' => SORT_ASC]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/WorkerGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function userFilter(ActiveQuery $query, ?Model $form): ActiveQuery
*/
protected function userOrder(ActiveQuery $query, ?Model $form): ActiveQuery
{
return $query->orderBy(['title' => SORT_ASC]);
return $query->orderBy(['sort' => SORT_ASC, 'title' => SORT_ASC]);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/forms/api/ApiCreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class ApiCreateForm extends Model
* )
*/
public $title;
/**
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
*/
public $sort;
/**
* @OA\Property(
* property="extra",
Expand All @@ -56,6 +65,8 @@ public function rules()
return [
[['method', 'path', 'title'], 'required'],
[['method', 'path', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['path', 'title'], 'string', 'max' => 255],
[['method'], 'string', 'max' => 10],
Expand Down
8 changes: 8 additions & 0 deletions src/forms/api/ApiUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
* description="API name"
* )
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
* @OA\Property(
* property="extra",
* type="object|null",
* example=null,
Expand All @@ -40,6 +46,8 @@ public function rules()
{
return [
[['method', 'path', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['path', 'title'], 'string', 'max' => 255],
[['method'], 'string', 'max' => 10],
Expand Down
11 changes: 11 additions & 0 deletions src/forms/api_group/ApiGroupCreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class ApiGroupCreateForm extends Model
* )
*/
public $is_secured;
/**
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
*/
public $sort;
/**
* @OA\Property(
* property="extra",
Expand All @@ -65,6 +74,8 @@ public function rules()
return [
[['alias', 'title'], 'required'],
[['alias', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['in_menu', 'is_secured'], 'boolean'],
[['in_menu'], 'default', 'value' => false],
[['is_secured'], 'default', 'value' => true],
Expand Down
8 changes: 8 additions & 0 deletions src/forms/api_group/ApiGroupUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
* example=false,
* description="Include to menu flag"
* )
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
*/
class ApiGroupUpdateForm extends ApiGroupCreateForm
{
Expand All @@ -37,6 +43,8 @@ public function rules()
[['in_menu', 'is_secured'], 'boolean'],
[['in_menu'], 'default', 'value' => false],
[['is_secured'], 'default', 'value' => true],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['alias', 'title'], 'string', 'max' => 255],
];
Expand Down
11 changes: 11 additions & 0 deletions src/forms/rule/RuleCreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class RuleCreateForm extends Model
* )
*/
public $title;
/**
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
*/
public $sort;
/**
* @OA\Property(
* property="extra",
Expand All @@ -47,6 +56,8 @@ public function rules()
return [
[['alias', 'title'], 'required'],
[['alias', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['alias', 'title'], 'string', 'max' => 255],
];
Expand Down
8 changes: 8 additions & 0 deletions src/forms/rule/RuleUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
* example=null,
* description="Extra data"
* )
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
*/
class RuleUpdateForm extends RuleCreateForm
{
Expand All @@ -34,6 +40,8 @@ public function rules()
{
return [
[['alias', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['alias', 'title'], 'string', 'max' => 255],
];
Expand Down
11 changes: 11 additions & 0 deletions src/forms/worker_group/WorkerGroupCreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class WorkerGroupCreateForm extends Model
* )
*/
public $title;
/**
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
*/
public $sort;
/**
* @OA\Property(
* property="extra",
Expand All @@ -47,6 +56,8 @@ public function rules()
return [
[['alias', 'title'], 'required'],
[['alias', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['alias', 'title'], 'string', 'max' => 255],
];
Expand Down
8 changes: 8 additions & 0 deletions src/forms/worker_group/WorkerGroupUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* description="Worker group name"
* )
* @OA\Property(
* property="sort",
* type="integer",
* example="0",
* description="Sort index"
* )
* @OA\Property(
* property="extra",
* type="object|null",
* example=null,
Expand All @@ -34,6 +40,8 @@ public function rules()
{
return [
[['alias', 'title'], 'string'],
[['sort'], 'integer'],
[['sort'], 'integer', 'default' => 0],
[['extra'], 'validateExtra'],
[['alias', 'title'], 'string', 'max' => 255],
];
Expand Down
5 changes: 4 additions & 1 deletion src/models/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @property string $method
* @property string $path
* @property string $title
* @property int $sort
* @property string|null $extra
* @property int $created_at
* @property int|null $updated_at
Expand All @@ -44,8 +45,9 @@ public function rules()
['id', UuidValidator::class],
[['method', 'path', 'title'], 'required'],
[['extra'], 'safe'],
[['sort'], 'default', 'value' => 0],
[['created_at', 'updated_at'], 'default', 'value' => null],
[['created_at', 'updated_at'], 'integer'],
[['sort', 'created_at', 'updated_at'], 'integer'],
[['method'], 'string', 'max' => 10],
[['path', 'title'], 'string', 'max' => 255],
[['method', 'path'], 'unique', 'targetAttribute' => ['method', 'path']],
Expand All @@ -63,6 +65,7 @@ public function attributeLabels()
'method' => 'Method',
'path' => 'Path',
'title' => 'Title',
'sort' => 'Sort',
'extra' => 'Extra',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
Expand Down
5 changes: 4 additions & 1 deletion src/models/ApiGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @property bool $in_menu
* @property bool $is_system
* @property bool $is_secured
* @property int $sort
* @property string|null $extra
* @property int $created_at
* @property int|null $updated_at
Expand Down Expand Up @@ -51,8 +52,9 @@ public function rules()
[['alias', 'title'], 'required'],
[['in_menu', 'is_system', 'is_secured'], 'boolean'],
[['extra'], 'safe'],
[['sort'], 'default', 'value' => 0],
[['created_at', 'updated_at'], 'default', 'value' => null],
[['created_at', 'updated_at'], 'integer'],
[['sort', 'created_at', 'updated_at'], 'integer'],
[['alias', 'title'], 'string', 'max' => 255],
[['alias'], 'unique'],
[['id'], 'unique'],
Expand All @@ -71,6 +73,7 @@ public function attributeLabels()
'in_menu' => 'In Menu',
'is_system' => 'Is System',
'is_secured' => 'Is Secured',
'sort' => 'Sort',
'extra' => 'Extra',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
Expand Down
5 changes: 4 additions & 1 deletion src/models/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @property string $alias
* @property string $title
* @property bool $is_system
* @property int $sort
* @property string|null $extra
* @property int $created_at
* @property int|null $updated_at
Expand Down Expand Up @@ -45,8 +46,9 @@ public function rules()
[['alias', 'title'], 'required'],
[['is_system'], 'boolean'],
[['extra'], 'safe'],
[['sort'], 'default', 'value' => 0],
[['created_at', 'updated_at'], 'default', 'value' => null],
[['created_at', 'updated_at'], 'integer'],
[['sort', 'created_at', 'updated_at'], 'integer'],
[['alias', 'title'], 'string', 'max' => 255],
[['alias'], 'unique'],
[['id'], 'unique'],
Expand All @@ -63,6 +65,7 @@ public function attributeLabels()
'alias' => 'Alias',
'title' => 'Title',
'is_system' => 'Is System',
'sort' => 'Sort',
'extra' => 'Extra',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
Expand Down
5 changes: 4 additions & 1 deletion src/models/WorkerGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @property string $alias
* @property string $title
* @property bool $is_system
* @property int $sort
* @property string|null $extra
* @property int $created_at
* @property int|null $updated_at
Expand Down Expand Up @@ -47,8 +48,9 @@ public function rules()
[['alias', 'title'], 'required'],
[['is_system'], 'boolean'],
[['extra'], 'safe'],
[['sort'], 'default', 'value' => 0],
[['created_at', 'updated_at'], 'default', 'value' => null],
[['created_at', 'updated_at'], 'integer'],
[['sort', 'created_at', 'updated_at'], 'integer'],
[['alias', 'title'], 'string', 'max' => 255],
[['alias'], 'unique'],
[['id'], 'unique'],
Expand All @@ -65,6 +67,7 @@ public function attributeLabels()
'alias' => 'Alias',
'title' => 'Title',
'is_system' => 'Is System',
'sort' => 'Sort',
'extra' => 'Extra',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
Expand Down
9 changes: 9 additions & 0 deletions src/models/query/ApiGroupQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public function byWorkerGroup($workerGroupId)
return $this->andWhereExtended([$this->aliasColumn('id') => array_unique($apiGroupIds)]);
}

/**
* @param int $direction
* @return self
*/
public function sort(int $direction = SORT_ASC): self
{
return $this->orderBy(['sort' => $direction]);
}

/**
* @param Connection|null $db
* @return array|ApiGroup
Expand Down
9 changes: 9 additions & 0 deletions src/models/query/ApiQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public function byPath($path, bool $filter = false)
return $this->andWhereExtended([$this->aliasColumn('path') => $path], $filter);
}

/**
* @param int $direction
* @return self
*/
public function sort(int $direction = SORT_ASC): self
{
return $this->orderBy(['sort' => $direction]);
}

/**
* @param Connection|null $db
* @return array|Api
Expand Down
9 changes: 9 additions & 0 deletions src/models/query/RuleQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function byTitle($title, bool $filter = false)
return $this->andWhereExtended([$this->aliasColumn('title') => $title], $filter);
}

/**
* @param int $direction
* @return self
*/
public function sort(int $direction = SORT_ASC): self
{
return $this->orderBy(['sort' => $direction]);
}

/**
* @param Connection|null $db
* @return array|Rule
Expand Down
9 changes: 9 additions & 0 deletions src/models/query/WorkerGroupQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public function byRule($ruleId)
return $this->andWhereExtended([$this->aliasColumn('id') => $workerGroupIds]);
}

/**
* @param int $direction
* @return self
*/
public function sort(int $direction = SORT_ASC): self
{
return $this->orderBy(['sort' => $direction]);
}

/**
* @param Connection|null $db
* @return array|WorkerGroup
Expand Down

0 comments on commit 5055e8d

Please sign in to comment.