ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 public. More...
 
 getFirstName ()
 Access Method public. More...
 
 getMiddleName ()
 Access Method public. More...
 
 getLastName ()
 Access Method public. More...
 
 getTitle ()
 Access Method public. More...
 
 getSuffix ()
 Access Method public. More...
 
 getNotParseable ()
 Access Method public. More...
 
 setFullName ( $newFullName)
 Mutator Method 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 public

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

References parse().

82  {
83  $this->title = "";
84  $this->first = "";
85  $this->middle = "";
86  $this->last = "";
87  $this->suffix = "";
88 
89  //$this->titles = array('dr','doctor','miss','misses','mr','mister','mrs','ms','judge','sir','madam','madame');
90 
91  // added Military Titles
92  $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');
93 
94  $this->prefices = array('bon','ben','bin','da','dal','de','del','der','de','e','la','le','san','st','ste','van','vel','von');
95  $this->suffices = array('esq','esquire','jr','sr','2','i','ii','iii','iv','v','clu','chfc','cfp','md','phd');
96  $this->fullName = "";
97  $this->notParseable = FALSE;
98 
99  // if initialized by value, set class variable and then parse
100  if ( $initString != "" ) {
101  $this->fullName = $initString;
102  $this->parse();
103  }
104  }
parse()
Extract the elements of the full name into separate parts.
+ Here is the call graph for this function:

◆ __destruct()

ilFullnameParser::__destruct ( )

Destructor public.

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

111 {}

Member Function Documentation

◆ getFirstName()

ilFullnameParser::getFirstName ( )

Access Method public.

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

References $first.

◆ getLastName()

ilFullnameParser::getLastName ( )

Access Method public.

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

References $last.

◆ getMiddleName()

ilFullnameParser::getMiddleName ( )

Access Method public.

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

References $middle.

◆ getNotParseable()

ilFullnameParser::getNotParseable ( )

Access Method public.

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

References $notParseable.

◆ getSuffix()

ilFullnameParser::getSuffix ( )

Access Method public.

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

References $suffix.

◆ getTitle()

ilFullnameParser::getTitle ( )

Access Method public.

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

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 private

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

Referenced by parse().

179  {
180  $needle = trim( strtolower( str_replace( '.', '', $needle ) ) );
181  return in_array( $needle, $haystack );
182  }
+ Here is the caller graph for this function:

◆ parse()

ilFullnameParser::parse ( )

Extract the elements of the full name into separate parts.

public

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

References inArrayNorm().

Referenced by __construct().

