> * @since 1.0.0 */ protected static array $columns = [ 'hr_timerecording_session_id' => ['name' => 'hr_timerecording_session_id', 'type' => 'int', 'internal' => 'id'], 'hr_timerecording_session_type' => ['name' => 'hr_timerecording_session_type', 'type' => 'int', 'internal' => 'type'], 'hr_timerecording_session_start' => ['name' => 'hr_timerecording_session_start', 'type' => 'DateTime', 'internal' => 'start'], 'hr_timerecording_session_end' => ['name' => 'hr_timerecording_session_end', 'type' => 'DateTime', 'internal' => 'end'], 'hr_timerecording_session_busy' => ['name' => 'hr_timerecording_session_busy', 'type' => 'int', 'internal' => 'busy'], 'hr_timerecording_session_employee' => ['name' => 'hr_timerecording_session_employee', 'type' => 'int', 'internal' => 'employee'], ]; /** * Has many relation. * * @var array> * @since 1.0.0 */ protected static array $hasMany = [ 'sessionElements' => [ 'mapper' => SessionElementMapper::class, 'table' => 'hr_timerecording_session_element', 'dst' => 'hr_timerecording_session_element_session', 'src' => null, ], ]; /** * Belongs to. * * @var array> * @since 1.0.0 */ protected static array $belongsTo = [ 'employee' => [ 'mapper' => EmployeeMapper::class, 'src' => 'hr_timerecording_session_employee', ], ]; /** * Primary table. * * @var string * @since 1.0.0 */ protected static string $table = 'hr_timerecording_session'; /** * Primary field name. * * @var string * @since 1.0.0 */ protected static string $primaryField = 'hr_timerecording_session_id'; /** * Created at column * * @var string * @since 1.0.0 */ protected static string $createdAt = 'hr_timerecording_session_start'; /** * Get last sessions from all employees * * @return array * * @todo: consider selecting only active employees * @todo: consider using a datetime to limit the results to look for * * @since 1.0.0 */ public static function getLastSessionsForDate(\DateTime $dt = null) : array { $join = new Builder(self::$db); $join->prefix(self::$db->getPrefix()) ->select(self::$table . '.hr_timerecording_session_employee') ->selectAs('MAX(hr_timerecording_session_start)', 'maxDate') ->from(self::$table) ->groupBy(self::$table . '.hr_timerecording_session_employee'); $query = new Builder(self::$db); $query->prefix(self::$db->getPrefix()) ->select('*')->fromAs(self::$table, 't') ->innerJoin($join, 'tm') ->on('t.hr_timerecording_session_employee', '=', 'tm.hr_timerecording_session_employee') ->andOn('t.hr_timerecording_session_start', '=', 'tm.maxDate'); return self::getAllByQuery($query, RelationType::ALL, 6); } }