HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;

    }

}