contactManager.class.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Keeps track of the people in our contact list.
  4. *
  5. * Starts with a standard contact list and can add
  6. * new people to our list or change existing contacts.
  7. * This class is for example purposes only, just to
  8. * show how to create a webservice
  9. */
  10. class contactManager{
  11. /**
  12. * Gets the current contact list.
  13. * @return contact[]
  14. */
  15. public function getContacts() {
  16. $contact = new contact();
  17. $contact->address = new Address();
  18. $contact->address->city ="sesamcity";
  19. $contact->address->street ="sesamstreet";
  20. $contact->email = "me@you.com";
  21. $contact->id = 1;
  22. $contact->name ="me";
  23. $ret[] = $contact;
  24. //debugObject("contacten: ",$ret);
  25. return $ret;
  26. }
  27. /**
  28. * Gets the contact with the given id.
  29. * @param int The id
  30. * @return contact
  31. */
  32. public function getContact($id) {
  33. //get contact from db
  34. //might wanna throw an exception when it does not exists
  35. $c = new contact();
  36. $c->id = $id;
  37. $c->name= "Automatic contact $id";
  38. $c->email= "Automatic$id@contact.org";
  39. return $c;
  40. throw new Exception("Contact '$id' not found");
  41. }
  42. /**
  43. * Generates an new, empty contact template
  44. * @return contact
  45. */
  46. public function newContact() {
  47. return new contact();
  48. }
  49. /**
  50. * Saves a given contact
  51. * @param contact
  52. * @return void
  53. */
  54. public function saveContact(contact $contact) {
  55. $contact->save();
  56. }
  57. }
  58. ?>