Guillermo - add creatae log architecture [skip ci]
This commit is contained in:
parent
c7cdfd7318
commit
cab43cf5e0
|
@ -55,11 +55,10 @@ class AddStaffController extends Controller {
|
|||
|
||||
]);
|
||||
|
||||
$staff = Controller::getLoggedUser();
|
||||
Log::createLog('ADD_STAFF', $this->name);
|
||||
|
||||
$this->addOwner();
|
||||
|
||||
Log::createLog('ADD_STAFF', $this->name);
|
||||
|
||||
Response::respondSuccess([
|
||||
'id' => $staff->store()
|
||||
]);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
use RedBeanPHP\Facade as RedBean;
|
||||
|
||||
DataValidator::with('CustomValidations', true);
|
||||
|
||||
class DeleteStaffController extends Controller {
|
||||
|
@ -32,7 +34,7 @@ class DeleteStaffController extends Controller {
|
|||
$department->store();
|
||||
}
|
||||
|
||||
|
||||
RedBean::exec('DELETE FROM log WHERE author_staff_id = ?', [$staffId]);
|
||||
$staff->delete();
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
use RedBeanPHP\Facade as RedBean;
|
||||
|
||||
DataValidator::with('CustomValidations', true);
|
||||
|
||||
class DeleteUserController extends Controller {
|
||||
|
@ -22,7 +24,7 @@ class DeleteUserController extends Controller {
|
|||
$user = User::getDataStore($userId);
|
||||
|
||||
Log::createLog('DELETE_USER', $user->name);
|
||||
|
||||
RedBean::exec('DELETE FROM log WHERE author_user_id = ?', [$userId]);
|
||||
$user->delete();
|
||||
|
||||
Response::respondSuccess();
|
||||
|
|
|
@ -12,6 +12,7 @@ class Log extends DataStore {
|
|||
'to'
|
||||
];
|
||||
}
|
||||
|
||||
public static function createLog($type,$to, $author = null) {
|
||||
if($author === null) {
|
||||
$author = Controller::getLoggedUser();
|
||||
|
@ -20,17 +21,23 @@ class Log extends DataStore {
|
|||
|
||||
$log->setProperties(array(
|
||||
'type' => $type,
|
||||
'authorUser' => (!$author->isNull() && !$author->staff) ? $author : null,
|
||||
'authorStaff' => (!$author->isNull() && $author->staff) ? $author : null,
|
||||
'to' => $to,
|
||||
'to' => $to
|
||||
));
|
||||
|
||||
if($author instanceof User) {
|
||||
$log->authorUser = $author;
|
||||
} else {
|
||||
$log->authorStaff = $author;
|
||||
}
|
||||
|
||||
$log->store();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'to' => $this->to,
|
||||
'author' => ($this->authorUser) ? $this->authorUser->toArray() : $this->authorStaff->toArray()
|
||||
'author' => ($this->authorUser instanceof User) ? $this->authorUser->toArray() : $this->authorStaff->toArray()
|
||||
];
|
||||
}
|
||||
}
|
|
@ -28,4 +28,12 @@ class User extends DataStore {
|
|||
public static function getUser($value, $property = 'id') {
|
||||
return parent::getDataStore($value, $property);
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
'email' => $this->email,
|
||||
'id' => $this->id,
|
||||
'name' => $this->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue