2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* Model for the Actionlog (the table that keeps a historical log of
|
|
|
|
* checkouts, checkins, and updates).
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class Actionlog extends Model implements ICompanyableChild
|
|
|
|
{
|
|
|
|
use SoftDeletes;
|
|
|
|
use CompanyableChildTrait;
|
|
|
|
|
|
|
|
protected $dates = [ 'deleted_at' ];
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
protected $table = 'action_logs';
|
2016-03-25 01:18:05 -07:00
|
|
|
public $timestamps = true;
|
2016-09-06 19:39:42 -07:00
|
|
|
protected $fillable = [ 'created_at', 'item_type','user_id','item_id','action_type','note','target_id', 'target_type' ];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
public function getCompanyableParents()
|
|
|
|
{
|
|
|
|
return [ 'accessorylog', 'assetlog', 'licenselog', 'consumablelog' ];
|
|
|
|
}
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
// Eloquent Relationships below
|
|
|
|
public function item()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->morphTo('item')->withTrashed();
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
public function itemType()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-09-20 00:45:25 -07:00
|
|
|
|
2016-09-15 19:58:27 -07:00
|
|
|
if($this->item_type == AssetModel::class) {
|
|
|
|
return "model";
|
|
|
|
}
|
2016-09-06 19:39:42 -07:00
|
|
|
return camel_case(class_basename($this->item_type));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
public function uploads()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->morphTo('item')
|
|
|
|
->where('action_type', '=', 'uploaded')
|
2016-03-25 01:18:05 -07:00
|
|
|
->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
public function userlog()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->target();
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
public function user()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->belongsTo(User::class, 'user_id')
|
2016-03-25 01:18:05 -07:00
|
|
|
->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
public function target()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->morphTo('target');
|
2016-08-02 05:06:17 -07:00
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
public function childlogs()
|
|
|
|
{
|
|
|
|
return $this->hasMany('\App\Models\ActionLog', 'thread_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function parentlog()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('\App\Models\ActionLog', 'thread_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the file exists, and if it does, force a download
|
|
|
|
**/
|
2016-03-25 17:20:28 -07:00
|
|
|
public function get_src($type = 'assets')
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
$file = config('app.private_uploads') . '/' . $type . '/' . $this->filename;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
return $file;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the parent category name
|
|
|
|
*/
|
|
|
|
public function logaction($actiontype)
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->action_type = $actiontype;
|
|
|
|
|
|
|
|
if ($this->save()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getListingOfActionLogsChronologicalOrder
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
|
|
|
public function getListingOfActionLogsChronologicalOrder()
|
|
|
|
{
|
|
|
|
|
2016-09-06 19:39:42 -07:00
|
|
|
return $this->all()
|
2016-03-25 01:18:05 -07:00
|
|
|
->where('action_type', '!=', 'uploaded')
|
2016-09-06 19:39:42 -07:00
|
|
|
->orderBy('item_id', 'asc')
|
2016-03-25 01:18:05 -07:00
|
|
|
->orderBy('created_at', 'asc')
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
}
|