Passed
Push — master ( 26e0e4...4a85b9 )
by Peter
10:37
created

RepresentedOrganization::setAsOrganizationPartOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
/**
5
 * The MIT License
6
 *
7
 * Copyright 2018  Peter Gee <https://github.com/pgee70>.
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in
17
 * all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 * THE SOFTWARE.
26
 */
27
28
namespace i3Soft\CDA\RIM\Entity;
29
30
/**
31
 *
32
 * @package     i3Soft\CDA
33
 * @author      Peter Gee <https://github.com/pgee70>
34
 * @link        https://github.com/pgee70/cda
35
 *
36
 */
37
38
use i3Soft\CDA\DataType\Name\EntityName;
39
use i3Soft\CDA\Elements\AbstractElement;
40
use i3Soft\CDA\Elements\StandardIndustryClassCode;
41
use i3Soft\CDA\Interfaces\ClassCodeInterface;
42
use i3Soft\CDA\Interfaces\DeterminerCodeInterface;
43
use i3Soft\CDA\RIM\Extensions\AsEntityIdentifier;
44
use i3Soft\CDA\RIM\Role\AsOrganizationPartOf;
45
use i3Soft\CDA\Traits\AddrsTrait;
46
use i3Soft\CDA\Traits\AsEntityIdentifierTrait;
47
use i3Soft\CDA\Traits\ClassCodeTrait;
48
use i3Soft\CDA\Traits\DeterminerCodeTrait;
49
use i3Soft\CDA\Traits\IdsTrait;
50
use i3Soft\CDA\Traits\NamesTrait;
51
use i3Soft\CDA\Traits\TelecomsTrait;
52
53
54
/**
55
 * Class RepresentedOrganization
56
 *
57
 * @package i3Soft\CDA\RIM\Entity
58
 */
59
class RepresentedOrganization extends AbstractElement implements ClassCodeInterface, DeterminerCodeInterface
60
{
61
    use IdsTrait;
62
    use NamesTrait;
63
    use TelecomsTrait;
64
    use AddrsTrait;
65
    use ClassCodeTrait;
66
    use AsEntityIdentifierTrait;
67
68
69
    use DeterminerCodeTrait;
70
71
72
    /** @var StandardIndustryClassCode */
73
    protected $standardIndustryClassCode;
74
    /** @var AsOrganizationPartOf */
75
    protected $asOrganizationPartOf;
76
77
    /**
78
     * RepresentedOrganization constructor.
79
     *
80
     * @param EntityName         $name
81
     * @param AsEntityIdentifier $as_entity_identifier
82
     */
83
    public function __construct($name = null, $as_entity_identifier = null)
84
    {
85
        $this->setAcceptableClassCodes(ClassCodeInterface::EntityClassOrganization)
86
          ->setClassCode(ClassCodeInterface::IDENTITY)
87
          ->setDeterminerCode('');
88
        if ($name && $name instanceof EntityName) {
89
            $this->addName($name);
90
        }
91
        if ($as_entity_identifier && $as_entity_identifier instanceof AsEntityIdentifier) {
92
            $this->setAsEntityIdentifier($as_entity_identifier);
93
        }
94
    }
95
96
    /**
97
     * @param EntityName $name
98
     *
99
     * @return self
100
     */
101
    public function addName(EntityName $name): self
102
    {
103
        $this->names[] = $name;
104
        return $this;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getElementTag(): string
111
    {
112
        return 'representedOrganization';
113
    }
114
115
    /**
116
     * @param \DOMDocument $doc
117
     *
118
     * @return \DOMElement
119
     */
120
    public function toDOMElement(\DOMDocument $doc): \DOMElement
121
    {
122
        $el = $this->createElement($doc);
123
        if ($this->hasIds()) {
124
            foreach ($this->getIds() as $id) {
125
                $el->appendChild($id->toDOMElement($doc));
126
            }
127
        }
128
        $this->renderIds($el, $doc);
129
        $this->renderNames($el, $doc);
130
        $this->renderTelecoms($el, $doc);
131
        $this->renderAddrs($el, $doc);
132
133
134
        if ($this->hasStandardIndustryClassCode()) {
135
            $el->appendChild($this->getStandardIndustryClassCode()->toDOMElement($doc));
136
        }
137
        $this->renderAsOrganizationPartOf($el, $doc);
138
        $this->renderAsEntityIdentifier($el, $doc);
139
140
        return $el;
141
    }
142
143
144
    /**
145
     * @return bool
146
     */
147
    public function hasStandardIndustryClassCode(): bool
148
    {
149
        return null !== $this->standardIndustryClassCode;
150
    }
151
152
    /**
153
     * @return StandardIndustryClassCode
154
     */
155
    public function getStandardIndustryClassCode(): StandardIndustryClassCode
156
    {
157
        return $this->standardIndustryClassCode;
158
    }
159
160
    /**
161
     * @param StandardIndustryClassCode $standardIndustryClassCode
162
     *
163
     * @return self
164
     */
165
    public function setStandardIndustryClassCode(StandardIndustryClassCode $standardIndustryClassCode): self
166
    {
167
        $this->standardIndustryClassCode = $standardIndustryClassCode;
168
        return $this;
169
    }
170
171
    /**
172
     * @param \DOMElement  $el
173
     * @param \DOMDocument $doc
174
     */
175
    public function renderAsOrganizationPartOf(\DOMElement $el, \DOMDocument $doc)
176
    {
177
        if ($this->hasAsOrganizationPartOf()) {
178
            $el->appendChild($this->getAsOrganizationPartOf()->toDOMElement($doc));
179
        }
180
    }
181
182
    /**
183
     * @return bool
184
     */
185
    public function hasAsOrganizationPartOf(): bool
186
    {
187
        return null !== $this->asOrganizationPartOf;
188
    }
189
190
    /**
191
     * @return AsOrganizationPartOf
192
     */
193
    public function getAsOrganizationPartOf(): AsOrganizationPartOf
194
    {
195
        return $this->asOrganizationPartOf;
196
    }
197
198
    /**
199
     * @param AsOrganizationPartOf $asOrganizationPartOf
200
     *
201
     * @return self
202
     */
203
    public function setAsOrganizationPartOf(AsOrganizationPartOf $asOrganizationPartOf): self
204
    {
205
        $this->asOrganizationPartOf = $asOrganizationPartOf;
206
        return $this;
207
    }
208
209
210
}