diff --git a/migrations/Version20230402170923.php b/migrations/Version20230402170923.php new file mode 100644 index 00000000..1a05fd74 --- /dev/null +++ b/migrations/Version20230402170923.php @@ -0,0 +1,44 @@ +addSql('ALTER TABLE part_lots ADD id_owner INT DEFAULT NULL'); + $this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES `users` (id) ON DELETE SET NULL'); + $this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)'); + $this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A4727ACA70 FOREIGN KEY (parent_id) REFERENCES projects (id)'); + $this->addSql('ALTER TABLE storelocations ADD id_owner INT DEFAULT NULL, ADD part_owner_must_match TINYINT(1) NOT NULL'); + $this->addSql('ALTER TABLE storelocations ADD CONSTRAINT FK_751702021E5A74C FOREIGN KEY (id_owner) REFERENCES `users` (id) ON DELETE SET NULL'); + $this->addSql('CREATE INDEX IDX_751702021E5A74C ON storelocations (id_owner)'); + $this->addSql('ALTER TABLE users ADD about_me LONGTEXT DEFAULT \'\' NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) NOT NULL'); + $this->addSql('ALTER TABLE part_lots DROP FOREIGN KEY FK_EBC8F94321E5A74C'); + $this->addSql('DROP INDEX IDX_EBC8F94321E5A74C ON part_lots'); + $this->addSql('ALTER TABLE part_lots DROP id_owner'); + $this->addSql('ALTER TABLE projects DROP FOREIGN KEY FK_5C93B3A4727ACA70'); + $this->addSql('ALTER TABLE `storelocations` DROP FOREIGN KEY FK_751702021E5A74C'); + $this->addSql('DROP INDEX IDX_751702021E5A74C ON `storelocations`'); + $this->addSql('ALTER TABLE `storelocations` DROP id_owner, DROP part_owner_must_match'); + $this->addSql('ALTER TABLE `users` DROP about_me'); + } +} diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index 40db1fc2..f30434ab 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -26,6 +26,7 @@ use App\Entity\Base\AbstractDBElement; use App\Entity\Base\TimestampTrait; use App\Entity\Contracts\NamedElementInterface; use App\Entity\Contracts\TimeStampableInterface; +use App\Entity\UserSystem\User; use App\Validator\Constraints\Selectable; use App\Validator\Constraints\ValidPartLot; use DateTime; @@ -111,6 +112,13 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named */ protected Part $part; + /** + * @var User|null The owner of this part lot + * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User") + * @ORM\JoinColumn(name="id_owner", referencedColumnName="id", nullable=true, onDelete="SET NULL") + */ + protected ?User $owner; + public function __clone() { if ($this->id) { @@ -304,6 +312,28 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named return $this; } + /** + * Returns the owner of this part lot. + * @return User|null + */ + public function getOwner(): ?User + { + return $this->owner; + } + + /** + * Sets the owner of this part lot. + * @param User|null $owner + * @return PartLot + */ + public function setOwner(?User $owner): PartLot + { + $this->owner = $owner; + return $this; + } + + + public function getName(): string { return $this->description; diff --git a/src/Entity/Parts/Storelocation.php b/src/Entity/Parts/Storelocation.php index 52f84f2d..eee159bf 100644 --- a/src/Entity/Parts/Storelocation.php +++ b/src/Entity/Parts/Storelocation.php @@ -25,6 +25,7 @@ namespace App\Entity\Parts; use App\Entity\Attachments\StorelocationAttachment; use App\Entity\Base\AbstractPartsContainingDBElement; use App\Entity\Parameters\StorelocationParameter; +use App\Entity\UserSystem\User; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; @@ -89,6 +90,19 @@ class Storelocation extends AbstractPartsContainingDBElement */ protected bool $limit_to_existing_parts = false; + /** + * @var User|null The owner of this storage location + * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User") + * @ORM\JoinColumn(name="id_owner", referencedColumnName="id", nullable=true, onDelete="SET NULL") + */ + protected ?User $owner; + + /** + * @var bool If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here. + * @ORM\Column(type="boolean") + */ + protected bool $part_owner_must_match = false; + /** * @var Collection * @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) @@ -166,6 +180,49 @@ class Storelocation extends AbstractPartsContainingDBElement return $this; } + /** + * Returns the owner of this storage location + * @return User|null + */ + public function getOwner(): ?User + { + return $this->owner; + } + + /** + * Sets the owner of this storage location + * @param User|null $owner + * @return Storelocation + */ + public function setOwner(?User $owner): Storelocation + { + $this->owner = $owner; + return $this; + } + + /** + * If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here. + * @return bool + */ + public function isPartOwnerMustMatch(): bool + { + return $this->part_owner_must_match; + } + + /** + * If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here. + * @param bool $part_owner_must_match + * @return Storelocation + */ + public function setPartOwnerMustMatch(bool $part_owner_must_match): Storelocation + { + $this->part_owner_must_match = $part_owner_must_match; + return $this; + } + + + + /******************************************************************************** * * Setters diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index fd8c9054..375030a5 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -103,6 +103,13 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe */ protected string $instock_comment_w = ''; + /** + * @var string A self-description of the user + * @ORM\Column(type="text", options={"default": ""}) + * @Groups({"full", "import"}) + */ + protected string $aboutMe = ''; + /** @var int The version of the trusted device cookie. Used to invalidate all trusted device cookies at once. * @ORM\Column(type="integer") */