2019-09-16 21:40:47 +02:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-09-16 21:40:47 +02:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-09-16 21:40:47 +02:00
|
|
|
*
|
2019-11-01 13:40:30 +01:00
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
2019-09-16 21:40:47 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entity\Parts\PartTraits;
|
|
|
|
|
|
|
|
use App\Entity\Parts\Category;
|
|
|
|
use App\Entity\Parts\Footprint;
|
|
|
|
use App\Security\Annotations\ColumnSecurity;
|
|
|
|
use App\Validator\Constraints\Selectable;
|
2020-05-17 21:13:46 +02:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2019-09-16 21:40:47 +02:00
|
|
|
|
|
|
|
trait BasicPropertyTrait
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string A text describing what this part does
|
|
|
|
* @ORM\Column(type="text")
|
|
|
|
* @ColumnSecurity(prefix="description")
|
|
|
|
*/
|
|
|
|
protected $description = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string A comment/note related to this part
|
|
|
|
* @ORM\Column(type="text")
|
|
|
|
* @ColumnSecurity(prefix="comment")
|
|
|
|
*/
|
|
|
|
protected $comment = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool Kept for compatibility (it is not used now, and I dont think it was used in old versions)
|
|
|
|
* @ORM\Column(type="boolean")
|
|
|
|
*/
|
|
|
|
protected $visible = true;
|
|
|
|
|
|
|
|
/**
|
2020-01-04 20:24:09 +01:00
|
|
|
* @var bool true, if the part is marked as favorite
|
2019-09-16 21:40:47 +02:00
|
|
|
* @ORM\Column(type="boolean")
|
|
|
|
* @ColumnSecurity(type="boolean")
|
|
|
|
*/
|
|
|
|
protected $favorite = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Category The category this part belongs too (e.g. Resistors). Use tags, for more complex grouping.
|
2019-11-09 00:47:20 +01:00
|
|
|
* Every part must have a category.
|
2020-05-16 20:53:35 +02:00
|
|
|
* @ORM\ManyToOne(targetEntity="Category")
|
2019-09-16 21:40:47 +02:00
|
|
|
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
|
|
|
|
* @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category")
|
|
|
|
* @Selectable()
|
2020-05-17 21:13:46 +02:00
|
|
|
* @Assert\NotNull(message="validator.select_valid_category")
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
|
|
|
protected $category;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Footprint|null The footprint of this part (e.g. DIP8)
|
2020-05-16 20:53:35 +02:00
|
|
|
* @ORM\ManyToOne(targetEntity="Footprint")
|
2019-09-16 21:40:47 +02:00
|
|
|
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id")
|
|
|
|
* @ColumnSecurity(prefix="footprint", type="App\Entity\Parts\Footprint")
|
|
|
|
* @Selectable()
|
|
|
|
*/
|
|
|
|
protected $footprint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the description string like it is saved in the database.
|
|
|
|
* This can contain BBCode, it is not parsed yet.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @return string the description
|
|
|
|
*/
|
|
|
|
public function getDescription(): string
|
|
|
|
{
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the comment associated with this part.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @return string The raw/unparsed comment
|
|
|
|
*/
|
|
|
|
public function getComment(): string
|
|
|
|
{
|
|
|
|
return $this->comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get if this part is visible.
|
|
|
|
* This property is not used yet.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @return bool true if this part is visible
|
|
|
|
* false if this part isn't visible
|
|
|
|
*/
|
|
|
|
public function isVisible(): bool
|
|
|
|
{
|
|
|
|
return $this->visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this part is a favorite.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @return bool * true if this part is a favorite
|
2020-01-04 20:24:09 +01:00
|
|
|
* * false if this part is not a favorite
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
|
|
|
public function isFavorite(): bool
|
|
|
|
{
|
|
|
|
return $this->favorite;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the category of this part (e.g. Resistors).
|
|
|
|
* There is always a category, for each part!
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @return Category the category of this part
|
|
|
|
*/
|
|
|
|
public function getCategory(): ?Category
|
|
|
|
{
|
|
|
|
return $this->category;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* Gets the Footprint of this part (e.g. DIP8).
|
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @return Footprint|null The footprint of this part. Null if this part should no have a footprint.
|
|
|
|
*/
|
|
|
|
public function getFootprint(): ?Footprint
|
|
|
|
{
|
|
|
|
return $this->footprint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the description of this part.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @param string $new_description the new description
|
2020-03-15 13:56:31 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @return $this
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
|
|
|
public function setDescription(?string $new_description): self
|
|
|
|
{
|
|
|
|
$this->description = $new_description;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-09-16 21:40:47 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the comment property of this part.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @param string $new_comment the new comment
|
2020-03-15 13:56:31 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @return $this
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
|
|
|
public function setComment(string $new_comment): self
|
|
|
|
{
|
|
|
|
$this->comment = $new_comment;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-09-16 21:40:47 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the category of this Part.
|
2019-11-09 00:47:20 +01:00
|
|
|
* The category property is required for every part, so you can not pass null like the other properties (footprints).
|
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* @param Category $category The new category of this part
|
2020-03-15 13:56:31 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @return $this
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
2020-05-17 21:13:46 +02:00
|
|
|
public function setCategory(?Category $category): self
|
2019-09-16 21:40:47 +02:00
|
|
|
{
|
|
|
|
$this->category = $category;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-09-16 21:40:47 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the new Footprint of this Part.
|
|
|
|
*
|
|
|
|
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have
|
|
|
|
* a footprint.
|
2020-03-15 13:56:31 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @return $this
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
2019-09-16 22:04:59 +02:00
|
|
|
public function setFootprint(?Footprint $new_footprint): self
|
2019-09-16 21:40:47 +02:00
|
|
|
{
|
|
|
|
$this->footprint = $new_footprint;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-09-16 21:40:47 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the favorite status for this part.
|
|
|
|
*
|
2020-01-05 15:46:58 +01:00
|
|
|
* @param bool $new_favorite_status The new favorite status, that should be applied on this part.
|
|
|
|
* Set this to true, when the part should be a favorite.
|
2020-03-15 13:56:31 +01:00
|
|
|
*
|
2020-02-02 14:05:36 +01:00
|
|
|
* @return $this
|
2019-09-16 21:40:47 +02:00
|
|
|
*/
|
|
|
|
public function setFavorite(bool $new_favorite_status): self
|
|
|
|
{
|
|
|
|
$this->favorite = $new_favorite_status;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-09-16 21:40:47 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
}
|