Bristol SU Support Package
ActivityInstance.php
Go to the documentation of this file.
1 <?php
2 
4 
10 use BristolSU\ControlDB\Contracts\Repositories\Group as GroupRepository;
11 use BristolSU\ControlDB\Contracts\Repositories\Role as RoleRepository;
16 
20 class ActivityInstance extends Model implements Authenticatable
21 {
22  use HasRevisions;
23 
32  protected $appends = ['run_number', 'participant'];
33 
39  protected $fillable = [
40  'name', 'description', 'activity_id', 'resource_type', 'resource_id'
41  ];
42 
50  public function getRunNumberAttribute()
51  {
52  $activityInstances = static::newQuery()
53  ->where('activity_id', $this->activity_id)
54  ->where('resource_type', $this->resource_type)
55  ->where('resource_id', $this->resource_id)
56  ->orderBy('created_at')
57  ->get();
58  if ($activityInstances->count() > 0) {
59  for ($i = 0; $i <= $activityInstances->count(); $i++) {
60  if ($this->is($activityInstances->offsetGet($i))) {
61  return $i + 1;
62  }
63  }
64  }
65  return 1;
66  }
67 
79  public function getParticipantAttribute()
80  {
81  if ($this->resource_type === 'user') {
82  return app(UserRepository::class)->getById($this->resource_id);
83  }
84  if ($this->resource_type === 'group') {
85  return app(GroupRepository::class)->getById($this->resource_id);
86  }
87  if ($this->resource_type === 'role') {
88  return app(RoleRepository::class)->getById($this->resource_id);
89  }
90  throw new \Exception('Resource type is not valid');
91  }
92 
100  public function participant()
101  {
102  return $this->participant;
103  }
104 
110  public function moduleInstances()
111  {
112  return $this->hasManyThrough(ModuleInstance::class, Activity::class, 'id', 'activity_id', 'activity_id', 'id');
113  }
114 
120  public function activity()
121  {
122  return $this->belongsTo(Activity::class);
123  }
124 
130  public function getAuthIdentifierName()
131  {
132  return 'id';
133  }
134 
140  public function getAuthIdentifier()
141  {
142  return $this->id;
143  }
144 
150  public function getAuthPassword()
151  {
152  }
153 
159  public function getRememberToken()
160  {
161  }
162 
169  public function setRememberToken($value)
170  {
171  }
172 
178  public function getRememberTokenName()
179  {
180  }
181 }