morphMany(Actionlog::class, 'item'); } /** * @author Daniel Meltzer determineLogItemType($log); $log->user_id = Auth::user()->id; if (!isset($target)) { throw new Exception('All checkout logs require a target'); return; } $log->target_type = get_class($target); $log->target_id = $target->id; // Figure out what the target is if ($log->target_type == Location::class) { $log->location_id = $target->id; } elseif ($log->target_type == Asset::class) { $log->location_id = $target->rtd_location_id; } else { $log->location_id = $target->location_id; } $log->note = $note; $log->logaction('checkout'); $params = [ 'item' => $log->item, 'target_type' => $log->target_type, 'target' => $target, 'admin' => $log->user, 'note' => $note, 'log_id' => $log->id, 'settings' => $settings, ]; // Send to the admin, if settings dictate $recipient = new \App\Models\Recipients\AdminRecipient(); if (method_exists($target, 'notify')) { $target->notify(new static::$checkoutClass($params)); } if ($settings->admin_cc_email!='') { $recipient->notify(new static::$checkoutClass($params)); } return $log; } /** * Helper method to determine the log item type */ private function determineLogItemType($log) { // We need to special case licenses because of license_seat vs license. So much for clean polymorphism : if (static::class == LicenseSeat::class) { $log->item_type = License::class; $log->item_id = $this->license_id; } else { $log->item_type = static::class; $log->item_id = $this->id; } return $log; } /** * @author Daniel Meltzer target_type = get_class($target); $log->target_id = $target->id; if (static::class == LicenseSeat::class) { $log->item_type = License::class; $log->item_id = $this->license_id; } else { $log->item_type = static::class; $log->item_id = $this->id; } $log->location_id = null; $log->note = $note; $log->user_id = Auth::user()->id; $log->logaction('checkin from'); $params = [ 'target' => $target, 'item' => $log->item, 'admin' => $log->user, 'note' => $note, 'target_type' => $log->target_type, 'settings' => $settings, ]; // Send to the admin, if settings dictate $recipient = new \App\Models\Recipients\AdminRecipient(); $checkoutClass = null; if (method_exists($target, 'notify')) { $target->notify(new static::$checkinClass($params)); } if ($settings->admin_cc_email!='') { $recipient->notify(new static::$checkinClass($params)); } return $log; } /** * @author A. Gianotto * @since [v4.0] * @return \App\Models\Actionlog */ public function logAudit($note, $location_id) { $log = new Actionlog; $location = Location::find($location_id); if (static::class == LicenseSeat::class) { $log->item_type = License::class; $log->item_id = $this->license_id; } else { $log->item_type = static::class; $log->item_id = $this->id; } $log->location_id = ($location_id) ? $location_id : null; $log->note = $note; $log->user_id = Auth::user()->id; $log->logaction('audit'); $params = [ 'item' => $log->item, 'admin' => $log->user, 'location' => ($location) ? $location->name : '', 'note' => $note ]; Setting::getSettings()->notify(new AuditNotification($params)); return $log; } /** * @author Daniel Meltzer id; } $log = new Actionlog; if (static::class == LicenseSeat::class) { $log->item_type = License::class; $log->item_id = $this->license_id; } else { $log->item_type = static::class; $log->item_id = $this->id; } $log->location_id = null; $log->note = $note; $log->user_id = $user_id; $log->logaction('create'); $log->save(); return $log; } /** * @author Daniel Meltzer item_type = License::class; $log->item_id = $this->license_id; } else { $log->item_type = static::class; $log->item_id = $this->id; } $log->user_id = Auth::user()->id; $log->note = $note; $log->target_id = null; $log->created_at = date("Y-m-d H:i:s"); $log->filename = $filename; $log->logaction('uploaded'); return $log; } }