191  {
192  // reset values
193  $this->title = "";
194  $this->first = "";
195  $this->middle = "";
196  $this->last = "";
197  $this->suffix = "";
198  $this->notParseable = FALSE;
199 
200  // break up name based on number of commas
201  $pieces = explode( ',', preg_replace('/\s+/', ' ', trim( $this->fullName ) ) );
202  $numPieces = count( $pieces );
203 
204  switch ( $numPieces ) {
205 
206  // array(title first middle last suffix)
207  case 1:
208  $subPieces = explode(' ', trim( $pieces[0] ) );
209  $numSubPieces = count( $subPieces );
210  for ( $i = 0; $i < $numSubPieces; $i++ ) {
211  $current = trim( $subPieces[$i] );
212  if ( $i < ($numSubPieces-1) ) {
213  $next = trim( $subPieces[$i+1] );
214  } else {
215  $next = "";
216  }
217  if ( $i == 0 && $this->inArrayNorm( $current, $this->titles ) ) {
218  $this->title = $current;
219  continue;
220  }
221  if ( $this->first == "" ) {
222  $this->first = $current;
223  continue;
224  }
225  if ( $i == $numSubPieces-2 && ($next != "") && $this->inArrayNorm( $next, $this->suffices ) ) {
226  if ( $this->last != "") {
227  $this->last .= " ".$current;
228  } else {
229  $this->last = $current;
230  }
231  $this->suffix = $next;
232  break;
233  }
234  if ( $i == $numSubPieces-1 ) {
235  if ( $this->last != "" ) {
236  $this->last .= " ".$current;
237  } else {
238  $this->last = $current;
239  }
240  continue;
241  }
242  if ( $this->inArrayNorm( $current, $this->prefices ) ) {
243  if ( $this->last != "" ) {
244  $this->last .= " ".$current;
245  } else {
246  $this->last = $current;
247  }
248  continue;
249  }
250  if ( $next == 'y' || $next == 'Y' ) {
251  if ( $this->last != "" ) {
252  $this->last .= " ".$current;
253  } else {
254  $this->last = $current;
255  }
256  continue;
257  }
258  if ( $this->last != "" ) {
259  $this->last .= " ".$current;
260  continue;
261  }
262  if( $this->middle != "" ) {
263  $this->middle .= " ".$current;
264  } else {
265  $this->middle = $current;
266  }
267  }
268  break;
269 
270  default:
271  switch( $this->inArrayNorm( $pieces[1], $this->suffices ) ) {
272 
273  // array(title first middle last, suffix [, suffix])
274  case TRUE:
275  $subPieces = explode(' ', trim( $pieces[0] ) );
276  $numSubPieces = count( $subPieces );
277  for ( $i = 0; $i < $numSubPieces; $i++ ) {
278  $current = trim( $subPieces[$i] );
279  if ( $i < ($numSubPieces-1) ) {
280  $next = trim( $subPieces[$i+1] );
281  } else {
282  $next = "";
283  }
284  if ( $i == 0 && $this->inArrayNorm( $current, $this->titles ) ) {
285  $this->title = $current;
286  continue;
287  }
288  if ( $this->first == "" ) {
289  $this->first = $current;
290  continue;
291  }
292  if ( $i == $numSubPieces-1 ) {
293  if ( $this->last != "" ) {
294  $this->last .= " ".$current;
295  } else {
296  $this->last = $current;
297  }
298  continue;
299  }
300  if ( $this->inArrayNorm( $current, $this->prefices ) ) {
301  if ( $this->last != "" ) {
302  $this->last .= " ".$current;
303  } else {
304  $this->last = $current;
305  }
306  continue;
307  }
308  if ( $next == 'y' || $next == 'Y' ) {
309  if ( $this->last != "" ) {
310  $this->last .= " ".$current;
311  } else {
312  $this->last = $current;
313  }
314  continue;
315  }
316  if ( $this->last != "" ) {
317  $this->last .= " ".$current;
318  continue;
319  }
320  if ( $this->middle != "" ) {
321  $this->middle .= " ".$current;
322  } else {
323  $this->middle = $current;
324  }
325  }
326  $this->suffix = trim($pieces[1]);
327  for ( $i = 2; $i < $numPieces; $i++ ) {
328  $this->suffix .= ", ". trim( $pieces[$i] );
329  }
330  break;
331 
332  // array(last, title first middles[,] suffix [,suffix])
333  case FALSE:
334  $subPieces = explode( ' ', trim( $pieces[1] ) );
335  $numSubPieces = count( $subPieces );
336  for ( $i = 0; $i < $numSubPieces; $i++ ) {
337  $current = trim( $subPieces[$i] );
338  if ( $i < ($numSubPieces-1) ) {
339  $next = trim( $subPieces[$i+1] );
340  } else {
341  $next = "";
342  }
343  if ( $i == 0 && $this->inArrayNorm( $current, $this->titles ) ) {
344  $this->title = $current;
345  continue;
346  }
347  if ( $this->first == "" ) {
348  $this->first = $current;
349  continue;
350  }
351  if ( $i == $numSubPieces-2 && ($next != "") && $this->inArrayNorm( $next, $this->suffices ) ) {
352  if ( $this->middle != "" ) {
353  $this->middle .= " ".$current;
354  } else {
355  $this->middle = $current;
356  }
357  $this->suffix = $next;
358  break;
359  }
360  if ( $i == $numSubPieces-1 && $this->inArrayNorm( $current, $this->suffices ) ) {
361  $this->suffix = $current;
362  continue;
363  }
364  if ( $this->middle != "" ) {
365  $this->middle .= " ".$current;
366  } else {
367  $this->middle = $current;
368  }
369  }
370  if( isset($pieces[2]) && $pieces[2] ) {
371  if ( $this->last == "" ) {
372  $this->suffix = trim( $pieces[2] );
373  for ($s = 3; $s < $numPieces; $s++) {
374  $this->suffix .= ", ". trim( $pieces[$s] );
375  }
376  } else {
377  for ($s = 2; $s < $numPieces; $s++) {
378  $this->suffix .= ", ". trim( $pieces[$s] );
379  }
380  }
381  }
382  $this->last = $pieces[0];
383  break;
384  }
385  unset( $pieces );
386  break;
387  }
388  if ( $this->first == "" && $this->middle == "" && $this->last == "" ) {
389  $this->notParseable = TRUE;
390  }
391  }
inArrayNorm( $needle, $haystack)
Determine if the needle is in the haystack.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFullName()

ilFullnameParser::setFullName (   $newFullName)

Mutator Method public.

Parameters
newFullNamethe new value to set fullName to

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

168 { $this->fullName = $newFullName; }

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: