Passed
Push — master ( da72f5...6369ee )
by Jan
04:43
created

AbstractDBElement::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20
 */
21
22
declare(strict_types=1);
23
24
namespace App\Entity\Base;
25
26
use Doctrine\ORM\Mapping as ORM;
27
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
28
use Symfony\Component\Serializer\Annotation\Groups;
29
30
/**
31
 * This class is for managing all database objects.
32
 *
33
 * You should use this class for ALL classes which manages database records!
34
 *          (except special tables like "internal"...)
35
 * Every database table which are managed with this class (or a subclass of it)
36
 *          must have the table row "id"!! The ID is the unique key to identify the elements.
37
 *
38
 * @ORM\MappedSuperclass()
39
 *
40
 * @ORM\EntityListeners({"App\Security\EntityListeners\ElementPermissionListener"})
41
 *
42
 * @DiscriminatorMap(typeProperty="type", mapping={
43
 *      "attachment_type" = "App\Entity\AttachmentType",
44
 *      "attachment" = "App\Entity\Attachment",
45
 *      "category" = "App\Entity\Attachment",
46
 *      "device" = "App\Entity\Device",
47
 *      "device_part" = "App\Entity\DevicePart",
48
 *      "footprint" = "App\Entity\Footprint",
49
 *      "group" = "App\Entity\Group",
50
 *      "manufacturer" = "App\Entity\Manufacturer",
51
 *      "orderdetail" = "App\Entity\Orderdetail",
52
 *      "part" = "App\Entity\Part",
53
 *      "pricedetail" = "App\Entity\Pricedetail",
54
 *      "storelocation" = "App\Entity\Storelocation",
55
 *      "supplier" = "App\Entity\Supplier",
56
 *      "user" = "App\Entity\User"
57
 *  })
58
 */
59
abstract class AbstractDBElement
60
{
61
    /** @var int|null The Identification number for this part. This value is unique for the element in this table.
62
     * Null if the element is not saved to DB yet.
63
     * @ORM\Column(type="integer")
64
     * @ORM\Id()
65
     * @ORM\GeneratedValue()
66
     * @Groups({"full"})
67
     */
68
    protected $id;
69
70
    public function __clone()
71
    {
72
        //Set ID to null, so that an new entry is created
73
        $this->id = null;
74
    }
75
76
    /**
77
     * Get the ID. The ID can be zero, or even negative (for virtual elements). If an element is virtual, can be
78
     * checked with isVirtualElement().
79
     *
80
     * Returns null, if the element is not saved to the DB yet.
81
     *
82
     * @return int|null the ID of this element
83
     */
84
    public function getID(): ?int
85
    {
86
        return $this->id;
87
    }
88
89
    /**
90
     * Returns the ID as an string, defined by the element class.
91
     * This should have a form like P000014, for a part with ID 14.
92
     *
93
     * @return string The ID as a string;
94
     */
95
    abstract public function getIDString(): string;
96
}
97