ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilFullnameParser Class Reference
+ Collaboration diagram for ilFullnameParser:

Public Member Functions

 __construct ($initString="")
 Constructor: Setup the object, initialise the variables, and if instantiated with a name - parse it automagically. More...
 
 __destruct ()
 Destructor @access public. More...
 
 getFirstName ()
 Access Method @access public. More...
 
 getMiddleName ()
 Access Method @access public. More...
 
 getLastName ()
 Access Method @access public. More...
 
 getTitle ()
 Access Method @access public. More...
 
 getSuffix ()
 Access Method @access public. More...
 
 getNotParseable ()
 Access Method @access public. More...
 
 setFullName ($newFullName)
 Mutator Method @access public. More...
 
 parse ()
 Extract the elements of the full name into separate parts. More...
 

Private Member Functions

 inArrayNorm ($needle, $haystack)
 Determine if the needle is in the haystack. More...
 

Private Attributes

 $titles
 
 $prefices
 
 $suffices
 
 $title
 
 $first
 
 $middle
 
 $last
 
 $suffix
 
 $fullName
 
 $notParseable
 

Detailed Description

Definition at line 11 of file class.ilFullnameParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilFullnameParser::__construct (   $initString = "")

Constructor: Setup the object, initialise the variables, and if instantiated with a name - parse it automagically.

Parameters
stringThe Name String @access public

Definition at line 82 of file class.ilFullnameParser.php.

83 {
84 $this->title = "";
85 $this->first = "";
86 $this->middle = "";
87 $this->last = "";
88 $this->suffix = "";
89
90 //$this->titles = array('dr','doctor','miss','misses','mr','mister','mrs','ms','judge','sir','madam','madame');
91
92 // added Military Titles
93 $this->titles = array('dr','doctor','miss','misses','mr','mister','mrs','ms','judge','sir','madam','madame','AB','2ndLt','Amn','1stLt','A1C','Capt','SrA','Maj','SSgt','LtCol','TSgt','Col','BrigGen','1stSgt','MajGen','SMSgt','LtGen','1stSgt','Gen','CMSgt','1stSgt','CCMSgt','CMSAF','PVT','2LT','PV2','1LT','PFC','CPT','SPC','MAJ','CPL','LTC','SGT','COL','SSG','BG','SFC','MG','MSG','LTG','1SGT','GEN','SGM','CSM','SMA','WO1','WO2','WO3','WO4','WO5','ENS','SA','LTJG','SN','LT','PO3','LCDR','PO2','CDR','PO1','CAPT','CPO','RADM(LH)','SCPO','RADM(UH)','MCPO','VADM','MCPOC','ADM','MPCO-CG','CWO-2','CWO-3','CWO-4','Pvt','2ndLt','PFC','1stLt','LCpl','Capt','Cpl','Maj','Sgt','LtCol','SSgt','Col','GySgt','BGen','MSgt','MajGen','1stSgt','LtGen','MGySgt','Gen','SgtMaj','SgtMajMC','WO-1','CWO-2','CWO-3','CWO-4','CWO-5','ENS','SA','LTJG','SN','LT','PO3','LCDR','PO2','CDR','PO1','CAPT','CPO','RDML','SCPO','RADM','MCPO','VADM','MCPON','ADM','FADM','WO1','CWO2','CWO3','CWO4','CWO5');
94
95 $this->prefices = array('bon','ben','bin','da','dal','de','del','der','de','e','la','le','san','st','ste','van','vel','von');
96 $this->suffices = array('esq','esquire','jr','sr','2','i','ii','iii','iv','v','clu','chfc','cfp','md','phd');
97 $this->fullName = "";
98 $this->notParseable = false;
99
100 // if initialized by value, set class variable and then parse
101 if ($initString != "") {
102 $this->fullName = $initString;
103 $this->parse();
104 }
105 }
parse()
Extract the elements of the full name into separate parts.

References parse().

+ Here is the call graph for this function:

◆ __destruct()

ilFullnameParser::__destruct ( )

Destructor @access public.

Definition at line 112 of file class.ilFullnameParser.php.

113 {
114 }

Member Function Documentation

◆ getFirstName()

ilFullnameParser::getFirstName ( )

Access Method @access public.

Definition at line 122 of file class.ilFullnameParser.php.

123 {
124 return $this->first;
125 }

References $first.

◆ getLastName()

ilFullnameParser::getLastName ( )

Access Method @access public.

Definition at line 144 of file class.ilFullnameParser.php.

145 {
146 return $this->last;
147 }

References $last.

◆ getMiddleName()

ilFullnameParser::getMiddleName ( )

Access Method @access public.

