mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 19:58:53 +02:00
Allow to add a comment when editing/creating/deleting an element.
This commit is contained in:
parent
c14d6d91ff
commit
b6f95ebe48
19 changed files with 421 additions and 47 deletions
45
src/Entity/Contracts/LogWithCommentInterface.php
Normal file
45
src/Entity/Contracts/LogWithCommentInterface.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\Contracts;
|
||||
|
||||
|
||||
interface LogWithCommentInterface
|
||||
{
|
||||
/**
|
||||
* Checks if this log entry has a user provided comment.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasComment(): bool;
|
||||
|
||||
/**
|
||||
* Gets the user provided comment associated with this log entry.
|
||||
* Returns null if not comment was set.
|
||||
* @return string|null
|
||||
*/
|
||||
public function getComment(): ?string;
|
||||
|
||||
/**
|
||||
* Sets the user provided comment associated with this log entry.
|
||||
* @param string|null $new_comment
|
||||
* @return $this
|
||||
*/
|
||||
public function setComment(?string $new_comment): self;
|
||||
}
|
|
@ -43,12 +43,13 @@ declare(strict_types=1);
|
|||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\LogWithCommentInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementCreatedLogEntry extends AbstractLogEntry
|
||||
class ElementCreatedLogEntry extends AbstractLogEntry implements LogWithCommentInterface
|
||||
{
|
||||
protected $typeString = 'element_created';
|
||||
|
||||
|
@ -78,4 +79,29 @@ class ElementCreatedLogEntry extends AbstractLogEntry
|
|||
{
|
||||
return null !== $this->getCreationInstockValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function hasComment(): bool
|
||||
{
|
||||
return isset($this->extra['m']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->extra['m'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setComment(?string $new_comment): LogWithCommentInterface
|
||||
{
|
||||
$this->extra['m'] = $new_comment;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ declare(strict_types=1);
|
|||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\LogWithCommentInterface;
|
||||
use App\Entity\Contracts\NamedElementInterface;
|
||||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -50,7 +51,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInterface
|
||||
class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface
|
||||
{
|
||||
protected $typeString = 'element_deleted';
|
||||
|
||||
|
@ -111,4 +112,29 @@ class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInter
|
|||
{
|
||||
return $this->extra['d'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function hasComment(): bool
|
||||
{
|
||||
return isset($this->extra['m']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->extra['m'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setComment(?string $new_comment): LogWithCommentInterface
|
||||
{
|
||||
$this->extra['m'] = $new_comment;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,14 @@ declare(strict_types=1);
|
|||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Contracts\LogWithCommentInterface;
|
||||
use App\Entity\Contracts\TimeTravelInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface
|
||||
class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterface, LogWithCommentInterface
|
||||
{
|
||||
protected $typeString = 'element_edited';
|
||||
|
||||
|
@ -72,16 +73,6 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message associated with this edit change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->extra['m'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@ -97,4 +88,29 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
|
|||
{
|
||||
return $this->extra['d'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function hasComment(): bool
|
||||
{
|
||||
return isset($this->extra['m']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->extra['m'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setComment(?string $new_comment): LogWithCommentInterface
|
||||
{
|
||||
$this->extra['m'] = $new_comment;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue