File: /mnt/data/ghayatcom/ghayatcom-api/app/Library/ActivityLibrary.php
<?php
namespace App\Library;
use Spatie\Activitylog\Models\Activity;
use DB;
class ActivityLibrary {
public function labelGet() {
return [
'vaccinationGet.name' => 'vaccination',
'alcoholConsumptionGet.name' => 'alcohol consumption',
'allergieGet.name' => 'allergie',
'dietaryRestrictionGet.name' => 'dietary restriction',
'medicalConditionGet.name' => 'medical condition',
'medicationGet.name' => 'medication',
'procedureGet.name' => 'procedure',
'recreationalDrugGet.name' => 'recreational drug',
'tobaccoUseGet.name' => 'tobacco use',
'prosthesisGet.name' => 'prosthesis',
];
}
public function propertyMsgRetrieve($properties, $action, $subject) {
$attributes = $properties['attributes'];
$arr = [];
foreach ($attributes as $key => $value) {
$nameAlternate = str_replace("_"," ",$key);
$labelResult = $this->labelGet();
if (array_key_exists($key, $labelResult)) {
$name = $labelResult[$key];
} else {
$name = $nameAlternate;
}
if($action == "created") {
if($subject == "App\HealthProfileProsthesis"){
$label = $name ." ".$value." Changed to YES";
}
else
$label = __('activity_log.created.value', [ 'name' => $name, 'value' => $value ]);
} else {
$old = $properties['old'];
$label = __('activity_log.updated.value', [ 'name' => $name, 'old' => $old[$key], 'new' => $value ]);
}
array_push($arr, $label);
}
return $arr;
}
}