Definition at line 133 of file class.ilFullnameParser.php.

134 {
135 return $this->middle;
136 }

References $middle.

◆ getNotParseable()

ilFullnameParser::getNotParseable ( )

Access Method @access public.

Definition at line 177 of file class.ilFullnameParser.php.

178 {
179 return $this->notParseable;
180 }

References $notParseable.

◆ getSuffix()

ilFullnameParser::getSuffix ( )

Access Method @access public.

Definition at line 166 of file class.ilFullnameParser.php.

167 {
168 return $this->suffix;
169 }

References $suffix.

◆ getTitle()

ilFullnameParser::getTitle ( )

Access Method @access public.

Definition at line 155 of file class.ilFullnameParser.php.

156 {
157 return $this->title;
158 }

References $title.

◆ inArrayNorm()

ilFullnameParser::inArrayNorm (   $needle,
  $haystack 
)
private

Determine if the needle is in the haystack.

Parameters
needlethe needle to look for
haystackthe haystack from which to look into @access private

Definition at line 203 of file class.ilFullnameParser.php.

204 {
205 $needle = trim(strtolower(str_replace('.', '', $needle)));
206 return in_array($needle, $haystack);
207 }

Referenced by parse().

+ Here is the caller graph for this function:

◆ parse()

ilFullnameParser::parse ( )

Extract the elements of the full name into separate parts.

@access public

Definition at line 216 of file class.ilFullnameParser.php.

217 {
218 // reset values
219 $this->title = "";
220 $this->first = "";
221 $this->middle = "";
222 $this->last = "";
223 $this->suffix = "";
224 $this->notParseable = false;
225
226 // break up name based on number of commas
227 $pieces = explode(',', preg_replace('/\s+/', ' ', trim($this->fullName)));
228 $numPieces = count($pieces);
229
230 switch ($numPieces) {
231
232 // array(title first middle last suffix)
233 case 1:
234 $subPieces = explode(' ', trim($pieces[0]));
235 $numSubPieces = count($subPieces);
236 for ($i = 0; $i < $numSubPieces; $i++) {
237 $current = trim($subPieces[$i]);
238 if ($i < ($numSubPieces - 1)) {
239 $next = trim($subPieces[$i + 1]);
240 } else {
241 $next = "";
242 }
243 if ($i == 0 && $this->inArrayNorm($current, $this->titles)) {
244 $this->title = $current;
245 continue;
246 }
247 if ($this->first == "") {
248 $this->first = $current;
249 continue;
250 }
251 if ($i == $numSubPieces - 2 && ($next != "") && $this->inArrayNorm($next, $this->suffices)) {
252 if ($this->last != "") {
253 $this->last .= " " . $current;
254 } else {
255 $this->last = $current;
256 }
257 $this->suffix = $next;
258 break;
259 }
260 if ($i == $numSubPieces - 1) {
261 if ($this->last != "") {
262 $this->last .= " " . $current;
263 } else {
264 $this->last = $current;
265 }
266 continue;
267 }
268 if ($this->inArrayNorm($current, $this->prefices)) {
269 if ($this->last != "") {
270 $this->last .= " " . $current;
271 } else {
272 $this->last = $current;
273 }
274 continue;
275 }
276 if ($next == 'y' || $next == 'Y') {
277 if ($this->last != "") {
278 $this->last .= " " . $current;
279 } else {
280 $this->last = $current;
281 }
282 continue;
283 }
284 if ($this->last != "") {
285 $this->last .= " " . $current;
286 continue;
287 }
288 if ($this->middle != "") {
289 $this->middle .= " " . $current;
290 } else {
291 $this->middle = $current;
292 }
293 }
294 break;
295
296 default:
297 switch ($this->inArrayNorm($pieces[1], $this->suffices)) {
298
299 // array(title first middle last, suffix [, suffix])
300 case true:
301 $subPieces = explode(' ', trim($pieces[0]));
302 $numSubPieces = count($subPieces);
303 for ($i = 0; $i < $numSubPieces; $i++) {
304 $current = trim($subPieces[$i]);
305 if ($i < ($numSubPieces - 1)) {
306 $next = trim($subPieces[$i + 1]);
307 } else {
308 $next = "";
309 }
310 if ($i == 0 && $this->inArrayNorm($current, $this->titles)) {
311 $this->title = $current;
312 continue;
313 }
314 if ($this->first == "") {
315 $this->first = $current;
316 continue;
317 }
318 if ($i == $numSubPieces - 1) {
319 if ($this->last != "") {
320 $this->last .= " " . $current;
321 } else {
322 $this->last = $current;
323 }
324 continue;
325 }
326 if ($this->inArrayNorm($current, $this->prefices)) {
327 if ($this->last != "") {
328 $this->last .= " " . $current;
329 } else {
330 $this->last = $current;
331 }
332 continue;
333 }
334 if ($next == 'y' || $next == 'Y') {
335 if ($this->last != "") {
336 $this->last .= " " . $current;
337 } else {
338 $this->last = $current;
339 }
340 continue;
341 }
342 if ($this->last != "") {
343 $this->last .= " " . $current;
344 continue;
345 }
346 if ($this->middle != "") {
347 $this->middle .= " " . $current;
348 } else {
349 $this->middle = $current;
350 }
351 }
352 $this->suffix = trim($pieces[1]);
353 for ($i = 2; $i < $numPieces; $i++) {
354 $this->suffix .= ", " . trim($pieces[$i]);
355 }
356 break;
357
358 // array(last, title first middles[,] suffix [,suffix])
359 case false:
360 $subPieces = explode(' ', trim($pieces[1]));
361 $numSubPieces = count($subPieces);
362 for ($i = 0; $i < $numSubPieces; $i++) {
363 $current = trim($subPieces[$i]);
364 if ($i < ($numSubPieces - 1)) {
365 $next = trim($subPieces[$i + 1]);
366 } else {
367 $next = "";
368 }
369 if ($i == 0 && $this->inArrayNorm($current, $this->titles)) {
370 $this->title = $current;
371 continue;
372 }
373 if ($this->first == "") {
374 $this->first = $current;
375 continue;
376 }
377 if ($i == $numSubPieces - 2 && ($next != "") && $this->inArrayNorm($next, $this->suffices)) {
378 if ($this->middle != "") {
379 $this->middle .= " " . $current;
380 } else {
381 $this->middle = $current;
382 }
383 $this->suffix = $next;
384 break;
385 }
386 if ($i == $numSubPieces - 1 && $this->inArrayNorm($current, $this->suffices)) {
387 $this->suffix = $current;
388 continue;
389 }
390 if ($this->middle != "") {
391 $this->middle .= " " . $current;
392 } else {
393 $this->middle = $current;
394 }
395 }
396 if (isset($pieces[2]) && $pieces[2]) {
397 if ($this->last == "") {
398 $this->suffix = trim($pieces[2]);
399 for ($s = 3; $s < $numPieces; $s++) {
400 $this->suffix .= ", " . trim($pieces[$s]);
401 }
402 } else {
403 for ($s = 2; $s < $numPieces; $s++) {
404 $this->suffix .= ", " . trim($pieces[$s]);
405 }
406 }
407 }
408 $this->last = $pieces[0];
409 break;
410 }
411 unset($pieces);
412 break;
413 }
414 if ($this->first == "" && $this->middle == "" && $this->last == "") {
415 $this->notParseable = true;
416 }
417 }
inArrayNorm($needle, $haystack)
Determine if the needle is in the haystack.
$i
Definition: metadata.php:24

