first_name = $first_name . $time; $contact->last_name = $last_name ; $contact->email1 = 'contact@'. $time. 'sugar.com'; if(!empty($id)) { $contact->new_with_id = true; $contact->id = $id; } $contact->save(); self::$_createdContacts[] = $contact; $GLOBALS['db']->commit(); return $contact; } public static function setCreatedContact($contact_ids) { foreach($contact_ids as $contact_id) { $contact = new Contact(); $contact->id = $contact_id; self::$_createdContacts[] = $contact; } // foreach } // fn public static function removeAllCreatedContacts() { $contact_ids = self::getCreatedContactIds(); $GLOBALS['db']->query('DELETE FROM contacts WHERE id IN (\'' . implode("', '", $contact_ids) . '\')'); } /** * removeCreatedContactsEmailAddresses * * This function removes email addresses that may have been associated with the contacts created * * @static * @return void */ public static function removeCreatedContactsEmailAddresses(){ $contact_ids = self::getCreatedContactIds(); $GLOBALS['db']->query('DELETE FROM email_addresses WHERE id IN (SELECT DISTINCT email_address_id FROM email_addr_bean_rel WHERE bean_module =\'Contacts\' AND bean_id IN (\'' . implode("', '", $contact_ids) . '\'))'); $GLOBALS['db']->query('DELETE FROM emails_beans WHERE bean_module=\'Contacts\' AND bean_id IN (\'' . implode("', '", $contact_ids) . '\')'); $GLOBALS['db']->query('DELETE FROM email_addr_bean_rel WHERE bean_module=\'Contacts\' AND bean_id IN (\'' . implode("', '", $contact_ids) . '\')'); } public static function removeCreatedContactsUsersRelationships(){ $contact_ids = self::getCreatedContactIds(); $GLOBALS['db']->query('DELETE FROM contacts_users WHERE contact_id IN (\'' . implode("', '", $contact_ids) . '\')'); } public static function getCreatedContactIds() { $contact_ids = array(); foreach (self::$_createdContacts as $contact) { $contact_ids[] = $contact->id; } return $contact_ids; } } ?>