firefly-iii/app/Repositories/AuditLogEntry/ALERepository.php

61 lines
1.8 KiB
PHP
Raw Normal View History

2022-10-02 07:37:50 -05:00
<?php
2022-10-16 12:29:53 -05:00
2022-10-02 07:37:50 -05:00
/*
* ALERepository.php
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2022-10-16 12:29:53 -05:00
declare(strict_types=1);
2022-10-02 07:37:50 -05:00
namespace FireflyIII\Repositories\AuditLogEntry;
use FireflyIII\Models\AuditLogEntry;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
/**
* Class ALERepository
*/
class ALERepository implements ALERepositoryInterface
{
2022-12-29 12:42:26 -06:00
/**
* @inheritDoc
*/
public function getForObject(Model $model): Collection
{
2022-12-31 06:32:42 -06:00
// all Models have an ID.
return AuditLogEntry::where('auditable_id', $model->id)->where('auditable_type', get_class($model))->get(); // @phpstan-ignore-line
2022-12-29 12:42:26 -06:00
}
2022-10-02 07:37:50 -05:00
/**
* @inheritDoc
*/
public function store(array $data): AuditLogEntry
{
2022-10-30 08:24:28 -05:00
$auditLogEntry = new AuditLogEntry();
2022-10-02 07:37:50 -05:00
$auditLogEntry->auditable()->associate($data['auditable']);
$auditLogEntry->changer()->associate($data['changer']);
2022-10-02 13:13:32 -05:00
$auditLogEntry->action = $data['action'];
2022-10-02 07:37:50 -05:00
$auditLogEntry->before = $data['before'];
$auditLogEntry->after = $data['after'];
$auditLogEntry->save();
return $auditLogEntry;
}
}