Allow task attach search across global tasks
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TaskCollection extends Model
|
||||
{
|
||||
@@ -99,6 +100,27 @@ class TaskCollection extends Model
|
||||
return $value ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int|string> $taskIds
|
||||
*/
|
||||
public function reassignTasks(array $taskIds): void
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $taskIds)));
|
||||
|
||||
if ($ids === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('task_collection_task')
|
||||
->whereIn('task_id', $ids)
|
||||
->where('task_collection_id', '!=', $this->getKey())
|
||||
->delete();
|
||||
|
||||
Task::query()
|
||||
->whereIn('id', $ids)
|
||||
->update(['collection_id' => $this->getKey()]);
|
||||
}
|
||||
|
||||
protected function resolveTranslation(string $attribute, ?string $locale = null): string
|
||||
{
|
||||
$translations = $this->{$attribute} ?? [];
|
||||
|
||||
Reference in New Issue
Block a user