Part-DB.Part-DB-server/src/Entity/Base/AbstractNamedDBElement.php

103 lines
3 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
2022-11-29 22:28:53 +01:00
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
2020-02-22 18:14:36 +01:00
* 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
2020-02-22 18:14:36 +01:00
* GNU Affero General Public License for more details.
*
2020-02-22 18:14:36 +01:00
* 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/>.
*/
declare(strict_types=1);
2019-02-23 22:41:13 +01:00
namespace App\Entity\Base;
2019-02-23 22:41:13 +01:00
2023-06-11 14:55:06 +02:00
use Doctrine\DBAL\Types\Types;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
2019-02-23 22:41:13 +01:00
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
2019-02-23 22:41:13 +01:00
/**
* All subclasses of this class have an attribute "name".
*/
#[ORM\MappedSuperclass(repositoryClass: 'App\Repository\NamedDBElement')]
#[ORM\HasLifecycleCallbacks]
abstract class AbstractNamedDBElement extends AbstractDBElement implements NamedElementInterface, TimeStampableInterface, \Stringable
2019-02-23 22:41:13 +01:00
{
use TimestampTrait;
2019-02-23 22:41:13 +01:00
/**
2020-08-21 21:36:22 +02:00
* @var string the name of this element
2019-02-23 22:41:13 +01:00
*/
2023-05-28 01:21:05 +02:00
#[Assert\NotBlank]
#[Groups(['simple', 'extended', 'full', 'import'])]
2023-06-11 14:55:06 +02:00
#[ORM\Column(type: Types::STRING)]
2022-09-18 22:59:31 +02:00
protected string $name = '';
2019-02-23 22:41:13 +01:00
2020-01-05 15:46:58 +01:00
/******************************************************************************
*
* Helpers
*
******************************************************************************/
public function __toString(): string
2020-01-05 15:46:58 +01:00
{
return $this->getName();
}
2020-03-15 13:56:31 +01:00
public function __clone()
{
if ($this->id) {
//We create a new object, so give it a new creation date
$this->addedDate = null;
}
parent::__clone(); // TODO: Change the autogenerated stub
}
2019-02-23 22:41:13 +01:00
/********************************************************************************
*
* Getters
*
*********************************************************************************/
/**
* Get the name of this element.
*
* @return string the name of this element
2019-02-23 22:41:13 +01:00
*/
public function getName(): string
2019-02-23 22:41:13 +01:00
{
return $this->name;
2019-02-23 22:41:13 +01:00
}
/********************************************************************************
*
* Setters
*
*********************************************************************************/
/**
* Change the name of this element.
2019-02-23 22:41:13 +01:00
*
* @param string $new_name the new name
2019-02-23 22:41:13 +01:00
*/
public function setName(string $new_name): self
2019-02-23 22:41:13 +01:00
{
$this->name = $new_name;
2020-03-15 13:56:31 +01:00
return $this;
}
}