Completed
Push — master ( bcdba8...408d98 )
by Jan
03:54
created

DBElement   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

2 Methods

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