2019-03-20 23:16:07 +01:00
|
|
|
<?php
|
2019-08-12 15:47:57 +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-08-12 15:47:57 +02:00
|
|
|
*
|
2020-02-22 18:14:36 +01:00
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
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.
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
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/>.
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
namespace App\Entity\Base;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2020-02-02 13:03:45 +01:00
|
|
|
use App\Entity\Contracts\NamedElementInterface;
|
2020-02-16 23:48:57 +01:00
|
|
|
use App\Entity\Contracts\TimeStampableInterface;
|
2019-02-23 22:41:13 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-04-07 19:30:42 +02:00
|
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
2019-11-09 00:47:20 +01:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2019-03-13 13:23:12 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* All subclasses of this class have an attribute "name".
|
|
|
|
*
|
2020-01-02 18:45:41 +01:00
|
|
|
* @ORM\MappedSuperclass(repositoryClass="App\Repository\UserRepository")
|
2019-03-05 14:02:36 +01:00
|
|
|
* @ORM\HasLifecycleCallbacks()
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2020-02-16 23:48:57 +01:00
|
|
|
abstract class AbstractNamedDBElement extends AbstractDBElement implements NamedElementInterface, TimeStampableInterface
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-08-12 18:04:53 +02:00
|
|
|
use TimestampTrait;
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* @var string The name of this element.
|
|
|
|
* @ORM\Column(type="string")
|
2019-03-13 13:23:12 +01:00
|
|
|
* @Assert\NotBlank()
|
2019-04-07 19:30:42 +02:00
|
|
|
* @Groups({"simple", "extended", "full"})
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 22:53:06 +01:00
|
|
|
protected $name = '';
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2020-01-05 15:46:58 +01:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Helpers
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->getName();
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/********************************************************************************
|
|
|
|
*
|
|
|
|
* Getters
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* Get the name of this element.
|
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string the name of this element
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getName(): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-13 13:23:12 +01:00
|
|
|
return $this->name;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
*
|
|
|
|
* Setters
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Change the name of this element.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @param string $new_name the new name
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-03-05 13:57:40 +01:00
|
|
|
* @return self
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function setName(string $new_name): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->name = $new_name;
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2019-02-24 12:54:11 +01:00
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|