-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Intelrx\Rapidkit\Controller; | ||
use Illuminate\Routing\Controller; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class ActivityController extends Controller | ||
{ | ||
public function setup(){ | ||
File::mkdir(app_path('Traits')); | ||
$stubPath = dirname(__DIR__, 2) . '/src/stubs/config/HasActivityLog.stub'; | ||
$traitPath = app_path('Traits/Activitylog.php'); | ||
$stubContent = File::get($stubPath); | ||
if (!File::exists($traitPath)) { | ||
File::put($traitPath, $stubContent); | ||
} | ||
|
||
Artisan::call('vendor:publish', [ | ||
'--provider' => 'Spatie\Activitylog\ActivitylogServiceProvider', | ||
'--tag' => 'activitylog-migrations' | ||
]); | ||
Artisan::call('migrate'); | ||
Artisan::call("vendor:publish", [ | ||
"--provider" => "Spatie\Activitylog\ActivitylogServiceProvider", | ||
"--tag" => "activitylog-config" | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Intelrx\Rapidkit\Controller; | ||
use Illuminate\Routing\Controller; | ||
|
||
class BuildController extends Controller | ||
{ | ||
private $app_name; | ||
public function __construct($app_name = null) { | ||
$this->$app_name = $app_name; | ||
dd($this->$app_name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
|
||
class Config | ||
{ | ||
const VERSION = '1.7.5'; | ||
const VERSION = '1.8'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace App\Traits; | ||
|
||
use Carbon\Carbon; | ||
use Spatie\Activitylog\Traits\LogsActivity; | ||
use Spatie\Activitylog\LogOptions; | ||
use Spatie\Activitylog\Contracts\Activity; | ||
use Illuminate\Support\Facades\Auth; | ||
use Spatie\Activitylog\Models\Activity as ModelsActivity; | ||
use App\Http\Controllers\Controller; | ||
|
||
trait HasActivityLog | ||
{ | ||
use LogsActivity; | ||
|
||
public function getActivitylogOptions(): LogOptions | ||
{ | ||
return LogOptions::defaults()->logOnly(['*'])->logOnlyDirty(); | ||
} | ||
|
||
/** | ||
* activity logging description, causer name, and log name. | ||
* | ||
* @param String $activity_module | ||
* @param String $activity_column | ||
* @return void activityInfo ["activity_column" => ..., "activity_description" => ...]; | ||
* | ||
*/ | ||
public function tapActivity(Activity $activity, $eventName) | ||
{ | ||
try { | ||
if (method_exists($this, 'activityInfo')) { | ||
$info = $this->activityInfo(); | ||
$info["class"] = get_class($this); | ||
$info["description"] = $info["activity_description"]; | ||
} | ||
|
||
$user_name = Auth::user()->name ?? "GUST"; | ||
$data = $activity->subject[$this->activity_column]; | ||
|
||
switch ($eventName) { | ||
case 'created': | ||
$data = $activity->properties["attributes"][$this->activity_column]; | ||
break; | ||
|
||
case 'updated': | ||
if (isset($activity->properties['old'][$this->activity_column])) { | ||
$new_data = $activity->properties['attributes'][$this->activity_column] ?? 'NULL'; | ||
$data = $activity->properties['old'][$this->activity_column] ." to ". $new_data; | ||
} | ||
break; | ||
|
||
default: | ||
$data = $activity->properties['old'][$this->activity_column] ?? $data; | ||
break; | ||
} | ||
$activity->description = "$user_name has $eventName " . ($info["description"] ?? " $data ") . " on $this->activity_module"; | ||
$activity->causer_name = $user_name; | ||
$activity->log_name = $this->activity_module; | ||
} | ||
catch (\Exception $e) { | ||
throw $e; | ||
} | ||
} | ||
|
||
/** | ||
* Loads the audit data for a given ID. | ||
* | ||
* @param int $id The ID of the subject. | ||
* @return Illuminate\Support\Collection The transformed audit data. | ||
*/ | ||
public function getAudit(int $id){ | ||
try{ | ||
$data = ModelsActivity::orderby('id', 'desc')->where(function ($query) use ($id) { | ||
$query->where('subject_id', $id); | ||
$query->where('log_name', $this->activity_module); | ||
})->get(); | ||
|
||
return collect($data->toArray())->transform(function($item){ | ||
$carbon_format = 'Y-m-d h:i A'; | ||
foreach (["attributes", "old"] as $key => $value) { | ||
if (isset($item["properties"][$value]['updated_at'])) { | ||
$item["properties"][$value]["updated_at"] = Carbon::parse($item["properties"][$value]["updated_at"])->format($carbon_format); | ||
} | ||
if (isset($item["properties"][$value]['created_at'])) { | ||
$item["properties"][$value]["created_at"] = Carbon::parse($item["properties"][$value]["created_at"])->format($carbon_format); | ||
} | ||
} | ||
$item["created_at"] = Carbon::parse($item["created_at"])->format($carbon_format); | ||
$item["updated_at"] = Carbon::parse($item["updated_at"])->format($carbon_format); | ||
$item["log_name"] = $this->activity_module; | ||
$item["module_name"] = $this->activity_module; | ||
return $item; | ||
}); | ||
} | ||
catch (\Exception $e) { | ||
throw $e; | ||
} | ||
} | ||
} |