Skip to content

Instantly share code, notes, and snippets.

@walterheck
Created April 14, 2013 16:53
Show Gist options
  • Save walterheck/5383389 to your computer and use it in GitHub Desktop.
Save walterheck/5383389 to your computer and use it in GitHub Desktop.
class foo {
// Lots more stuff here...
private function processPersonContacts($person, $callback_function) {
if (is_array($person->contacts)) {
foreach($person->contacts as $contact) {
$this->processContactEmailRecords($person, $contact, $callback_function);
}
} else {
$this->processContactEmailRecords($person, $person->contacts, $callback_function);
}
}
private function processContactEmailRecords ($person, $contact, $callback_function) {
if (is_array($contact->email)) {
foreach($contact->email as $emailRecord) {
$this->processEmailRecord($person, $contact, $emailRecord, $callback_function);
}
} else {
$this->processEmailRecord($person, $contact, $contact->email, $callback_function);
}
}
private function processEmailRecord($person, $contact, $emailRecord, $callback_function) {
call_user_func($callback_function, $person, $contact, $emailRecord);
}
public function emailCallback($person, $contact, $emailRecord) {
$this->people[$person->id] = $emailRecord->emailAddress;
}
// Retrieves a list of emails keyed by id
public function getPeople() {
$parties = $this->capsule->party->getList();
$this->people = array();
foreach ($parties->parties->person as $person) {
// debug(print_r($person, TRUE));
// Create a little summary of this person
$this->processPersonContacts($person, $this->emailCallback);
// $firstname = property_exists($person, 'firstName') ? $person->firstName : "";
// $lastname = property_exists($person, 'lastName') ? $person->lastName : "";
// $organisation = property_exists($person, 'organisationName') ? $person->organisationName : "";
// $this->debug("Person ($id): $firstname $lastname ($organisation)\n");
}
return $people;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment