VipsAssignment::class, 'assoc_foreign_key' => 'block_id' ]; $config['belongs_to']['course'] = [ 'class_name' => Course::class, 'foreign_key' => 'range_id' ]; $config['belongs_to']['group'] = [ 'class_name' => Statusgruppen::class, 'foreign_key' => 'group_id' ]; parent::configure($config); } /** * Delete entry from the database. */ public function delete() { foreach ($this->assignments as $assignment) { $assignment->block_id = null; $assignment->store(); } return parent::delete(); } /** * Check if this block is visible to this user. */ public function isVisible(string $user_id): bool { $visible = $this->visible; if ($visible && $this->group_id) { $visible = StatusgruppeUser::exists([$this->group_id, $user_id]); } return $visible; } /** * Get the first assignment attempt of the given user for this block. * Returns null if there is no assignment attempt for this user. * * @param string $user_id user id */ public function getAssignmentAttempt(string $user_id): ?VipsAssignmentAttempt { $assignment_ids = $this->assignments->pluck('id'); return VipsAssignmentAttempt::findOneBySQL( 'assignment_id IN (?) AND user_id = ? ORDER BY start', [$assignment_ids, $user_id] ); } }