$agentid = $result['agentid']; if (strlen($others) > 0 && strlen($agentid) > 0) { $otherbits = explode("|", $others); foreach ($otherbits as $otherbit) { $othername = explode(":", $otherbit); $an = new agentnames(); $an->setagentid($agentid); $type = $othername[0]; // TODO: Add full range of types. if ($type == "standard" || $type == "Standard Abbreviation") { $an->setType('Standard Abbreviation'); } elseif ($type == "First Initials Last") { $an->setType('First Initials Last'); } else { $an->setType('Also Known As'); } $an->setname($othername[1]); if (!$an->save()) { if (strpos($an->errorMessage(), "Duplicate entry") === FALSE) { // report problems other than duplicate entries echo "Error in saving agent name record: " . $an->errorMessage(); } } } } if ($result['added'] == 1) { echo "Saved "; } echo "{$agentid}\n"; } }
public function saveNewAgent($toSave, $forceaka = FALSE) { global $clientRoot; $result = ""; if ($toSave->save()) { switch ($toSave->gettype()) { case 'Team': $name = AgentManager::standardizeNameString($toSave->getAssembledName()); //$name = str_replace(';','|',$name); // convert any semicolon separators to pipe //$name = str_replace('|',' | ',$name); // add spaces around pipe separator $name = preg_replace('/ +/', ' ', $name); // strip out any duplicate spaces $name = trim($name); $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Standard DwC List'); $an->setname($name); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } // put list in human readable form delimited by ; with the last element separated by and. $aname = explode(' | ', $name); $separator = ""; for ($i = 0; $i < count($aname); $i++) { $sname .= $separator . $aname[$i]; // if at penultimate position, change separator to " and " so that it will be // used between the penultimate and ultimate positions. if ($i < count($aname) - 2) { $separator = "; "; } else { $separator = " and "; } } $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Also Known As'); $an->setname($sname); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } break; case 'Organization': $name = trim($toSave->getAssembledName()); $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Full Name'); $an->setname($name); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } break; case 'Individual': $suffix = ""; if (strlen($toSave->getsuffix()) > 0) { $suffix = " " . $toSave->getsuffix(); } $prefix = ""; if (strlen($toSave->getprefix()) > 0) { $prefix = $toSave->getprefix() . " "; } $hitlong = FALSE; if (strlen($toSave->getfirstname()) > 2 && strlen($toSave->getmiddlename()) > 2) { $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Full Name'); $an->setname($toSave->getAssembledName()); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } $hitlong = TRUE; } if (!$hitlong && strlen($toSave->getfirstname()) > 1 && strlen($toSave->getmiddlename()) > 1 && strpos($toSave->getAssembledName(), '.') === false) { $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Full Name'); $an->setname($toSave->getAssembledName()); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } $hitlong = TRUE; } if (strlen($toSave->getfirstname()) > 0 || strlen($toSave->getmiddlename()) > 0) { $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Last Name, Initials'); $an->setname(str_replace(" .", '', $prefix . $toSave->getfamilyname() . "{$suffix}, " . substr($toSave->getfirstname(), 0, 1) . ". " . substr($toSave->getmiddlename(), 0, 1) . ".")); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } } if (strlen($toSave->getfirstname()) > 0 || strlen($toSave->getmiddlename()) > 0) { $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Initials Last Name'); $an->setname(str_replace(" .", '', substr($toSave->getfirstname(), 0, 1) . ". " . substr($toSave->getmiddlename(), 0, 1) . ". {$prefix}" . $toSave->getfamilyname() . $suffix)); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } } if (strlen($toSave->getfirstname()) > 2) { $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('First Initials Last'); $an->setname(str_replace(" .", '', $toSave->getfirstname() . " " . substr($toSave->getmiddlename(), 0, 1) . ". {$prefix}" . $toSave->getfamilyname() . $suffix)); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } $hitlong = TRUE; } if (!$hitlong && $forceaka) { $an = new agentnames(); $an->setagentid($toSave->getagentid()); $an->setType('Also Known As'); $an->setname($toSave->getAssembledName()); if (!$an->save()) { $result .= "Error in saving agent name record: " . $an->errorMessage(); } } break; default: throw new Exception("Error: Unable to create name for agent without a recognized type."); } $result .= "Saved. <a href='{$clientRoot}/agents/agent.php?agentid=" . $toSave->getagentid() . "'>View [" . $toSave->getagentid() . "]</a>"; } else { $result .= "Error in saving agent record [" . $toSave->getagentid() . "]: " . $toSave->errorMessage(); } return $result; }