Добавлен order для отделений
This commit is contained in:
@@ -16,6 +16,7 @@ class Department extends Model
|
|||||||
'name_short',
|
'name_short',
|
||||||
'rf_mis_department_id',
|
'rf_mis_department_id',
|
||||||
'rf_department_type',
|
'rf_department_type',
|
||||||
|
'order',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function metrikaDefault()
|
public function metrikaDefault()
|
||||||
|
|||||||
@@ -38,12 +38,18 @@ class StatisticsService
|
|||||||
*/
|
*/
|
||||||
private function resolveUserDepartments(User $user)
|
private function resolveUserDepartments(User $user)
|
||||||
{
|
{
|
||||||
return Department::select('department_id', 'name_short', 'rf_department_type', 'user_name', 'order')
|
$departmentsTable = (new Department)->getTable();
|
||||||
|
$userDepartmentsTable = (new UserDepartment)->getTable();
|
||||||
|
|
||||||
|
return Department::select('department_id', 'name_short', 'rf_department_type', 'user_name')
|
||||||
->with('departmentType')
|
->with('departmentType')
|
||||||
->join((new UserDepartment)->getTable(), (new Department)->getTable().'.department_id', (new UserDepartment)->getTable().'.rf_department_id')
|
->join($userDepartmentsTable, "{$departmentsTable}.department_id", "{$userDepartmentsTable}.rf_department_id")
|
||||||
->where((new UserDepartment)->getTable().'.rf_user_id', $user->id)
|
->where("{$userDepartmentsTable}.rf_user_id", $user->id)
|
||||||
->orderBy('rf_department_type')
|
->orderBy('rf_department_type')
|
||||||
->orderBy((new UserDepartment)->getTable().'.order', 'asc')
|
// Персональный порядок пользователя приоритетнее общего порядка отделений;
|
||||||
|
// общий порядок — как запасной вариант (тай-брейк), если у пользователя порядок не задан.
|
||||||
|
->orderBy("{$userDepartmentsTable}.order", 'asc')
|
||||||
|
->orderBy("{$departmentsTable}.order", 'asc')
|
||||||
->get()
|
->get()
|
||||||
->groupBy('departmentType.name_full');
|
->groupBy('departmentType.name_full');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('departments', function (Blueprint $table) {
|
||||||
|
$table->integer('order')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('departments', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('order');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user