mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-13 15:01:02 -08:00
2d8269ddcd
* Create a new action_log table to replace asset_log. Use Polymorphism to generalize class and targets. Port everything I can find to use it. Add a migration to port the asset_logs table to action_logs. * Initial work on requestable asset models * Backend work for polymorphic requests table to store checkout requests. * Add missing files * Add a record to the db when requesting items. Build up a testing route for interfacing with this. * Users can now toggle requests of items on the request page. Reformat page to use the same tab layout we use elsewhere * Polymorphic request function. Implement requesting of asset models. Need to port mail/slack to notifications still. * Implement requesting of asset models. Build up emails and notifications to support it. Allow specifying a quantity of model to request. * Add view to show currently requested assets. Needs some work and cleanup, but it isn't accessible from anywhere yet.
124 lines
2.8 KiB
PHP
Executable file
124 lines
2.8 KiB
PHP
Executable file
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Model for the Actionlog (the table that keeps a historical log of
|
|
* checkouts, checkins, and updates).
|
|
*
|
|
* @version v1.0
|
|
*/
|
|
class Actionlog extends Model implements ICompanyableChild
|
|
{
|
|
use SoftDeletes;
|
|
use CompanyableChildTrait;
|
|
|
|
protected $dates = [ 'deleted_at' ];
|
|
|
|
protected $table = 'action_logs';
|
|
public $timestamps = true;
|
|
protected $fillable = [ 'created_at', 'item_type','user_id','item_id','action_type','note','target_id', 'target_type' ];
|
|
|
|
public function getCompanyableParents()
|
|
{
|
|
return [ 'accessorylog', 'assetlog', 'licenselog', 'consumablelog' ];
|
|
}
|
|
|
|
// Eloquent Relationships below
|
|
public function item()
|
|
{
|
|
return $this->morphTo('item')->withTrashed();
|
|
}
|
|
|
|
public function itemType()
|
|
{
|
|
// dd($this);
|
|
if($this->item_type == AssetModel::class) {
|
|
return "model";
|
|
}
|
|
return camel_case(class_basename($this->item_type));
|
|
}
|
|
|
|
public function uploads()
|
|
{
|
|
|
|
return $this->morphTo('item')
|
|
->where('action_type', '=', 'uploaded')
|
|
->withTrashed();
|
|
}
|
|
|
|
public function userlog()
|
|
{
|
|
return $this->target();
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id')
|
|
->withTrashed();
|
|
}
|
|
|
|
public function target()
|
|
{
|
|
return $this->morphTo('target');
|
|
}
|
|
|
|
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
|
|
**/
|
|
public function get_src($type = 'assets')
|
|
{
|
|
|
|
$file = config('app.private_uploads') . '/' . $type . '/' . $this->filename;
|
|
|
|
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()
|
|
{
|
|
|
|
return $this->all()
|
|
->where('action_type', '!=', 'uploaded')
|
|
->orderBy('item_id', 'asc')
|
|
->orderBy('created_at', 'asc')
|
|
->get();
|
|
}
|
|
}
|