first change
This commit is contained in:
116
Modules/PMS/app/Repositories/TaskRepository.php
Normal file
116
Modules/PMS/app/Repositories/TaskRepository.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PMS\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\PMS\Models\KanbanColumn;
|
||||
use Modules\PMS\Models\Task;
|
||||
|
||||
class TaskRepository implements TaskInterface
|
||||
{
|
||||
public function findAll($filters = [], $limit = null, $offset = null)
|
||||
{
|
||||
return Task::when(true, function ($query) use ($filters) {
|
||||
$query->whereNull("parent_id");
|
||||
|
||||
if (isset($filters["search"])) {
|
||||
$search = $filters['search'];
|
||||
$query->whereAny(['title'], 'LIKE', "%$search%");
|
||||
}
|
||||
|
||||
if (isset($filters["status"])) {
|
||||
$query->where("status", $filters["status"]);
|
||||
}
|
||||
|
||||
if (isset($filters["priority"])) {
|
||||
$query->where("priority", $filters["priority"]);
|
||||
}
|
||||
|
||||
if (isset($filters["date"])) {
|
||||
$explodeDate = explode("to", $filters['date']);
|
||||
$query->whereBetween("start_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]);
|
||||
}
|
||||
|
||||
if (isset($filters["assigned_to"])) {
|
||||
$query->whereJsonContains("assigned_id->ids", (string) $filters['assigned_to']);
|
||||
}
|
||||
|
||||
if (auth()->user()->hasRole('employee')) {
|
||||
$assigned_id = auth()->user()->employee_id;
|
||||
$query->whereJsonContains("assigned_id->ids", (string) $assigned_id);
|
||||
}
|
||||
|
||||
})
|
||||
->with('assignedUser:id,first_name,middle_name,last_name,profile_picture')
|
||||
->latest()
|
||||
->limit($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getTaskById($TaskId)
|
||||
{
|
||||
return Task::findOrFail($TaskId);
|
||||
}
|
||||
|
||||
public function delete($TaskId)
|
||||
{
|
||||
Task::destroy($TaskId);
|
||||
}
|
||||
|
||||
public function create($TaskDetails)
|
||||
{
|
||||
return Task::create($TaskDetails);
|
||||
}
|
||||
|
||||
public function update($TaskId, array $newDetails)
|
||||
{
|
||||
return Task::whereId($TaskId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function pluck()
|
||||
{
|
||||
return Task::pluck(DB::raw('CONCAT(first_name," ", middle_name , " ",last_name) AS full_name'), 'id');
|
||||
}
|
||||
|
||||
public function getAllTasks($filters = [])
|
||||
{
|
||||
return Task::with('subTask')->when(true, function ($query) use ($filters) {
|
||||
$query->whereNull("parent_id");
|
||||
if (isset($filters["project_id"])) {
|
||||
$query->where("project_id", $filters["project_id"]);
|
||||
}
|
||||
|
||||
if (isset($filters["date"])) {
|
||||
$explodeDate = explode("to", $filters['date']);
|
||||
$query->whereBetween("start_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]);
|
||||
}
|
||||
|
||||
})
|
||||
// ->latest()
|
||||
->get();
|
||||
}
|
||||
|
||||
public function findAllWithRelations(array $relations = [], $limit = null)
|
||||
{
|
||||
$query = Task::with($relations);
|
||||
if ($limit) {
|
||||
$query->limit($limit);
|
||||
}
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function getTaskCountsByCategory($userId = null)
|
||||
{
|
||||
$query = KanbanColumn::select('category', DB::raw('COUNT(tbl_tasks.id) as task_count'))
|
||||
->leftJoin('tbl_tasks', 'kanban_columns.id', '=', 'tbl_tasks.status');
|
||||
|
||||
// Filter by user ID if provided
|
||||
if ($userId) {
|
||||
$query->whereJsonContains('tbl_tasks.assigned_id->ids', (string) $userId);
|
||||
}
|
||||
|
||||
return $query->groupBy('kanban_columns.category')->get();
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user