mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-30 05:24:28 +02:00
Added entities and properties for some future features.
This commit is contained in:
parent
bcdba8b3e0
commit
7826e3d2ad
49 changed files with 1477 additions and 362 deletions
178
src/Entity/Base/NamedDBElement.php
Normal file
178
src/Entity/Base/NamedDBElement.php
Normal file
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||
* http://code.google.com/p/part-db/
|
||||
*
|
||||
* Part-DB Version 0.4+
|
||||
* Copyright (C) 2016 - 2019 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 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
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 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 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\Base;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* All subclasses of this class have an attribute "name".
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
abstract class NamedDBElement extends DBElement
|
||||
{
|
||||
/**
|
||||
* @var string The name of this element.
|
||||
* @ORM\Column(type="string")
|
||||
* @Assert\NotBlank()
|
||||
* @Groups({"simple", "extended", "full"})
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* @var \DateTime The date when this element was modified the last time.
|
||||
* @ORM\Column(type="datetimetz", name="last_modified")
|
||||
* @Groups({"extended", "full"})
|
||||
*/
|
||||
protected $lastModified;
|
||||
|
||||
/**
|
||||
* @var \DateTime The date when this element was created.
|
||||
* @ORM\Column(type="datetimetz", name="datetime_added")
|
||||
* @Groups({"extended", "full"})
|
||||
*/
|
||||
protected $addedDate;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the name.
|
||||
*
|
||||
* @return string the name of this element
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
/*
|
||||
//Strip HTML from Name, so no XSS injection is possible.
|
||||
return strip_tags($this->name); */
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function getLastModified(): ?\DateTime
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function getAddedDate(): ?\DateTime
|
||||
{
|
||||
return $this->addedDate;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Change the name of this element.
|
||||
*
|
||||
* Spaces at the begin and at the end of the string will be removed
|
||||
* automatically in NamedDBElement::check_values_validity().
|
||||
* So you don't have to do this yourself.
|
||||
*
|
||||
* @param string $new_name the new name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setName(string $new_name): self
|
||||
{
|
||||
$this->name = $new_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Helpers
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Helper for updating the timestamp. It is automatically called by doctrine before persisting.
|
||||
*
|
||||
* @ORM\PrePersist
|
||||
* @ORM\PreUpdate
|
||||
*/
|
||||
public function updatedTimestamps(): void
|
||||
{
|
||||
$this->lastModified = new \DateTime('now');
|
||||
if (null === $this->addedDate) {
|
||||
$this->addedDate = new \DateTime('now');
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getName();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue