The open cards are kept in the user's board preferences (expanded_cards, at most 500), saved without redrawing the board and restored on return. Co-Authored-By: Claude Opus 5.5 <[email protected]>
55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
|
|
|
use App\Modules\Jobs\Domain\Contracts\BoardRepository;
|
|
use App\Modules\Jobs\Domain\ValueObjects\BoardPreferences;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\JobBoardPreferenceModel;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Card order and pins are plain column updates: they are board state, not
|
|
* job details, so they bypass the job entity and its change history.
|
|
*/
|
|
class EloquentBoardRepository implements BoardRepository
|
|
{
|
|
public function setJobPositions(array $positions): void
|
|
{
|
|
foreach ($positions as $jobId => $position) {
|
|
DB::table('customer_jobs')->where('id', $jobId)->update(['board_position' => $position]);
|
|
}
|
|
}
|
|
|
|
public function setTaskPositions(array $positions): void
|
|
{
|
|
foreach ($positions as $taskId => $position) {
|
|
DB::table('tasks')->where('id', $taskId)->update(['board_position' => $position]);
|
|
}
|
|
}
|
|
|
|
public function setTaskPinned(int $taskId, bool $pinned): void
|
|
{
|
|
DB::table('tasks')->where('id', $taskId)->update(['is_pinned_to_board' => $pinned]);
|
|
}
|
|
|
|
public function preferencesOf(int $userId): BoardPreferences
|
|
{
|
|
$model = JobBoardPreferenceModel::query()->where('user_id', $userId)->first();
|
|
|
|
return $model === null
|
|
? BoardPreferences::defaults()
|
|
: BoardPreferences::fromStored($model->density, $model->urgent_threshold, $model->column_colors ?? [], $model->column_sorts ?? [], $model->expanded_cards ?? []);
|
|
}
|
|
|
|
public function savePreferences(int $userId, BoardPreferences $preferences): void
|
|
{
|
|
JobBoardPreferenceModel::query()->updateOrCreate(['user_id' => $userId], [
|
|
'density' => $preferences->density->value,
|
|
'urgent_threshold' => $preferences->urgentThreshold->value,
|
|
'column_colors' => $preferences->colorValues(),
|
|
'column_sorts' => $preferences->sortValues(),
|
|
'expanded_cards' => $preferences->expandedCards,
|
|
]);
|
|
}
|
|
}
|