Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * Customer and customers classes for Dalnix Control panel
  4. *
  5. * @author larsemil
  6. */
  7. class Customers {
  8. //put your code here
  9.  
  10.  
  11.  
  12. function __construct()
  13. {
  14. $this->debugSetting = False;
  15. $this->debugmsg = "----DEBUG OF CLASS CUSTOMERS ---\n";
  16. $this->customers = array();
  17. //constructor of class, establish databaseconnection
  18. $username = "dalnix_se";
  19. $password = "";
  20. $database = "customerpanel";
  21. try{
  22. $this->dbh = new PDO("mysql:host=localhost;dbname=".$database, $username, $password);
  23. $this->debug("Connected to database");
  24. }
  25. catch(PDOException $e)
  26. {
  27. $this->debug($e->getMessage());
  28. }
  29.  
  30. //retrieve list of customers
  31. $this->retrieveCustomers();
  32. }
  33.  
  34. function __destruct()
  35. {
  36. //we close the database upon class destruction
  37. $this->dbh = null;
  38. if($this->debugSetting)
  39. print $this->debugmsg;
  40. }
  41.  
  42. function debug($msg)
  43. {
  44. //adds the message to the debugbuffer
  45.  
  46. if(is_array($msg))
  47. {
  48. foreach($msg as $row)
  49. {
  50. $newmsg.=$row."\n";
  51. }
  52. $msg = $newmsg;
  53.  
  54. }
  55. $this->debugmsg.="\n".$msg;
  56. }
  57.  
  58. function retrieveCustomers()
  59. {
  60. //returns the customers in form of array
  61. $sql = "select * from customers order by name asc;";
  62. foreach($this->dbh->query($sql) as $customer)
  63. {
  64. $this->customers[] = new Customer($customer['id'],$customer['name'],$customer['contact_person'],$customer['email'],$customer['phonenumber'],$customer['orgnr']);
  65. $this->debug("Added ".$customer['name']." to list of customers");
  66. }
  67. }
  68.  
  69. function getCustomers()
  70. {
  71. $returnArr =array();
  72. foreach($this->customers as $customer)
  73. {
  74. $returnArr[] = array("id" => $customer->getId(), "name" => $customer->getName());
  75.  
  76. }
  77.  
  78. return $returnArr;
  79.  
  80. }
  81. }
  82.  
  83. class Customer{
  84. function __construct($id,$name,$contactPerson,$email,$phonenumber,$orgnr)
  85. {
  86. $this->id = $id;
  87. $this->name = $name;
  88. $this->contactPerson = $contactPerson;
  89. $this->email = $email;
  90. $this->phonenumber = $phonenumber;
  91. $this->orgnr = $orgnr;
  92.  
  93. }
  94.  
  95. function getName()
  96. {
  97. return $this->name;
  98. }
  99.  
  100. function getContactPerson()
  101. {
  102. return $this->contactPerson;
  103. }
  104.  
  105. function getEmail()
  106. {
  107. return $this->email;
  108. }
  109.  
  110. function getPhonenumber()
  111. {
  112. return $this->phonenumber;
  113. }
  114.  
  115. function getOrgnr()
  116. {
  117. return $this->orgnr;
  118. }
  119.  
  120. function getId()
  121. {
  122. return $this->id;
  123. }
  124.  
  125. function setName($name)
  126. {
  127. $this->name = $name;
  128. }
  129.  
  130. function setContactPerson($contactPerson)
  131. {
  132. $this->contactPerson = $contactPerson;
  133. }
  134.  
  135. function setEmail($email)
  136. {
  137. $this->email = $email;
  138. }
  139.  
  140. function setPhonenumber($phonenumber)
  141. {
  142. $this->phonenumber = $phonenumber;
  143. }
  144.  
  145. function setOrgnr($orgnr)
  146. {
  147. $this->orgnr = $orgnr;
  148. }
  149.  
  150. function setId($id)
  151. {
  152. $this->id = $id;
  153. }
  154.  
  155.  
  156.  
  157.  
  158. }
  159.  
  160. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement