1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FabienCrassat\CurriculumVitaeBundle Symfony bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Crassat <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FabienCrassat\CurriculumVitaeBundle\Entity; |
13
|
|
|
|
14
|
|
|
use FabienCrassat\CurriculumVitaeBundle\Utility\LibXmlDisplayErrors; |
15
|
|
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
16
|
|
|
|
17
|
|
|
class CurriculumVitae extends Xml2arrayFunctions |
18
|
|
|
{ |
19
|
|
|
private $lang; |
20
|
|
|
private $curriculumVitae; |
21
|
|
|
private $pathToFile; |
22
|
|
|
private $interface; |
23
|
|
|
private $cvFile; |
24
|
|
|
private $xml2arrayFunctions; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $pathToFile |
28
|
|
|
* @param string $lang |
29
|
|
|
*/ |
30
|
29 |
|
public function __construct($pathToFile, $lang = 'en') { |
31
|
29 |
|
$this->pathToFile = $pathToFile; |
32
|
29 |
|
$this->setFileName(); |
33
|
29 |
|
$this->lang = $lang; |
34
|
29 |
|
$this->curriculumVitae = $this->getXmlCurriculumVitae(); |
35
|
26 |
|
$this->xml2arrayFunctions = new Xml2arrayFunctions($this->curriculumVitae, $this->lang); |
36
|
26 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return null|array |
40
|
|
|
*/ |
41
|
23 |
|
public function getDropDownLanguages() { |
42
|
23 |
|
$this->interface = $this->curriculumVitae->{'langs'}; |
43
|
9 |
|
$return = $this->getXMLValue(); |
44
|
9 |
|
if (!$return) { |
45
|
1 |
|
$return = [$this->lang => $this->lang]; |
46
|
1 |
|
} |
47
|
|
|
|
48
|
9 |
|
return $return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
4 |
|
public function getAnchors() { |
55
|
4 |
|
$anchorsAttribute = $this->curriculumVitae->xpath('curriculumVitae/*[attribute::anchor]'); |
56
|
|
|
|
57
|
4 |
|
$anchors = []; |
58
|
4 |
|
foreach ($anchorsAttribute as $anchorsValue) { |
59
|
4 |
|
$anchor = (string) $anchorsValue['anchor']; |
60
|
4 |
|
$title = $anchorsValue->xpath("anchorTitle[@lang='" . $this->lang . "']"); |
61
|
4 |
|
if (count($title) == 0) { |
62
|
1 |
|
$title = $anchorsValue->xpath('anchorTitle'); |
63
|
1 |
|
} |
64
|
4 |
|
$anchors[$anchor] = [ |
65
|
4 |
|
'href' => $anchor, |
66
|
4 |
|
'title' => (string) $title[0], |
67
|
|
|
]; |
68
|
4 |
|
}; |
69
|
|
|
|
70
|
4 |
|
return $anchors; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
5 |
|
public function getHumanFileName() { |
77
|
5 |
|
$myName = $this->getMyName(); |
78
|
5 |
|
if (empty($myName)) { |
79
|
1 |
|
return $this->cvFile; |
80
|
|
|
} |
81
|
|
|
|
82
|
4 |
|
$myCurrentJob = $this->getMyCurrentJob(); |
83
|
4 |
|
if (empty($myCurrentJob)) { |
84
|
1 |
|
return $myName; |
85
|
|
|
} |
86
|
|
|
|
87
|
3 |
|
return $myName.' - '.$myCurrentJob; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array<string,null|array<string,array>> |
92
|
|
|
*/ |
93
|
5 |
|
public function getCurriculumVitaeArray() { |
94
|
|
|
return [ |
95
|
5 |
|
'identity' => $this->getIdentity(), |
96
|
5 |
|
'followMe' => $this->getFollowMe(), |
97
|
5 |
|
'lookingFor' => $this->getLookingFor(), |
98
|
5 |
|
'experiences' => $this->getExperiences(), |
99
|
5 |
|
'skills' => $this->getSkills(), |
100
|
5 |
|
'educations' => $this->getEducations(), |
101
|
5 |
|
'languageSkills' => $this->getLanguageSkills(), |
102
|
5 |
|
'miscellaneous' => $this->getMiscellaneous() |
103
|
5 |
|
]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return null|array<string,array> |
108
|
|
|
*/ |
109
|
13 |
|
public function getIdentity() { |
110
|
13 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->identity->items; |
111
|
13 |
|
return $this->getXMLValue(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return null|array<string,array> |
116
|
|
|
*/ |
117
|
6 |
|
public function getFollowMe() { |
118
|
6 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->followMe->items; |
119
|
6 |
|
return $this->getXMLValue(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return null|array<string,array> |
124
|
|
|
*/ |
125
|
11 |
|
public function getLookingFor() { |
126
|
11 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->lookingFor; |
127
|
11 |
|
return $this->getXMLValue(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return null|array<string,array> |
132
|
|
|
*/ |
133
|
7 |
|
public function getExperiences() { |
134
|
7 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->experiences->items; |
135
|
7 |
|
return $this->getXMLValue(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return null|array<string,array> |
140
|
|
|
*/ |
141
|
6 |
|
public function getSkills() { |
142
|
6 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->skills->items; |
143
|
6 |
|
return $this->getXMLValue(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return null|array<string,array> |
148
|
|
|
*/ |
149
|
6 |
|
public function getEducations() { |
150
|
6 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->educations->items; |
151
|
6 |
|
return $this->getXMLValue(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return null|array<string,array> |
156
|
|
|
*/ |
157
|
6 |
|
public function getLanguageSkills() { |
158
|
6 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->languageSkills->items; |
159
|
6 |
|
return $this->getXMLValue(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return null|array<string,array> |
164
|
|
|
*/ |
165
|
6 |
|
public function getMiscellaneous() { |
166
|
6 |
|
$this->interface = $this->curriculumVitae->curriculumVitae->miscellaneous->items; |
167
|
6 |
|
return $this->getXMLValue(); |
168
|
|
|
} |
169
|
|
|
|
170
|
29 |
|
private function setFileName() { |
171
|
29 |
|
$data = explode('/', $this->pathToFile); |
172
|
29 |
|
$data = $data[count($data) - 1]; |
173
|
29 |
|
$data = explode('.', $data); |
174
|
|
|
|
175
|
29 |
|
$this->cvFile = $data[0]; |
176
|
29 |
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return null|string |
180
|
|
|
*/ |
181
|
5 |
|
private function getMyName() { |
182
|
5 |
|
$identity = $this->getIdentity(); |
183
|
|
|
|
184
|
5 |
|
if (isset($identity['myself']['name'])) { |
185
|
4 |
|
return $identity['myself']['name']; |
186
|
|
|
} |
187
|
|
|
|
188
|
1 |
|
return NULL; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return null|string |
193
|
|
|
*/ |
194
|
4 |
|
private function getMyCurrentJob() { |
195
|
4 |
|
$lookingFor = $this->getLookingFor(); |
196
|
4 |
|
if (isset($lookingFor['experience']['job'])) { |
197
|
3 |
|
return (string) $lookingFor['experience']['job']; |
198
|
2 |
|
} elseif (isset($lookingFor['experience'])) { |
199
|
1 |
|
return (string) $lookingFor['experience']; |
200
|
|
|
} |
201
|
|
|
|
202
|
1 |
|
return NULL; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return \SimpleXMLElement |
207
|
|
|
*/ |
208
|
29 |
|
private function getXmlCurriculumVitae() { |
209
|
29 |
|
if (is_null($this->pathToFile) || !is_file($this->pathToFile)) { |
210
|
1 |
|
throw new InvalidArgumentException('The path ' . $this->pathToFile . ' is not a valid path to file.'); |
211
|
|
|
} |
212
|
28 |
|
$this->isValidXmlCurriculumVitae(); |
213
|
|
|
|
214
|
26 |
|
return simplexml_load_file($this->pathToFile); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return boolean |
219
|
|
|
*/ |
220
|
28 |
|
private function isValidXmlCurriculumVitae() { |
221
|
|
|
// Active "user error handling" |
222
|
28 |
|
libxml_use_internal_errors(TRUE); |
223
|
|
|
|
224
|
|
|
// Instanciate of a DOMDocument |
225
|
28 |
|
$dom = new \DOMDocument('1.0'); |
226
|
|
|
|
227
|
|
|
// Load the XML from the file |
228
|
28 |
|
$dom->load($this->pathToFile); |
229
|
|
|
|
230
|
|
|
// Validation duof the XML document |
231
|
28 |
|
$reflClass = new \ReflectionClass(get_class($this)); |
232
|
28 |
|
$xsdFile = dirname($reflClass->getFileName()).'/validator.xsd'; |
233
|
28 |
|
$validate = $dom->schemaValidate($xsdFile); |
234
|
28 |
|
if (!$validate) { |
235
|
2 |
|
$libxmlDisplayErrors = new LibXmlDisplayErrors; |
236
|
2 |
|
throw new InvalidArgumentException($libxmlDisplayErrors->libXmlDisplayErrors()); |
237
|
|
|
} |
238
|
|
|
|
239
|
26 |
|
return $validate; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return null|array<string,array> |
244
|
|
|
*/ |
245
|
25 |
|
private function getXMLValue() { |
246
|
25 |
|
if (!$this->interface) { |
247
|
3 |
|
return NULL; |
248
|
|
|
} |
249
|
|
|
|
250
|
23 |
|
return $this->xml2arrayFunctions->xml2array($this->interface); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|