49 'start_date' =>
'datetime',
50 'end_date' =>
'datetime',
51 'enabled' =>
'boolean' 64 parent::__construct($attributes);
65 self::creating(
function($model) {
66 if ($model->slug === null) {
67 $model->slug = Str::slug($model->name);
69 if($model->user_id === null && ($user = app(UserAuthentication::class)->getUser()) !== null) {
70 $model->user_id = $user->controlId();
82 return $this->hasMany(ModuleInstance::class);
93 return $query->where(
'enabled',
true);
103 return $this->belongsTo(Logic::class,
'for_logic');
113 return $this->belongsTo(Logic::class,
'admin_logic');
126 ->where([
'start_date' => null,
'end_date'=>null])
128 [
'start_date',
'<=', Carbon::now()],
129 [
'end_date',
'>=', Carbon::now()]
141 return $this->type ===
'completable' || $this->type ===
'multi-completable';
151 return $this->hasMany(ActivityInstance::class);
160 public function user(): \BristolSU\ControlDB\Contracts\Models\User
162 if($this->user_id === null) {
163 throw new \Exception(sprintf(
'Activity #%u is not owned by a user.', $this->
id));
165 return app(User::class)->getById($this->user_id);
scopeEnabled(Builder $query)
scopeActive(Builder $query)
__construct(array $attributes=[])