/** * Answer a email for an agent * * @param Agent $agent * @return string */ protected function getAgentEmail(Agent $agent) { // print_r($agent->getProperties()); exit; $propertiesIterator = $agent->getProperties(); while ($propertiesIterator->hasNext()) { $properties = $propertiesIterator->next(); if (!is_null($properties->getProperty('EMail'))) { return $properties->getProperty('EMail'); } if (!is_null($properties->getProperty('email'))) { return $properties->getProperty('email'); } if (!is_null($properties->getProperty('Email'))) { return $properties->getProperty('Email'); } } return null; }
/** * Constructor * * @param object Agent $agent * @return void * @access public * @since 11/27/07 */ public function __construct(Agent $agent) { $this->id = $agent->getId(); $this->name = $agent->getDisplayName(); try { $propertiesIterator = $agent->getProperties(); while ($propertiesIterator->hasNext()) { $properties = $propertiesIterator->next(); try { if ($properties->getProperty('email')) { $this->email = $properties->getProperty('email'); break; } } catch (Exception $e) { } } } catch (Exception $e) { } }
/** * Compare an Agent to an Agent XML description and determine if the two match. * * The current implementation of this method is kind of goofy. It should be * re-worked to either use a more reliable comparison method or be made configurable * for different comparrison methods. * * @param object Agent $agent * @param object DOMElement $element * @return boolean * @access protected * @since 1/28/08 */ protected function agentMatches(Agent $agent, DOMElement $element) { // check some system-ids first as these will not have meaningful properties // to compare and their IDs are hard coded into the system. $sourceId = $element->getAttribute('id'); $systemIds = array("edu.middlebury.agents.everyone", "edu.middlebury.institute", "1", "edu.middlebury.agents.anonymous"); if (in_array($sourceId, $systemIds)) { if ($sourceId == $agent->getId()->getIdString()) { return true; } else { return false; } } // Compare agent properties to make sure that the agent and the DOMElement // are representing the same user. $xmlPropertiesToCheck = array('email', 'username'); $agentPropertiesToCheck = array('email', 'username'); // How man properties must match $threshold = 1; $matches = 0; $xmlValues = array(); foreach ($xmlPropertiesToCheck as $property) { // printpre(htmlentities($this->doc->saveXMLWithWhitespace($element))); $valueElements = $this->xpath->evaluate('./property[key = \'' . $property . '\']/string', $element); if ($valueElements->length) { $xmlValues[] = $this->getStringValue($valueElements->item(0)); } // throw new Exception('test error'); } $agentPropertiesIterator = $agent->getProperties(); while ($agentPropertiesIterator->hasNext()) { $properties = $agentPropertiesIterator->next(); // printpre($properties->getKeys()); foreach ($agentPropertiesToCheck as $key) { try { $value = $properties->getProperty($key); // printpre($value); if (!is_null($value) && in_array($value, $xmlValues)) { $matches++; } } catch (UnknownKeyException $e) { } } } if ($matches >= $threshold) { return true; } else { return false; } }
/** * Answer the email address of an agent * * @param Agent $agent * @return string * @access protected * @since 2/19/09 */ protected function getAgentEmail(Agent $agent) { $properties = $agent->getProperties(); $email = null; while ($properties->hasNext()) { $email = $properties->next()->getProperty("email"); if (preg_match('/^[^\\s@]+@[^\\s@]+$/', $email)) { return $email; } } throw new OperationFailedException("No email found for agent, '" . $agent->getDisplayName() . "'."); }