mirror of
https://github.com/Karaka-Management/oms-HumanResourceTimeRecording.git
synced 2026-02-12 10:58:39 +00:00
Draft simple session pagination
This commit is contained in:
parent
0cb87e39ed
commit
1f62c0d4e7
|
|
@ -43,6 +43,37 @@ use phpOMS\DataStorage\Database\RelationType;
|
||||||
*/
|
*/
|
||||||
final class ApiController extends Controller
|
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
|
* Api method to create a session
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\Views\View;
|
use phpOMS\Views\View;
|
||||||
use Modules\HumanResourceManagement\Models\EmployeeMapper;
|
use Modules\HumanResourceManagement\Models\EmployeeMapper;
|
||||||
use phpOMS\Stdlib\Base\SmartDateTime;
|
use phpOMS\Stdlib\Base\SmartDateTime;
|
||||||
|
use phpOMS\Views\PaginationView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TimeRecording controller class.
|
* TimeRecording controller class.
|
||||||
|
|
@ -79,11 +80,11 @@ final class BackendController extends Controller
|
||||||
$employee = EmployeeMapper::getFromAccount($request->getHeader()->getAccount())->getId();
|
$employee = EmployeeMapper::getFromAccount($request->getHeader()->getAccount())->getId();
|
||||||
$lastOpenSession = SessionMapper::getMostPlausibleOpenSessionForEmployee($employee);
|
$lastOpenSession = SessionMapper::getMostPlausibleOpenSessionForEmployee($employee);
|
||||||
|
|
||||||
$limit = new SmartDateTime('now');
|
$start = new SmartDateTime('now');
|
||||||
$limit = $limit->getEndOfMonth();
|
$limit = $start->getEndOfMonth();
|
||||||
$limit->smartModify(0, -2, 0);
|
$limit->smartModify(0, -2, 0);
|
||||||
|
|
||||||
$list = SessionMapper::getNewestForEmployee($employee, $limit);
|
$list = SessionMapper::getSessionListForEmployee($employee, $start, 0);
|
||||||
|
|
||||||
$view->addData('sessions', $list);
|
$view->addData('sessions', $list);
|
||||||
$view->addData('lastSession', $lastOpenSession);
|
$view->addData('lastSession', $lastOpenSession);
|
||||||
|
|
|
||||||
|
|
@ -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 int $employee Employee id
|
||||||
* @param \DateTime $start Sessions after this date
|
* @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 = new Builder(self::$db);
|
||||||
$query = self::getQuery($query)
|
$query = self::getQuery($query)
|
||||||
->where(self::$table . '.hr_timerecording_session_employee', '=', $employee)
|
->where(self::$table . '.hr_timerecording_session_employee', '=', $employee)
|
||||||
->andWhere(self::$table . '.' . self::$createdAt, '>', $start->format('Y-m-d'))
|
->andWhere(self::$table . '.' . self::$createdAt, '<=', $start->format('Y-m-d'))
|
||||||
->orderBy(self::$table . '.' . self::$createdAt, 'DESC');
|
->orderBy(self::$table . '.' . self::$createdAt, 'DESC')
|
||||||
|
->offset($offset)
|
||||||
|
->limit($limit);
|
||||||
|
|
||||||
$sth = self::$db->con->prepare($query->toSql());
|
$sth = self::$db->con->prepare($query->toSql());
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,8 @@ show additional section with vacation days
|
||||||
?>
|
?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<?= $this->getData('pagination')->render(); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Loading…
Reference in New Issue
Block a user