mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-26 19:58:53 +02:00
Applied symplify rules to codebase.
This commit is contained in:
parent
2f20d90041
commit
388e847b17
136 changed files with 1370 additions and 789 deletions
|
@ -26,6 +26,9 @@ namespace App\Entity\Attachments;
|
|||
use App\Entity\Base\NamedDBElement;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use function in_array;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
|
||||
/**
|
||||
* Class Attachment.
|
||||
|
@ -65,7 +68,9 @@ abstract class Attachment extends NamedDBElement
|
|||
*/
|
||||
public const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%', '%SECURE%'];
|
||||
|
||||
/** @var array Placeholders for attachments which using built in files. */
|
||||
/**
|
||||
* @var array Placeholders for attachments which using built in files.
|
||||
*/
|
||||
public const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%'];
|
||||
|
||||
/**
|
||||
|
@ -74,10 +79,10 @@ abstract class Attachment extends NamedDBElement
|
|||
public const ALLOWED_ELEMENT_CLASS = '';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
* @var string the original filename the file had, when the user uploaded it
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $show_in_table = false;
|
||||
protected $original_filename;
|
||||
|
||||
/**
|
||||
* @var string The path to the file relative to a placeholder path like %MEDIA%
|
||||
|
@ -85,17 +90,17 @@ abstract class Attachment extends NamedDBElement
|
|||
*/
|
||||
protected $path = '';
|
||||
|
||||
/**
|
||||
* @var string the original filename the file had, when the user uploaded it
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $original_filename;
|
||||
|
||||
/**
|
||||
* ORM mapping is done in sub classes (like PartAttachment).
|
||||
*/
|
||||
protected $element;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $show_in_table = false;
|
||||
|
||||
/**
|
||||
* @var AttachmentType
|
||||
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="attachments_with_type")
|
||||
|
@ -108,7 +113,7 @@ abstract class Attachment extends NamedDBElement
|
|||
{
|
||||
//parent::__construct();
|
||||
if ('' === static::ALLOWED_ELEMENT_CLASS) {
|
||||
throw new \LogicException('An *Attachment class must override the ALLOWED_ELEMENT_CLASS const!');
|
||||
throw new LogicException('An *Attachment class must override the ALLOWED_ELEMENT_CLASS const!');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +137,7 @@ abstract class Attachment extends NamedDBElement
|
|||
|
||||
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
|
||||
|
||||
return \in_array(strtolower($extension), static::PICTURE_EXTS, true);
|
||||
return in_array(strtolower($extension), static::PICTURE_EXTS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,7 +153,7 @@ abstract class Attachment extends NamedDBElement
|
|||
|
||||
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
|
||||
|
||||
return \in_array(strtolower($extension), static::MODEL_EXTS, true);
|
||||
return in_array(strtolower($extension), static::MODEL_EXTS, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,7 +175,7 @@ abstract class Attachment extends NamedDBElement
|
|||
return true;
|
||||
}
|
||||
|
||||
return ! \in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
|
||||
return ! in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,7 +368,7 @@ abstract class Attachment extends NamedDBElement
|
|||
public function setElement(AttachmentContainingDBElement $element): self
|
||||
{
|
||||
if (! is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
|
||||
throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
|
||||
throw new InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
|
||||
}
|
||||
|
||||
$this->element = $element;
|
||||
|
@ -406,7 +411,7 @@ abstract class Attachment extends NamedDBElement
|
|||
//Only set if the URL is not empty
|
||||
if (! empty($url)) {
|
||||
if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) {
|
||||
throw new \InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
|
||||
throw new InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
|
||||
}
|
||||
|
||||
$this->path = $url;
|
||||
|
@ -437,7 +442,7 @@ abstract class Attachment extends NamedDBElement
|
|||
return false;
|
||||
}
|
||||
|
||||
return \in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
|
||||
return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,7 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
|
|||
*
|
||||
* Mapping is done in sub classes like part
|
||||
*/
|
||||
protected $attachments;
|
||||
protected $attachments = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
|
@ -37,18 +37,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class AttachmentType extends StructuralDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection|AttachmentTypeAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\AttachmentTypeAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @var Collection|Attachment[]
|
||||
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachment_type")
|
||||
*/
|
||||
protected $attachments_with_type;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent", cascade={"persist"})
|
||||
*/
|
||||
|
@ -66,6 +54,17 @@ class AttachmentType extends StructuralDBElement
|
|||
* @ValidFileFilter
|
||||
*/
|
||||
protected $filetype_filter = '';
|
||||
/**
|
||||
* @var Collection|AttachmentTypeAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\AttachmentTypeAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @var Collection|Attachment[]
|
||||
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachment_type")
|
||||
*/
|
||||
protected $attachments_with_type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ declare(strict_types=1);
|
|||
namespace App\Entity\Base;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use function is_string;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
|
@ -157,7 +158,7 @@ abstract class Company extends PartsContainingDBElement
|
|||
*/
|
||||
public function getAutoProductUrl($partnr = null): string
|
||||
{
|
||||
if (\is_string($partnr)) {
|
||||
if (is_string($partnr)) {
|
||||
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,13 @@ namespace App\Entity\Base;
|
|||
|
||||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Validator\Constraints\NoneOfItsChildren;
|
||||
use function count;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use function get_class;
|
||||
use InvalidArgumentException;
|
||||
use function is_array;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
|
@ -50,23 +54,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
{
|
||||
public const ID_ROOT_ELEMENT = 0;
|
||||
|
||||
/** This is a not standard character, so build a const, so a dev can easily use it */
|
||||
/**
|
||||
* This is a not standard character, so build a const, so a dev can easily use it
|
||||
*/
|
||||
public const PATH_DELIMITER_ARROW = ' → ';
|
||||
|
||||
/**
|
||||
* We can not define the mapping here or we will get an exception. Unfortunately we have to do the mapping in the
|
||||
* subclasses
|
||||
* @var StructuralDBElement[]
|
||||
* @Groups({"include_children"})
|
||||
*/
|
||||
protected $children;
|
||||
/**
|
||||
* @var StructuralDBElement
|
||||
* @NoneOfItsChildren()
|
||||
* @Groups({"include_parents"})
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @var string The comment info for this element
|
||||
* @ORM\Column(type="text")
|
||||
|
@ -86,10 +78,25 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
*/
|
||||
protected $level = 0;
|
||||
|
||||
/**
|
||||
* We can not define the mapping here or we will get an exception. Unfortunately we have to do the mapping in the
|
||||
* subclasses.
|
||||
*
|
||||
* @var StructuralDBElement[]
|
||||
* @Groups({"include_children"})
|
||||
*/
|
||||
protected $children = [];
|
||||
/**
|
||||
* @var StructuralDBElement
|
||||
* @NoneOfItsChildren()
|
||||
* @Groups({"include_parents"})
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/** @var string[] all names of all parent elements as a array of strings,
|
||||
* the last array element is the name of the element itself
|
||||
*/
|
||||
private $full_path_strings;
|
||||
private $full_path_strings = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -109,7 +116,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return bool True, if this element is child of $another_element.
|
||||
*
|
||||
* @throws \InvalidArgumentException if there was an error
|
||||
* @throws InvalidArgumentException if there was an error
|
||||
*/
|
||||
public function isChildOf(self $another_element): bool
|
||||
{
|
||||
|
@ -117,8 +124,8 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
|
||||
//Check if both elements compared, are from the same type
|
||||
// (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
|
||||
if (! is_a($another_element, $class_name) && ! is_a($this, \get_class($another_element))) {
|
||||
throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!');
|
||||
if (! is_a($another_element, $class_name) && ! is_a($this, get_class($another_element))) {
|
||||
throw new InvalidArgumentException('isChildOf() only works for objects of the same type!');
|
||||
}
|
||||
|
||||
if (null === $this->getParent()) { // this is the root node
|
||||
|
@ -201,7 +208,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
*/
|
||||
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
|
||||
{
|
||||
if (! \is_array($this->full_path_strings)) {
|
||||
if (empty($this->full_path_strings)) {
|
||||
$this->full_path_strings = [];
|
||||
$this->full_path_strings[] = $this->getName();
|
||||
$element = $this;
|
||||
|
@ -233,7 +240,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
$tmp[] = $this;
|
||||
|
||||
//We only allow 20 levels depth
|
||||
while (! end($tmp)->isRoot() && \count($tmp) < 20) {
|
||||
while (! end($tmp)->isRoot() && count($tmp) < 20) {
|
||||
$tmp[] = end($tmp)->parent;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Base;
|
||||
|
||||
use DateTime;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
|
@ -32,14 +33,14 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
trait TimestampTrait
|
||||
{
|
||||
/**
|
||||
* @var \DateTime the date when this element was modified the last time
|
||||
* @var DateTime the date when this element was modified the last time
|
||||
* @ORM\Column(type="datetime", name="last_modified", options={"default"="CURRENT_TIMESTAMP"})
|
||||
* @Groups({"extended", "full"})
|
||||
*/
|
||||
protected $lastModified;
|
||||
|
||||
/**
|
||||
* @var \DateTime the date when this element was created
|
||||
* @var DateTime the date when this element was created
|
||||
* @ORM\Column(type="datetime", name="datetime_added", options={"default"="CURRENT_TIMESTAMP"})
|
||||
* @Groups({"extended", "full"})
|
||||
*/
|
||||
|
@ -49,9 +50,9 @@ trait TimestampTrait
|
|||
* Returns the last time when the element was modified.
|
||||
* Returns null if the element was not yet saved to DB yet.
|
||||
*
|
||||
* @return \DateTime|null the time of the last edit
|
||||
* @return DateTime|null the time of the last edit
|
||||
*/
|
||||
public function getLastModified(): ?\DateTime
|
||||
public function getLastModified(): ?DateTime
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
|
@ -60,9 +61,9 @@ trait TimestampTrait
|
|||
* Returns the date/time when the element was created.
|
||||
* Returns null if the element was not yet saved to DB yet.
|
||||
*
|
||||
* @return \DateTime|null the creation time of the part
|
||||
* @return DateTime|null the creation time of the part
|
||||
*/
|
||||
public function getAddedDate(): ?\DateTime
|
||||
public function getAddedDate(): ?DateTime
|
||||
{
|
||||
return $this->addedDate;
|
||||
}
|
||||
|
@ -75,9 +76,9 @@ trait TimestampTrait
|
|||
*/
|
||||
public function updatedTimestamps(): void
|
||||
{
|
||||
$this->lastModified = new \DateTime('now');
|
||||
$this->lastModified = new DateTime('now');
|
||||
if (null === $this->addedDate) {
|
||||
$this->addedDate = new \DateTime('now');
|
||||
$this->addedDate = new DateTime('now');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ use App\Entity\Attachments\DeviceAttachment;
|
|||
use App\Entity\Base\PartsContainingDBElement;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Class AttachmentType.
|
||||
|
@ -64,12 +65,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class Device extends PartsContainingDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection|DeviceAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\DeviceAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Device", mappedBy="parent")
|
||||
*/
|
||||
|
@ -81,6 +76,11 @@ class Device extends PartsContainingDBElement
|
|||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="DevicePart", mappedBy="device")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
|
@ -92,11 +92,11 @@ class Device extends PartsContainingDBElement
|
|||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $order_only_missing_parts = false;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="DevicePart", mappedBy="device")
|
||||
* @var Collection|DeviceAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\DeviceAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $parts;
|
||||
protected $attachments;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
|
@ -140,7 +140,7 @@ class Device extends PartsContainingDBElement
|
|||
public function setOrderQuantity(int $new_order_quantity): self
|
||||
{
|
||||
if ($new_order_quantity < 0) {
|
||||
throw new \InvalidArgumentException('The new order quantity must not be negative!');
|
||||
throw new InvalidArgumentException('The new order quantity must not be negative!');
|
||||
}
|
||||
$this->order_quantity = $new_order_quantity;
|
||||
|
||||
|
|
|
@ -63,6 +63,17 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class DevicePart extends DBElement
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", name="quantity")
|
||||
*/
|
||||
protected $quantity;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="text", name="mountnames")
|
||||
*/
|
||||
protected $mountnames;
|
||||
/**
|
||||
* @var Device
|
||||
* @ORM\ManyToOne(targetEntity="Device", inversedBy="parts")
|
||||
|
@ -77,18 +88,6 @@ class DevicePart extends DBElement
|
|||
*/
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", name="quantity")
|
||||
*/
|
||||
protected $quantity;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="text", name="mountnames")
|
||||
*/
|
||||
protected $mountnames;
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
|
|
|
@ -36,12 +36,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class Category extends PartsContainingDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection|CategoryAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CategoryAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
*/
|
||||
|
@ -105,6 +99,11 @@ class Category extends PartsContainingDBElement
|
|||
* @ORM\Column(type="text")
|
||||
*/
|
||||
protected $default_comment = '';
|
||||
/**
|
||||
* @var Collection|CategoryAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CategoryAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
|
|
|
@ -65,26 +65,25 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
class Footprint extends PartsContainingDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection|FootprintAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\FootprintAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $attachments;
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Footprint", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="footprint", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection|FootprintAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\FootprintAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @var FootprintAttachment|null
|
||||
|
|
|
@ -65,26 +65,25 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
class Manufacturer extends Company
|
||||
{
|
||||
/**
|
||||
* @var Collection|ManufacturerAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $attachments;
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="manufacturer", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection|ManufacturerAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
|
|
|
@ -41,12 +41,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
*/
|
||||
class MeasurementUnit extends PartsContainingDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection|MeasurementUnitAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for grams)
|
||||
* or m (for meters).
|
||||
|
@ -84,6 +78,11 @@ class MeasurementUnit extends PartsContainingDBElement
|
|||
* @ORM\OneToMany(targetEntity="Part", mappedBy="partUnit", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection|MeasurementUnitAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
|
|
|
@ -60,6 +60,7 @@ use App\Entity\Parts\PartTraits\InstockTrait;
|
|||
use App\Entity\Parts\PartTraits\ManufacturerTrait;
|
||||
use App\Entity\Parts\PartTraits\OrderTrait;
|
||||
use App\Security\Annotations\ColumnSecurity;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
@ -82,7 +83,9 @@ class Part extends AttachmentContainingDBElement
|
|||
use ManufacturerTrait;
|
||||
use OrderTrait;
|
||||
|
||||
/** TODO */
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
protected $devices;
|
||||
|
||||
/**
|
||||
|
@ -91,16 +94,9 @@ class Part extends AttachmentContainingDBElement
|
|||
*/
|
||||
protected $addedDate;
|
||||
|
||||
/**
|
||||
* @var \DateTime the date when this element was modified the last time
|
||||
* @ColumnSecurity(type="datetime")
|
||||
* @ORM\Column(type="datetime", name="last_modified", options={"default"="CURRENT_TIMESTAMP"})
|
||||
*/
|
||||
protected $lastModified;
|
||||
|
||||
/** *************************************************************
|
||||
* Overridden properties
|
||||
* (They are defined here and not in a trait, to avoid conflicts)
|
||||
* (They are defined here and not in a trait, to avoid conflicts).
|
||||
****************************************************************/
|
||||
|
||||
/**
|
||||
|
@ -117,6 +113,13 @@ class Part extends AttachmentContainingDBElement
|
|||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @var DateTime the date when this element was modified the last time
|
||||
* @ColumnSecurity(type="datetime")
|
||||
* @ORM\Column(type="datetime", name="last_modified", options={"default"="CURRENT_TIMESTAMP"})
|
||||
*/
|
||||
protected $lastModified;
|
||||
|
||||
/**
|
||||
* @var Attachment
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\Attachment")
|
||||
|
|
|
@ -29,7 +29,9 @@ use App\Entity\Base\TimestampTrait;
|
|||
use App\Entity\Parts\PartTraits\InstockTrait;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use App\Validator\Constraints\ValidPartLot;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Exception;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
|
@ -58,8 +60,8 @@ class PartLot extends DBElement
|
|||
protected $comment = '';
|
||||
|
||||
/**
|
||||
* @var ?\DateTime Set a time until when the lot must be used.
|
||||
* Set to null, if the lot can be used indefinitely.
|
||||
* @var ?DateTime Set a time until when the lot must be used.
|
||||
* Set to null, if the lot can be used indefinitely.
|
||||
* @ORM\Column(type="datetime", name="expiration_date", nullable=true)
|
||||
*/
|
||||
protected $expiration_date;
|
||||
|
@ -72,14 +74,6 @@ class PartLot extends DBElement
|
|||
*/
|
||||
protected $storage_location;
|
||||
|
||||
/**
|
||||
* @var Part The part that is stored in this lot
|
||||
* @ORM\ManyToOne(targetEntity="Part", inversedBy="partLots")
|
||||
* @ORM\JoinColumn(name="id_part", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* @var bool If this is set to true, the instock amount is marked as not known
|
||||
* @ORM\Column(type="boolean")
|
||||
|
@ -99,6 +93,14 @@ class PartLot extends DBElement
|
|||
*/
|
||||
protected $needs_refill = false;
|
||||
|
||||
/**
|
||||
* @var Part The part that is stored in this lot
|
||||
* @ORM\ManyToOne(targetEntity="Part", inversedBy="partLots")
|
||||
* @ORM\JoinColumn(name="id_part", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
|
@ -116,7 +118,7 @@ class PartLot extends DBElement
|
|||
*
|
||||
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
|
||||
*
|
||||
* @throws \Exception If an error with the DateTime occurs
|
||||
* @throws Exception If an error with the DateTime occurs
|
||||
*/
|
||||
public function isExpired(): ?bool
|
||||
{
|
||||
|
@ -125,7 +127,7 @@ class PartLot extends DBElement
|
|||
}
|
||||
|
||||
//Check if the expiration date is bigger then current time
|
||||
return $this->expiration_date < new \DateTime('now');
|
||||
return $this->expiration_date < new DateTime('now');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,9 +177,9 @@ class PartLot extends DBElement
|
|||
/**
|
||||
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function getExpirationDate(): ?\DateTime
|
||||
public function getExpirationDate(): ?DateTime
|
||||
{
|
||||
return $this->expiration_date;
|
||||
}
|
||||
|
@ -185,11 +187,11 @@ class PartLot extends DBElement
|
|||
/**
|
||||
* Sets the expiration date for the part lot. Set to null, if the part lot does not expires.
|
||||
*
|
||||
* @param \DateTime $expiration_date
|
||||
* @param DateTime $expiration_date
|
||||
*
|
||||
* @return PartLot
|
||||
*/
|
||||
public function setExpirationDate(?\DateTime $expiration_date): self
|
||||
public function setExpirationDate(?DateTime $expiration_date): self
|
||||
{
|
||||
$this->expiration_date = $expiration_date;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Entity\Parts\PartTraits;
|
|||
|
||||
use App\Entity\PriceInformations\Orderdetail;
|
||||
use App\Security\Annotations\ColumnSecurity;
|
||||
use function count;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
|
@ -183,7 +184,7 @@ trait OrderTrait
|
|||
{
|
||||
$all_orderdetails = $this->getOrderdetails();
|
||||
|
||||
if (0 === \count($all_orderdetails)) {
|
||||
if (0 === count($all_orderdetails)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,12 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class Storelocation extends PartsContainingDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection|StorelocationAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Storelocation", mappedBy="parent")
|
||||
*/
|
||||
|
@ -81,6 +75,22 @@ class Storelocation extends PartsContainingDBElement
|
|||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @var MeasurementUnit|null The measurement unit, which parts can be stored in here
|
||||
* @ORM\ManyToOne(targetEntity="MeasurementUnit")
|
||||
* @ORM\JoinColumn(name="storage_type_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $storage_type;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinTable(name="part_lots",
|
||||
* joinColumns={@ORM\JoinColumn(name="id_store_location", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="id_part", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
|
@ -98,22 +108,11 @@ class Storelocation extends PartsContainingDBElement
|
|||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $limit_to_existing_parts = false;
|
||||
|
||||
/**
|
||||
* @var MeasurementUnit|null The measurement unit, which parts can be stored in here
|
||||
* @ORM\ManyToOne(targetEntity="MeasurementUnit")
|
||||
* @ORM\JoinColumn(name="storage_type_id", referencedColumnName="id")
|
||||
* @var Collection|StorelocationAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $storage_type;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinTable(name="part_lots",
|
||||
* joinColumns={@ORM\JoinColumn(name="id_store_location", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="id_part", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
protected $parts;
|
||||
protected $attachments;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
|
|
|
@ -67,12 +67,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
*/
|
||||
class Supplier extends Company
|
||||
{
|
||||
/**
|
||||
* @var Collection|SupplierAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\SupplierAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Supplier", mappedBy="parent")
|
||||
*/
|
||||
|
@ -113,6 +107,11 @@ class Supplier extends Company
|
|||
* )
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection|SupplierAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\SupplierAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* Gets the currency that should be used by default, when creating a orderdetail with this supplier.
|
||||
|
|
|
@ -43,10 +43,12 @@ class Currency extends StructuralDBElement
|
|||
public const PRICE_SCALE = 5;
|
||||
|
||||
/**
|
||||
* @var Collection|CurrencyAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CurrencyAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @var string|null The exchange rate between this currency and the base currency
|
||||
* (how many base units the current currency is worth)
|
||||
* @ORM\Column(type="decimal", precision=11, scale=5, nullable=true)
|
||||
* @Assert\Positive()
|
||||
*/
|
||||
protected $attachments;
|
||||
protected $exchange_rate;
|
||||
|
||||
/**
|
||||
* @var string the 3 letter ISO code of the currency
|
||||
|
@ -55,14 +57,6 @@ class Currency extends StructuralDBElement
|
|||
*/
|
||||
protected $iso_code;
|
||||
|
||||
/**
|
||||
* @var string|null The exchange rate between this currency and the base currency
|
||||
* (how many base units the current currency is worth)
|
||||
* @ORM\Column(type="decimal", precision=11, scale=5, nullable=true)
|
||||
* @Assert\Positive()
|
||||
*/
|
||||
protected $exchange_rate;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Currency", mappedBy="parent", cascade={"persist"})
|
||||
*/
|
||||
|
@ -74,6 +68,12 @@ class Currency extends StructuralDBElement
|
|||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @var Collection|CurrencyAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CurrencyAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* Returns the 3 letter ISO code of this currency.
|
||||
*
|
||||
|
|
|
@ -71,21 +71,6 @@ class Orderdetail extends DBElement
|
|||
{
|
||||
use TimestampTrait;
|
||||
|
||||
/**
|
||||
* @var Part
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="orderdetails")
|
||||
* @ORM\JoinColumn(name="part_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* @var Supplier
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="orderdetails")
|
||||
* @ORM\JoinColumn(name="id_supplier", referencedColumnName="id")
|
||||
*/
|
||||
protected $supplier;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Pricedetail", mappedBy="orderdetail", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @Assert\Valid()
|
||||
|
@ -112,6 +97,21 @@ class Orderdetail extends DBElement
|
|||
*/
|
||||
protected $supplier_product_url = '';
|
||||
|
||||
/**
|
||||
* @var Part
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="orderdetails")
|
||||
* @ORM\JoinColumn(name="part_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* @var Supplier
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="orderdetails")
|
||||
* @ORM\JoinColumn(name="id_supplier", referencedColumnName="id")
|
||||
*/
|
||||
protected $supplier;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pricedetails = new ArrayCollection();
|
||||
|
|
|
@ -72,14 +72,6 @@ class Pricedetail extends DBElement
|
|||
|
||||
public const PRICE_PRECISION = 5;
|
||||
|
||||
/**
|
||||
* @var Orderdetail
|
||||
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
|
||||
* @ORM\JoinColumn(name="orderdetails_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
protected $orderdetail;
|
||||
|
||||
/**
|
||||
* @var string The price related to the detail. (Given in the selected currency)
|
||||
* @ORM\Column(type="decimal", precision=11, scale=5)
|
||||
|
@ -116,6 +108,14 @@ class Pricedetail extends DBElement
|
|||
*/
|
||||
protected $manual_input = true;
|
||||
|
||||
/**
|
||||
* @var Orderdetail
|
||||
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
|
||||
* @ORM\JoinColumn(name="orderdetails_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
protected $orderdetail;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
bcscale(static::PRICE_PRECISION);
|
||||
|
@ -280,6 +280,7 @@ class Pricedetail extends DBElement
|
|||
* quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically.
|
||||
*
|
||||
* @param float $new_price_related_quantity the price related quantity
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPriceRelatedQuantity(float $new_price_related_quantity): self
|
||||
|
|
|
@ -39,12 +39,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
class Group extends StructuralDBElement implements HasPermissionsInterface
|
||||
{
|
||||
/**
|
||||
* @var Collection|GroupAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Group", mappedBy="parent")
|
||||
*/
|
||||
|
@ -61,17 +55,22 @@ class Group extends StructuralDBElement implements HasPermissionsInterface
|
|||
*/
|
||||
protected $users;
|
||||
|
||||
/** @var PermissionsEmbed
|
||||
* @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_")
|
||||
* @ValidPermission()
|
||||
*/
|
||||
protected $permissions;
|
||||
|
||||
/**
|
||||
* @var bool If true all users associated with this group must have enabled some kind of 2 factor authentication
|
||||
* @ORM\Column(type="boolean", name="enforce_2fa")
|
||||
*/
|
||||
protected $enforce2FA = false;
|
||||
/**
|
||||
* @var Collection|GroupAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/** @var PermissionsEmbed
|
||||
* @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_")
|
||||
* @ValidPermission()
|
||||
*/
|
||||
protected $permissions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||
namespace App\Entity\UserSystem;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
@ -316,7 +317,7 @@ class PermissionsEmbed
|
|||
public function getBitValue(string $permission_name, int $bit_n): int
|
||||
{
|
||||
if (! $this->isValidPermissionName($permission_name)) {
|
||||
throw new \InvalidArgumentException(sprintf('No permission with the name "%s" is existing!', $permission_name));
|
||||
throw new InvalidArgumentException(sprintf('No permission with the name "%s" is existing!', $permission_name));
|
||||
}
|
||||
|
||||
$perm_int = (int) $this->{$permission_name};
|
||||
|
@ -386,7 +387,7 @@ class PermissionsEmbed
|
|||
public function setBitValue(string $permission_name, int $bit_n, int $new_value): self
|
||||
{
|
||||
if (! $this->isValidPermissionName($permission_name)) {
|
||||
throw new \InvalidArgumentException('No permission with the given name is existing!');
|
||||
throw new InvalidArgumentException('No permission with the given name is existing!');
|
||||
}
|
||||
|
||||
$this->{$permission_name} = static::writeBitPair($this->{$permission_name}, $bit_n, $new_value);
|
||||
|
@ -405,7 +406,7 @@ class PermissionsEmbed
|
|||
public function getRawPermissionValue(string $permission_name): int
|
||||
{
|
||||
if (! $this->isValidPermissionName($permission_name)) {
|
||||
throw new \InvalidArgumentException('No permission with the given name is existing!');
|
||||
throw new InvalidArgumentException('No permission with the given name is existing!');
|
||||
}
|
||||
|
||||
return $this->{$permission_name};
|
||||
|
@ -422,7 +423,7 @@ class PermissionsEmbed
|
|||
public function setRawPermissionValue(string $permission_name, int $value): self
|
||||
{
|
||||
if (! $this->isValidPermissionName($permission_name)) {
|
||||
throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
|
||||
throw new InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
|
||||
}
|
||||
|
||||
$this->{$permission_name} = $value;
|
||||
|
@ -456,7 +457,7 @@ class PermissionsEmbed
|
|||
* Reads a bit pair from $data.
|
||||
*
|
||||
* @param int|string $data The data from where the bits should be extracted from
|
||||
* @param int $n The number of the lower bit (of the pair) that should be read. Starting from zero.
|
||||
* @param int $n The number of the lower bit (of the pair) that should be read. Starting from zero.
|
||||
*
|
||||
* @return int the value of the bit pair
|
||||
*/
|
||||
|
@ -464,7 +465,7 @@ class PermissionsEmbed
|
|||
{
|
||||
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
|
||||
if (0 !== $n % 2) {
|
||||
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
throw new InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
}
|
||||
|
||||
$mask = 0b11 << $n; //Create a mask for the data
|
||||
|
@ -487,7 +488,7 @@ class PermissionsEmbed
|
|||
Assert::greaterThanEq($new, 0, '$new must not be negative, because a bit pair is written! Got %s.');
|
||||
|
||||
if (0 !== $n % 2) {
|
||||
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
throw new InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
}
|
||||
|
||||
$mask = 0b11 << $n; //Mask all bits that should be written
|
||||
|
|
|
@ -76,13 +76,6 @@ class U2FKey implements TwoFactorKeyInterface
|
|||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys")
|
||||
*
|
||||
* @var User
|
||||
**/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*
|
||||
|
@ -90,6 +83,13 @@ class U2FKey implements TwoFactorKeyInterface
|
|||
**/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys")
|
||||
*
|
||||
* @var User
|
||||
**/
|
||||
protected $user;
|
||||
|
||||
public function fromRegistrationData(Registration $data): void
|
||||
{
|
||||
$this->keyHandle = $data->keyHandle;
|
||||
|
|
|
@ -59,9 +59,13 @@ use App\Entity\PriceInformations\Currency;
|
|||
use App\Security\Interfaces\HasPermissionsInterface;
|
||||
use App\Validator\Constraints\Selectable;
|
||||
use App\Validator\Constraints\ValidPermission;
|
||||
use function count;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Exception;
|
||||
use function in_array;
|
||||
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorInterface as U2FTwoFactorInterface;
|
||||
use R\U2FTwoFactorBundle\Model\U2F\TwoFactorKeyInterface;
|
||||
use Scheb\TwoFactorBundle\Model\BackupCodeInterface;
|
||||
|
@ -84,7 +88,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
{
|
||||
use MasterAttachmentTrait;
|
||||
|
||||
/** The User id of the anonymous user */
|
||||
/**
|
||||
* The User id of the anonymous user
|
||||
*/
|
||||
public const ID_ANONYMOUS = 1;
|
||||
|
||||
public const AVAILABLE_THEMES = ['bootstrap', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal',
|
||||
|
@ -92,79 +98,10 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
'spacelab', 'united', 'yeti', ];
|
||||
|
||||
/**
|
||||
* @var Collection|UserAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\UserAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=180, unique=true)
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* //@ORM\Column(type="json").
|
||||
*/
|
||||
//protected $roles = [];
|
||||
|
||||
/**
|
||||
* @var string|null The hashed password
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @var bool True if the user needs to change password after log in
|
||||
* @var bool Determines if the user is disabled (user can not log in)
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $need_pw_change = true;
|
||||
|
||||
/**
|
||||
* @var string|null The first name of the User
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $first_name = '';
|
||||
|
||||
/**
|
||||
* @var string|null The last name of the User
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $last_name = '';
|
||||
|
||||
/**
|
||||
* @var string|null The department the user is working
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $department = '';
|
||||
|
||||
/**
|
||||
* @var string|null The email address of the user
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Assert\Email()
|
||||
*/
|
||||
protected $email = '';
|
||||
|
||||
/**
|
||||
* @var string|null The language/locale the user prefers
|
||||
* @ORM\Column(type="string", name="config_language", nullable=true)
|
||||
* @Assert\Language()
|
||||
*/
|
||||
protected $language = '';
|
||||
|
||||
/**
|
||||
* @var string|null The timezone the user prefers
|
||||
* @ORM\Column(type="string", name="config_timezone", nullable=true)
|
||||
* @Assert\Timezone()
|
||||
*/
|
||||
protected $timezone = '';
|
||||
protected $disabled = false;
|
||||
|
||||
/**
|
||||
* @var string|null The theme
|
||||
|
@ -173,6 +110,40 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
protected $theme = '';
|
||||
|
||||
/**
|
||||
* @var string|null The hash of a token the user must provide when he wants to reset his password.
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $pw_reset_token = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="config_instock_comment_a")
|
||||
*/
|
||||
protected $instock_comment_a = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="config_instock_comment_w")
|
||||
*/
|
||||
protected $instock_comment_w = '';
|
||||
|
||||
/** @var int The version of the trusted device cookie. Used to invalidate all trusted device cookies at once.
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $trustedDeviceCookieVersion = 0;
|
||||
|
||||
/**
|
||||
* @var string[]|null A list of backup codes that can be used, if the user has no access to its Google Authenticator device
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
protected $backupCodes = [];
|
||||
|
||||
/**
|
||||
* @ORM\Id()
|
||||
* @ORM\GeneratedValue()
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var Group|null the group this user belongs to
|
||||
* @ORM\ManyToOne(targetEntity="Group", inversedBy="users", fetch="EAGER")
|
||||
|
@ -188,25 +159,66 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
protected $googleAuthenticatorSecret;
|
||||
|
||||
/**
|
||||
* @var string[]|null A list of backup codes that can be used, if the user has no access to its Google Authenticator device
|
||||
* @ORM\Column(type="json")
|
||||
* @var string|null The timezone the user prefers
|
||||
* @ORM\Column(type="string", name="config_timezone", nullable=true)
|
||||
* @Assert\Timezone()
|
||||
*/
|
||||
protected $backupCodes = [];
|
||||
protected $timezone = '';
|
||||
|
||||
/** @var \DateTime The time when the backup codes were generated
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
/**
|
||||
* @var string|null The language/locale the user prefers
|
||||
* @ORM\Column(type="string", name="config_language", nullable=true)
|
||||
* @Assert\Language()
|
||||
*/
|
||||
protected $backupCodesGenerationDate;
|
||||
protected $language = '';
|
||||
|
||||
/** @var int The version of the trusted device cookie. Used to invalidate all trusted device cookies at once.
|
||||
* @ORM\Column(type="integer")
|
||||
/**
|
||||
* @var string|null The email address of the user
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
* @Assert\Email()
|
||||
*/
|
||||
protected $trustedDeviceCookieVersion = 0;
|
||||
protected $email = '';
|
||||
|
||||
/** @var Collection<TwoFactorKeyInterface>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\UserSystem\U2FKey", mappedBy="user", cascade={"REMOVE"}, orphanRemoval=true)
|
||||
/**
|
||||
* @var string|null The department the user is working
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $u2fKeys;
|
||||
protected $department = '';
|
||||
|
||||
/**
|
||||
* @var string|null The last name of the User
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $last_name = '';
|
||||
|
||||
/**
|
||||
* @var string|null The first name of the User
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $first_name = '';
|
||||
|
||||
/**
|
||||
* @var bool True if the user needs to change password after log in
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $need_pw_change = true;
|
||||
|
||||
/**
|
||||
* //@ORM\Column(type="json").
|
||||
*/
|
||||
//protected $roles = [];
|
||||
|
||||
/**
|
||||
* @var string|null The hashed password
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=180, unique=true)
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@ -214,6 +226,22 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
protected $settings = [];
|
||||
|
||||
/**
|
||||
* @var Collection|UserAttachment[]
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\UserAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $attachments;
|
||||
|
||||
/** @var DateTime The time when the backup codes were generated
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
protected $backupCodesGenerationDate;
|
||||
|
||||
/** @var Collection<TwoFactorKeyInterface>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\UserSystem\U2FKey", mappedBy="user", cascade={"REMOVE"}, orphanRemoval=true)
|
||||
*/
|
||||
protected $u2fKeys;
|
||||
|
||||
/**
|
||||
* @var Currency|null The currency the user wants to see prices in.
|
||||
* Dont use fetch=EAGER here, this will cause problems with setting the currency setting.
|
||||
|
@ -232,33 +260,11 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
protected $permissions;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="config_instock_comment_w")
|
||||
*/
|
||||
protected $instock_comment_w = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", name="config_instock_comment_a")
|
||||
*/
|
||||
protected $instock_comment_a = '';
|
||||
|
||||
/**
|
||||
* @var string|null The hash of a token the user must provide when he wants to reset his password.
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $pw_reset_token = null;
|
||||
|
||||
/**
|
||||
* @var \DateTime The time until the password reset token is valid.
|
||||
* @var DateTime The time until the password reset token is valid.
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
protected $pw_reset_expires = null;
|
||||
|
||||
/**
|
||||
* @var bool Determines if the user is disabled (user can not log in)
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $disabled = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@ -466,9 +472,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
/**
|
||||
* Gets the datetime when the password reset token expires.
|
||||
*
|
||||
* @return \DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getPwResetExpires(): \DateTime
|
||||
public function getPwResetExpires(): DateTime
|
||||
{
|
||||
return $this->pw_reset_expires;
|
||||
}
|
||||
|
@ -478,7 +484,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setPwResetExpires(\DateTime $pw_reset_expires): self
|
||||
public function setPwResetExpires(DateTime $pw_reset_expires): self
|
||||
{
|
||||
$this->pw_reset_expires = $pw_reset_expires;
|
||||
|
||||
|
@ -769,7 +775,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
public function isBackupCode(string $code): bool
|
||||
{
|
||||
return \in_array($code, $this->backupCodes, true);
|
||||
return in_array($code, $this->backupCodes, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -802,7 +808,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \Exception If an error with the datetime occurs
|
||||
* @throws Exception If an error with the datetime occurs
|
||||
*/
|
||||
public function setBackupCodes(array $codes): self
|
||||
{
|
||||
|
@ -810,7 +816,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
if (empty($codes)) {
|
||||
$this->backupCodesGenerationDate = null;
|
||||
} else {
|
||||
$this->backupCodesGenerationDate = new \DateTime();
|
||||
$this->backupCodesGenerationDate = new DateTime();
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -819,9 +825,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
/**
|
||||
* Return the date when the backup codes were generated.
|
||||
*
|
||||
* @return \DateTime|null
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function getBackupCodesGenerationDate(): ?\DateTime
|
||||
public function getBackupCodesGenerationDate(): ?DateTime
|
||||
{
|
||||
return $this->backupCodesGenerationDate;
|
||||
}
|
||||
|
@ -852,7 +858,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
public function isU2FAuthEnabled(): bool
|
||||
{
|
||||
return \count($this->u2fKeys) > 0;
|
||||
return count($this->u2fKeys) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue