* * */ class Person { private $uid; private $cn; private $touch; private $dn; private $sn; private $gecos; /** * * Constructor function. Fix touch value because this person still has not been touched. * */ function __construct() { $this->set_touch(false); } /** * it get uid person * @return string */ function get_uid() { return $this->uid; } /** * get common name * @return string * @example Bryan Stevens Acosta Hincapie */ function get_cn() { return $this->cn; } /** * get surname * @return string * @example Bryan Stevens Acosta Hincapie */ function get_sn() { return $this->sn; } /** * get gecos * @return string * @example Bryan Stevens Acosta Hincapie */ function get_gecos() { return $this->gecos; } /** * Set dn person. This may be how "uid=bryhin,ou=Students,ou=People,dc=12345678,dc=aula,dc=ma2,dc=lliurex,dc=net" * @param $ndn String * @return void * */ function set_dn($ndn) { $this->dn = $ndn; } /** * Get has been touch * @return boolean */ function get_touch() { return $this->touch; } /** * Set uid value * @param $nuid string * @return void */ function set_uid($nuid) { $this->uid = $nuid; } /** * Set common name * @param $ncn String * @return void */ function set_cn($ncn) { $this->cn = $ncn; } /** * Set surname * @param $nsn String * @return void */ function set_sn($nsn) { $this->sn = $nsn; } /** * Set gecos * @param $ngn String * @return void */ function set_gecos($ngn) { $this->gecos = $ngn; } /** * Touch person * @param $ntouch boolean * @return void */ function set_touch($ntouch) { $this->touch = $ntouch; } /** * get dn person * @return string * @example uid=bryhin,ou=Students,ou=People,dc=12345678,dc=aula,dc=ma2,dc=lliurex,dc=net */ function get_dn() { return $this->dn; } /** * Do strtolower encode utf8 * * @param $string String * @return string */ public static function strtolower_utf8($string) { $convert_to = array( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ø", "ù", "ú", "û", "ü", "ý", "а", "б", "в", "г", "д", "е", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я" ); $convert_from = array( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ъ", "Ь", "Э", "Ю", "Я" ); return str_replace($convert_from, $convert_to, $string); } /** * Compare a and b person through common name, deleting blank space and parsing to lower char on utf8. * If Person has accent, but other hasn't it, this function return that they are different. * * This function has been created for order array and later search with quicksort * * Return -1 , 0 or 1 if common name $a person is lower, equal or great that common name $b * * @param $a Person * @param $b Person * @return int */ public static function compare($a,$b) { if(is_a($a,'Person') && is_a($b,'Person')) { $var = strcmp(str_replace(" ", "",Person::strtolower_utf8($a->get_gecos())), str_replace(" ", "",Person::strtolower_utf8($b->get_gecos()))); return $var; } else { exit (1); } } /** * Search on array if needle exist. If exist return its position, in opposition return -1 * * @param $array Person * @param $needle Person * @return int */ public static function search($array,$needle) { $i = 0; $j = count($array)-1; while (true){ if ($i > $j) return -1; $medio = floor(($j + $i) /2); $compare = Person::compare($needle,$array[$medio]); if ($compare > 0) $i = $medio + 1; elseif ($compare < 0) $j = $medio - 1; elseif ($compare == 0) return $medio; } } } ?>