References $i, and inArrayNorm().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFullName()

ilFullnameParser::setFullName (   $newFullName)

Mutator Method @access public.

Parameters
newFullNamethe new value to set fullName to

Definition at line 189 of file class.ilFullnameParser.php.

190 {
191 $this->fullName = $newFullName;
192 }

Field Documentation

◆ $first

ilFullnameParser::$first
private

Definition at line 42 of file class.ilFullnameParser.php.

Referenced by getFirstName().

◆ $fullName

ilFullnameParser::$fullName
private

Definition at line 66 of file class.ilFullnameParser.php.

◆ $last

ilFullnameParser::$last
private

Definition at line 54 of file class.ilFullnameParser.php.

Referenced by getLastName().

◆ $middle

ilFullnameParser::$middle
private

Definition at line 48 of file class.ilFullnameParser.php.

Referenced by getMiddleName().

◆ $notParseable

ilFullnameParser::$notParseable
private

Definition at line 72 of file class.ilFullnameParser.php.

Referenced by getNotParseable().

◆ $prefices

ilFullnameParser::$prefices
private

Definition at line 24 of file class.ilFullnameParser.php.

◆ $suffices

ilFullnameParser::$suffices
private

Definition at line 30 of file class.ilFullnameParser.php.

◆ $suffix

ilFullnameParser::$suffix
private

Definition at line 60 of file class.ilFullnameParser.php.

Referenced by getSuffix().

◆ $title

ilFullnameParser::$title
private

Definition at line 36 of file class.ilFullnameParser.php.

Referenced by getTitle().

◆ $titles

ilFullnameParser::$titles
private

Definition at line 18 of file class.ilFullnameParser.php.


The documentation for this class was generated from the following file: