File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Employees/EmployeeService.php
<?php
namespace App\Komma\Employees;
use App\Komma\Departments\DepartmentService;
use App\Komma\Departments\Models\Department;
use App\Komma\Employees\Models\Employee;
class EmployeeService
{
/**
* Base query for get employees from DB
*
* @return Employee|\Illuminate\Database\Eloquent\Builder
*/
private function baseEmployeeQuery()
{
return Employee::with('translation', 'images')
->where('active', 1);
}
/**
* Get collection of all employees
*
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function getAllEmployees() {
$employees = $this->baseEmployeeQuery()->orderBy('lft');
return $employees->get();
}
/**
* Get employees grouped by their department_id
*
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function getEmployeesByDepartment() {
$departmentService = new DepartmentService();
$departmentWithEmployees = $departmentService->getDepartmentsWithEmployees();
// Move the first batch of employees to the end (no specific department is set on them)
$departmentWithEmployees->push($departmentWithEmployees->shift());
return $departmentWithEmployees;
}
}