public function process($data) { if ($this->isValid($data) !== true) { throw new C3op_Form_ContactCreateException('Invalid data!'); } else { $db = Zend_Registry::get('db'); $contactMapper = new C3op_Register_ContactMapper($db); $contact = new C3op_Register_Contact(); $contact->SetName($this->name->GetValue()); $contact->SetType($this->type->GetValue()); $contactMapper->insert($contact); } }
private function UpdatePhoneNumbers(C3op_Register_Contact $contact) { $currentPhoneNumbers = $contact->GetPhoneNumbers(); $oldPhoneNumbers = $this->fetchPhoneNumbers($contact); foreach ($oldPhoneNumbers as $key => $phoneNumber) { if (isset($currentPhoneNumbers[$key])) { $newPhoneNumber = $currentPhoneNumbers[$key]; if ($newPhoneNumber != $phoneNumber) { $this->db->exec(sprintf('UPDATE register_contacts_phone_numbers SET area_code = \'%s\', local_number = \'%s\', label = \'%s\' WHERE id = %d;', $newPhoneNumber['area_code'], $newPhoneNumber['local_number'], $newPhoneNumber['label'], $key)); } unset($currentPhoneNumbers[$key]); } else { $this->db->exec(sprintf('DELETE FROM register_contacts_phone_numbers WHERE id = %d;', $key)); } } reset($currentPhoneNumbers); foreach ($currentPhoneNumbers as $key => $phoneNumber) { $data = array('contact' => $contact->GetId(), 'area_code' => $phoneNumber['area_code'], 'local_number' => $phoneNumber['local_number'], 'label' => $phoneNumber['label']); $this->db->insert('register_contacts_phone_numbers', $data); } }