Actionlog.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
8 
15 class Actionlog extends Model implements ICompanyableChild
16 {
17  use SoftDeletes;
19 
20  protected $dates = [ 'deleted_at' ];
21 
22  protected $table = 'asset_logs';
23  public $timestamps = true;
24  protected $fillable = [ 'created_at', 'asset_type' ];
25 
26  public function getCompanyableParents()
27  {
28  return [ 'accessorylog', 'assetlog', 'licenselog', 'consumablelog' ];
29  }
30 
31  public function assetlog()
32  {
33 
34  return $this->belongsTo('\App\Models\Asset', 'asset_id')
35  ->withTrashed();
36  }
37 
38  public function uploads()
39  {
40 
41  return $this->belongsTo('\App\Models\Asset', 'asset_id')
42  ->where('action_type', '=', 'uploaded')
43  ->withTrashed();
44  }
45 
46  public function licenselog()
47  {
48 
49  return $this->belongsTo('\App\Models\License', 'asset_id')
50  ->withTrashed();
51  }
52 
53  public function accessorylog()
54  {
55 
56  return $this->belongsTo('\App\Models\Accessory', 'accessory_id')
57  ->withTrashed();
58  }
59 
60  public function consumablelog()
61  {
62 
63  return $this->belongsTo('\App\Models\Consumable', 'consumable_id')
64  ->withTrashed();
65  }
66 
67  public function adminlog()
68  {
69 
70  return $this->belongsTo('\App\Models\User', 'user_id')
71  ->withTrashed();
72  }
73 
74  public function userlog()
75  {
76 
77  return $this->belongsTo('\App\Models\User', 'checkedout_to')
78  ->withTrashed();
79  }
80 
81  public function childlogs()
82  {
83 
84  return $this->hasMany('\App\Models\ActionLog', 'thread_id');
85  }
86 
87  public function parentlog()
88  {
89 
90  return $this->belongsTo('\App\Models\ActionLog', 'thread_id');
91  }
92 
96  public function get_src($type = 'assets')
97  {
98 
99  $file = config('app.private_uploads') . '/' . $type . '/' . $this->filename;
100 
101  return $file;
102 
103  }
104 
108  public function logaction($actiontype)
109  {
110 
111  $this->action_type = $actiontype;
112 
113  if ($this->save()) {
114  return true;
115  } else {
116  return false;
117  }
118  }
119 
128  {
129 
130  return DB::table('asset_logs')
131  ->select('*')
132  ->where('action_type', '!=', 'uploaded')
133  ->orderBy('asset_id', 'asc')
134  ->orderBy('created_at', 'asc')
135  ->get();
136  }
137 
146  {
147 
148  return DB::table('asset_logs')
149  ->select(DB::raw('asset_id, MAX(created_at) as last_created'))
150  ->where('action_type', '=', 'checkout')
151  ->groupBy('asset_id')
152  ->get();
153  }
154 
164  public function scopeCheckoutWithoutAcceptance($query)
165  {
166 
167  return $query->where('action_type', '=', 'checkout')
168  ->where('accepted_id', '=', null);
169  }
170 }
Model for the Actionlog (the table that keeps a historical log of checkouts, checkins, and updates).
Definition: Actionlog.php:15
getListingOfActionLogsChronologicalOrder()
getListingOfActionLogsChronologicalOrder
Definition: Actionlog.php:127
logaction($actiontype)
Get the parent category name.
Definition: Actionlog.php:108
scopeCheckoutWithoutAcceptance($query)
scopeCheckoutWithoutAcceptance
Definition: Actionlog.php:164
getLatestCheckoutActionForAssets()
getLatestCheckoutActionForAssets
Definition: Actionlog.php:145
get_src($type= 'assets')
Check if the file exists, and if it does, force a download.
Definition: Actionlog.php:96