<?php

class PG_Controller_Plugin_Fullname
extends Zend_Controller_Plugin_Abstract
{
  	
		
		public function getName($Fullname, $uppcase =0, $abbrive=0){
			if(empty($Fullname)){
				return "N/A";
			}else{
				if(empty($this->getLastName($Fullname,$uppcase))){
					return $this->getOtherNamesInit($Fullname,0,0);
				}else{
					return $this->getLastName($Fullname,$uppcase).", ".$this->getOtherNamesInit($Fullname,$uppcase,$abbrive);
				}
				
			}
			
		}
		
		
		
		private function getLastName($Fullname,$uppcase){
			
			$last = explode(",", $Fullname);
			if($uppcase==1){
				return strtoupper($last[0]);
			}else{
				return ucfirst($last[0]);
			}
			
			
		}
		
		private function getOtherNamesInit($Fullname,$uppcase,$abbrive){
			$last = explode(",", $Fullname);
			$otherName = $last[1];
			
			$others = explode(" ", $otherName);
			$init = '';
			foreach ($others as $name) {
				
				
				if($abbrive==1){
					if($uppcase==1){
					$init .=" " .strtoupper(substr($name, 0,1));
					}else{
						$init .=" " .ucfirst(substr($name,0,1));
					}
				}else{
					if($uppcase==1){
					$init .=" " .strtoupper($name);
					}else{
						$init .=" " .ucfirst($name);
					}
				}
				
				
				
				
			}
			return $init;
		}
		
		
		
} 
  