$members has_many VipsGroupMember * @property SimpleORMapCollection $current_members has_many VipsGroupMember * @property Course $course belongs_to Course */ class VipsGroup extends SimpleORMap { /** * Configure the database mapping. */ protected static function configure($config = []) { $config['db_table'] = 'statusgruppen'; $config['has_many']['members'] = [ 'class_name' => VipsGroupMember::class, 'assoc_foreign_key' => 'group_id', 'on_delete' => 'delete' ]; $config['has_many']['current_members'] = [ 'class_name' => VipsGroupMember::class, 'assoc_foreign_key' => 'group_id', 'order_by' => 'AND end IS NULL' ]; $config['belongs_to']['course'] = [ 'class_name' => Course::class, 'foreign_key' => 'range_id' ]; parent::configure($config); } /** * Get the group the user is currently assigned to in a course. * Returns null if there is no group assignment for this user. * * @param string $user_id user id * @param string $course_id course id */ public static function getUserGroup(string $user_id, string $course_id): ?VipsGroup { return self::findOneBySQL( 'JOIN etask_group_members ON group_id = statusgruppe_id WHERE range_id = ? AND user_id = ? AND end IS NULL', [$course_id, $user_id] ); } }