diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 177a218..be67543 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -43,6 +43,37 @@ use phpOMS\DataStorage\Database\RelationType; */ final class ApiController extends Controller { + /** + * Api method to get multiple sessions for an employee + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiSessionsListForEmployeeGet(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + $account = (int) ($request->getData('account') ?? $request->getHeader()->getAccount()); + + if ($request->getData('account') !== null) { + if (!$this->app->accountManager->get($request->getHeader()->getAccount())->hasPermission( + PermissionType::GET, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::SESSION_FOREIGN + )) { + $this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', []); + } + } + + $employee = EmployeeMapper::getFromAccount($account); + + $sessions = SessionMapper::getSessionListForEmployee($employee->getId(), (int) ($request->getData('session') ?? 0), 50); + $this->fillJsonResponse($request, $response, NotificationLevel::HIDDEN, '', '', $sessions); + } + /** * Api method to create a session * diff --git a/Controller/BackendController.php b/Controller/BackendController.php index c08e77b..d50ca85 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -22,6 +22,7 @@ use phpOMS\Message\ResponseAbstract; use phpOMS\Views\View; use Modules\HumanResourceManagement\Models\EmployeeMapper; use phpOMS\Stdlib\Base\SmartDateTime; +use phpOMS\Views\PaginationView; /** * TimeRecording controller class. @@ -79,11 +80,11 @@ final class BackendController extends Controller $employee = EmployeeMapper::getFromAccount($request->getHeader()->getAccount())->getId(); $lastOpenSession = SessionMapper::getMostPlausibleOpenSessionForEmployee($employee); - $limit = new SmartDateTime('now'); - $limit = $limit->getEndOfMonth(); + $start = new SmartDateTime('now'); + $limit = $start->getEndOfMonth(); $limit->smartModify(0, -2, 0); - $list = SessionMapper::getNewestForEmployee($employee, $limit); + $list = SessionMapper::getSessionListForEmployee($employee, $start, 0); $view->addData('sessions', $list); $view->addData('lastSession', $lastOpenSession); diff --git a/Models/SessionMapper.php b/Models/SessionMapper.php index 387d165..d0b7696 100644 --- a/Models/SessionMapper.php +++ b/Models/SessionMapper.php @@ -166,18 +166,26 @@ final class SessionMapper extends DataMapperAbstract } /** - * Get newest sessions for employee + * Get sessions for employee * - * @param int $employee Employee to get the sessions for - * @param \DateTime $start Sessions after this date + * @param int $employee Employee id + * @param \DateTime $start Start + * @param int $offset Offset + * @param int $limit Result limit + * + * @return Session[] + * + * @since 1.0.0 */ - public static function getNewestForEmployee(int $employee, \DateTime $start) : array + public static function getSessionListForEmployee(int $employee, \DateTime $start, int $offset = 0, int $limit = 50) : array { $query = new Builder(self::$db); $query = self::getQuery($query) ->where(self::$table . '.hr_timerecording_session_employee', '=', $employee) - ->andWhere(self::$table . '.' . self::$createdAt, '>', $start->format('Y-m-d')) - ->orderBy(self::$table . '.' . self::$createdAt, 'DESC'); + ->andWhere(self::$table . '.' . self::$createdAt, '<=', $start->format('Y-m-d')) + ->orderBy(self::$table . '.' . self::$createdAt, 'DESC') + ->offset($offset) + ->limit($limit); $sth = self::$db->con->prepare($query->toSql()); $sth->execute(); diff --git a/Theme/Backend/private-dashboard.tpl.php b/Theme/Backend/private-dashboard.tpl.php index c3fd024..f6061d1 100644 --- a/Theme/Backend/private-dashboard.tpl.php +++ b/Theme/Backend/private-dashboard.tpl.php @@ -172,6 +172,8 @@ show additional section with vacation days ?> + + getData('pagination')->render(); ?> \ No newline at end of file