mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 11:18:51 +02:00
Fixed coding style.
This commit is contained in:
parent
0a94689d98
commit
f2ff77a8b3
44 changed files with 435 additions and 387 deletions
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
|
@ -24,8 +25,10 @@ declare(strict_types=1);
|
|||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Base\DBElement;
|
||||
use App\Entity\Devices\Device;
|
||||
use App\Entity\Devices\DevicePart;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
|
@ -36,13 +39,11 @@ use App\Entity\UserSystem\Group;
|
|||
use App\Entity\UserSystem\User;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Devices\DevicePart;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
/**
|
||||
* This entity describes a entry in the event log.
|
||||
* @package App\Entity\LogSystem
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\LogEntryRepository")
|
||||
* @ORM\Table("log")
|
||||
* @ORM\InheritanceType("SINGLE_TABLE")
|
||||
|
@ -97,7 +98,6 @@ abstract class AbstractLogEntry extends DBElement
|
|||
self::LEVEL_DEBUG => LogLevel::DEBUG,
|
||||
];
|
||||
|
||||
|
||||
protected const TARGET_CLASS_MAPPING = [
|
||||
self::TARGET_TYPE_USER => User::class,
|
||||
self::TARGET_TYPE_ATTACHEMENT => Attachment::class,
|
||||
|
@ -113,7 +113,7 @@ abstract class AbstractLogEntry extends DBElement
|
|||
self::TARGET_TYPE_SUPPLIER => Supplier::class,
|
||||
];
|
||||
|
||||
/** @var User $user The user which has caused this log entry
|
||||
/** @var User The user which has caused this log entry
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User")
|
||||
* @ORM\JoinColumn(name="id_user", nullable=false)
|
||||
*/
|
||||
|
@ -124,17 +124,17 @@ abstract class AbstractLogEntry extends DBElement
|
|||
*/
|
||||
protected $timestamp;
|
||||
|
||||
/** @var integer The priority level of the associated level. 0 is highest, 7 lowest
|
||||
/** @var int The priority level of the associated level. 0 is highest, 7 lowest
|
||||
* @ORM\Column(type="integer", name="level", columnDefinition="TINYINT")
|
||||
*/
|
||||
protected $level;
|
||||
|
||||
/** @var int $target_id The ID of the element targeted by this event
|
||||
/** @var int The ID of the element targeted by this event
|
||||
* @ORM\Column(name="target_id", type="integer", nullable=false)
|
||||
*/
|
||||
protected $target_id = 0;
|
||||
|
||||
/** @var int $target_type The Type of the targeted element
|
||||
/** @var int The Type of the targeted element
|
||||
* @ORM\Column(name="target_type", type="smallint", nullable=false)
|
||||
*/
|
||||
protected $target_type = 0;
|
||||
|
@ -143,7 +143,7 @@ abstract class AbstractLogEntry extends DBElement
|
|||
* The mapping between the log entry class and the discriminator column is done by doctrine.
|
||||
* Each subclass should override this string to specify a better string.
|
||||
*/
|
||||
protected $typeString = "unknown";
|
||||
protected $typeString = 'unknown';
|
||||
|
||||
/** @var array The extra data in raw (short form) saved in the DB
|
||||
* @ORM\Column(name="extra", type="json")
|
||||
|
@ -158,6 +158,7 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* Get the user that caused the event associated with this log entry.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): ?User
|
||||
|
@ -167,17 +168,19 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* Sets the user that caused the event.
|
||||
* @param User $user
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser(User $user): self
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp when the event that caused this log entry happened
|
||||
* Returns the timestamp when the event that caused this log entry happened.
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getTimestamp(): DateTime
|
||||
|
@ -187,18 +190,20 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* Sets the timestamp when the event happened.
|
||||
* @param DateTime $timestamp
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimestamp(DateTime $timestamp): AbstractLogEntry
|
||||
public function setTimestamp(DateTime $timestamp): self
|
||||
{
|
||||
$this->timestamp = $timestamp;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the priority level of this log entry. 0 is highest and 7 lowest level.
|
||||
* See LEVEL_* consts in this class for more info
|
||||
* See LEVEL_* consts in this class for more info.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel(): int
|
||||
|
@ -207,25 +212,28 @@ abstract class AbstractLogEntry extends DBElement
|
|||
if ($this->level < 0 || $this->level > 7) {
|
||||
return self::LEVEL_ALERT;
|
||||
}
|
||||
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new level of this log entry.
|
||||
* @param int $level
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLevel(int $level): AbstractLogEntry
|
||||
public function setLevel(int $level): self
|
||||
{
|
||||
if ($level < 0 || $this->level > 7) {
|
||||
throw new \InvalidArgumentException(sprintf('$level must be between 0 and 7! %d given!', $level));
|
||||
}
|
||||
$this->level = $level;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the priority level of this log entry as PSR3 compatible string
|
||||
* Get the priority level of this log entry as PSR3 compatible string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLevelString(): string
|
||||
|
@ -234,18 +242,20 @@ abstract class AbstractLogEntry extends DBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the priority level of this log entry as PSR3 compatible string
|
||||
* @param string $level
|
||||
* Sets the priority level of this log entry as PSR3 compatible string.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLevelString(string $level): AbstractLogEntry
|
||||
public function setLevelString(string $level): self
|
||||
{
|
||||
$this->setLevel(self::levelStringToInt($level));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the event this log entry is associated with.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
|
@ -253,22 +263,20 @@ abstract class AbstractLogEntry extends DBElement
|
|||
return $this->typeString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return "LOG".$this->getID();
|
||||
return 'LOG'.$this->getID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name of the target element associated with this log entry.
|
||||
* Returns null, if this log entry is not associated with an log entry.
|
||||
*
|
||||
* @return string|null The class name of the target class.
|
||||
*/
|
||||
public function getTargetClass(): ?string
|
||||
{
|
||||
if ($this->target_type === self::TARGET_TYPE_NONE) {
|
||||
if (self::TARGET_TYPE_NONE === $this->target_type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -278,11 +286,12 @@ abstract class AbstractLogEntry extends DBElement
|
|||
/**
|
||||
* Returns the ID of the target element associated with this log entry.
|
||||
* Returns null, if this log entry is not associated with an log entry.
|
||||
*
|
||||
* @return int|null The ID of the associated element.
|
||||
*/
|
||||
public function getTargetID(): ?int
|
||||
{
|
||||
if ($this->target_id === 0) {
|
||||
if (0 === $this->target_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -290,24 +299,28 @@ abstract class AbstractLogEntry extends DBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if this log entry is associated with an element
|
||||
* Checks if this log entry is associated with an element.
|
||||
*
|
||||
* @return bool True if this log entry is associated with an element, false otherwise.
|
||||
*/
|
||||
public function hasTarget(): bool
|
||||
{
|
||||
return $this->getTargetID() !== null && $this->getTargetClass() !== null;
|
||||
return null !== $this->getTargetID() && null !== $this->getTargetClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target element associated with this element
|
||||
* @param DBElement $element The element that should be associated with this element.
|
||||
* Sets the target element associated with this element.
|
||||
*
|
||||
* @param DBElement $element The element that should be associated with this element.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTargetElement(?DBElement $element): self
|
||||
{
|
||||
if ($element === null) {
|
||||
if (null === $element) {
|
||||
$this->target_id = 0;
|
||||
$this->target_type = self::TARGET_TYPE_NONE;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -324,12 +337,14 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* This function converts the internal numeric log level into an PSR3 compatible level string.
|
||||
* @param int $level The numerical log level
|
||||
*
|
||||
* @param int $level The numerical log level
|
||||
*
|
||||
* @return string The PSR3 compatible level string
|
||||
*/
|
||||
final public static function levelIntToString(int $level): string
|
||||
{
|
||||
if (!isset(self::LEVEL_ID_TO_STRING[$level])) {
|
||||
if (! isset(self::LEVEL_ID_TO_STRING[$level])) {
|
||||
throw new \InvalidArgumentException('No level with this int is existing!');
|
||||
}
|
||||
|
||||
|
@ -338,13 +353,15 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* This function converts a PSR3 compatible string to the internal numeric level string.
|
||||
*
|
||||
* @param string $level the PSR3 compatible string that should be converted
|
||||
*
|
||||
* @return int The internal int representation.
|
||||
*/
|
||||
final public static function levelStringToInt(string $level): int
|
||||
{
|
||||
$tmp = array_flip(self::LEVEL_ID_TO_STRING);
|
||||
if (!isset($tmp[$level])) {
|
||||
if (! isset($tmp[$level])) {
|
||||
throw new \InvalidArgumentException('No level with this string is existing!');
|
||||
}
|
||||
|
||||
|
@ -353,12 +370,14 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* Converts an target type id to an full qualified class name.
|
||||
* @param int $type_id The target type ID
|
||||
*
|
||||
* @param int $type_id The target type ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final public static function targetTypeIdToClass(int $type_id): string
|
||||
{
|
||||
if (!isset(self::TARGET_CLASS_MAPPING[$type_id])) {
|
||||
if (! isset(self::TARGET_CLASS_MAPPING[$type_id])) {
|
||||
throw new \InvalidArgumentException('No target type with this ID is existing!');
|
||||
}
|
||||
|
||||
|
@ -367,7 +386,9 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
/**
|
||||
* Convert a class name to a target type ID.
|
||||
* @param string $class The name of the class (FQN) that should be converted to id
|
||||
*
|
||||
* @param string $class The name of the class (FQN) that should be converted to id
|
||||
*
|
||||
* @return int The ID of the associated target type ID.
|
||||
*/
|
||||
final public static function targetTypeClassToID(string $class): int
|
||||
|
@ -387,6 +408,4 @@ abstract class AbstractLogEntry extends DBElement
|
|||
|
||||
throw new \InvalidArgumentException('No target ID for this class is existing!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -26,14 +29,13 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @package App\Entity\LogSystem
|
||||
*/
|
||||
class ConfigChangedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "config_changed";
|
||||
protected $typeString = 'config_changed';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
throw new LogEntryObsoleteException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,7 +24,6 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Exceptions\LogEntryObsoleteException;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +31,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class DatabaseUpdatedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "database_updated";
|
||||
protected $typeString = 'database_updated';
|
||||
|
||||
public function __construct(string $oldVersion, string $newVersion)
|
||||
{
|
||||
|
@ -40,6 +42,7 @@ class DatabaseUpdatedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Checks if the database update was successful.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful(): bool
|
||||
|
@ -50,6 +53,7 @@ class DatabaseUpdatedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Gets the database version before update.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOldVersion(): string
|
||||
|
@ -59,11 +63,11 @@ class DatabaseUpdatedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Gets the (target) database version after update.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNewVersion(): string
|
||||
{
|
||||
return (string) $this->extra['n'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,19 +24,18 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @package App\Entity\LogSystem
|
||||
*/
|
||||
class ElementCreatedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "element_created";
|
||||
protected $typeString = 'element_created';
|
||||
|
||||
/**
|
||||
* Gets the instock when the part was created
|
||||
* Gets the instock when the part was created.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCreationInstockValue(): ?int
|
||||
|
@ -43,10 +45,11 @@ class ElementCreatedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Checks if a creation instock value was saved with this entry.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCreationInstockValue(): bool
|
||||
{
|
||||
return $this->getCreationInstockValue() !== null;
|
||||
return null !== $this->getCreationInstockValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,7 +24,6 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
|
@ -29,10 +31,10 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class ElementDeletedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "element_deleted";
|
||||
protected $typeString = 'element_deleted';
|
||||
|
||||
public function getOldName(): string
|
||||
{
|
||||
return $this->extra['n'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -25,18 +28,18 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @package App\Entity\LogSystem
|
||||
*/
|
||||
class ElementEditedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "element_edited";
|
||||
protected $typeString = 'element_edited';
|
||||
|
||||
/**
|
||||
* Returns the message associated with this edit change
|
||||
* Returns the message associated with this edit change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage() : string
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->extra['m'] ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,13 +24,11 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
|
||||
use App\Exceptions\LogEntryObsoleteException;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @package App\Entity\LogSystem
|
||||
*/
|
||||
class ExceptionLogEntry extends AbstractLogEntry
|
||||
{
|
||||
|
@ -40,15 +41,17 @@ class ExceptionLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* The class name of the exception that caused this log entry.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExceptionClass(): string
|
||||
{
|
||||
return $this->extra['t'] ?? "Unknown Class";
|
||||
return $this->extra['t'] ?? 'Unknown Class';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file where the exception happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFile(): string
|
||||
|
@ -57,7 +60,8 @@ class ExceptionLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the line where the exception happened
|
||||
* Returns the line where the exception happened.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLine(): int
|
||||
|
@ -67,11 +71,11 @@ class ExceptionLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Return the message of the exception.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->extra['m'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,20 +24,18 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @package App\Entity\LogSystem
|
||||
*/
|
||||
class InstockChangedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "instock_changed";
|
||||
protected $typeString = 'instock_changed';
|
||||
|
||||
/**
|
||||
* Get the old instock
|
||||
* Get the old instock.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOldInstock(): int
|
||||
|
@ -43,7 +44,8 @@ class InstockChangedLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the new instock
|
||||
* Get the new instock.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNewInstock(): int
|
||||
|
@ -52,7 +54,8 @@ class InstockChangedLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the comment associated with the instock change
|
||||
* Gets the comment associated with the instock change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment(): string
|
||||
|
@ -62,7 +65,9 @@ class InstockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Returns the price that has to be payed for the change (in the base currency).
|
||||
* @param $absolute bool Set this to true, if you want only get the absolute value of the price (without minus)
|
||||
*
|
||||
* @param bool $absolute Set this to true, if you want only get the absolute value of the price (without minus)
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPrice(bool $absolute = false): float
|
||||
|
@ -70,18 +75,21 @@ class InstockChangedLogEntry extends AbstractLogEntry
|
|||
if ($absolute) {
|
||||
return abs($this->extra['p']);
|
||||
}
|
||||
|
||||
return $this->extra['p'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference value of the change ($new_instock - $old_instock).
|
||||
* @param $absolute bool Set this to true if you want only the absolute value of the difference.
|
||||
*
|
||||
* @param bool $absolute Set this to true if you want only the absolute value of the difference.
|
||||
*
|
||||
* @return int Difference is positive if instock has increased, negative if decreased.
|
||||
*/
|
||||
public function getDifference(bool $absolute = false): int
|
||||
{
|
||||
// Check if one of the instock values is unknown
|
||||
if ($this->getNewInstock() == -2 || $this->getOldInstock() == -2) {
|
||||
if (-2 === $this->getNewInstock() || -2 === $this->getOldInstock()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -95,11 +103,11 @@ class InstockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Checks if the Change was an withdrawal of parts.
|
||||
*
|
||||
* @return bool True if the change was an withdrawal, false if not.
|
||||
*/
|
||||
public function isWithdrawal(): bool
|
||||
{
|
||||
return $this->getNewInstock() < $this->getOldInstock();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -26,12 +29,12 @@ use Symfony\Component\HttpFoundation\IpUtils;
|
|||
|
||||
/**
|
||||
* This log entry is created when a user logs in.
|
||||
* @package App\Entity\LogSystem
|
||||
*
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class UserLoginLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "user_login";
|
||||
protected $typeString = 'user_login';
|
||||
|
||||
public function __construct(string $ip_address, bool $anonymize = true)
|
||||
{
|
||||
|
@ -42,6 +45,7 @@ class UserLoginLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Return the (anonymized) IP address used to login the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIPAddress(): string
|
||||
|
@ -50,9 +54,11 @@ class UserLoginLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the IP address used to login the user
|
||||
* @param string $ip The IP address used to login the user.
|
||||
* @param bool $anonymize Anonymize the IP address (remove last block) to be GPDR compliant
|
||||
* Sets the IP address used to login the user.
|
||||
*
|
||||
* @param string $ip The IP address used to login the user.
|
||||
* @param bool $anonymize Anonymize the IP address (remove last block) to be GPDR compliant
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIPAddress(string $ip, bool $anonymize = true): self
|
||||
|
@ -62,6 +68,7 @@ class UserLoginLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
$this->extra['i'] = $ip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,17 +24,15 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
/**
|
||||
* @ORM\Entity()
|
||||
* @package App\Entity\LogSystem
|
||||
*/
|
||||
class UserLogoutLogEntry extends AbstractLogEntry
|
||||
{
|
||||
protected $typeString = "user_logout";
|
||||
protected $typeString = 'user_logout';
|
||||
|
||||
public function __construct(string $ip_address, bool $anonymize = true)
|
||||
{
|
||||
|
@ -42,6 +43,7 @@ class UserLogoutLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Return the (anonymized) IP address used to login the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIPAddress(): string
|
||||
|
@ -50,9 +52,11 @@ class UserLogoutLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the IP address used to login the user
|
||||
* @param string $ip The IP address used to login the user.
|
||||
* @param bool $anonymize Anonymize the IP address (remove last block) to be GPDR compliant
|
||||
* Sets the IP address used to login the user.
|
||||
*
|
||||
* @param string $ip The IP address used to login the user.
|
||||
* @param bool $anonymize Anonymize the IP address (remove last block) to be GPDR compliant
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setIPAddress(string $ip, bool $anonymize = true): self
|
||||
|
@ -62,8 +66,7 @@ class UserLogoutLogEntry extends AbstractLogEntry
|
|||
}
|
||||
|
||||
$this->extra['i'] = $ip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -21,12 +24,10 @@
|
|||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
|
||||
use App\Exceptions\LogEntryObsoleteException;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @package App\Entity\LogSystem
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class UserNotAllowedLogEntry extends AbstractLogEntry
|
||||
|
@ -43,4 +44,4 @@ class UserNotAllowedLogEntry extends AbstractLogEntry
|
|||
{
|
||||
return $this->extra['p'] ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue