Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Customer and customers classes for Dalnix Control panel
- *
- * @author larsemil
- */
- class Customers {
- //put your code here
- function __construct()
- {
- $this->debugSetting = False;
- $this->debugmsg = "----DEBUG OF CLASS CUSTOMERS ---\n";
- $this->customers = array();
- //constructor of class, establish databaseconnection
- $username = "dalnix_se";
- $password = "";
- $database = "customerpanel";
- try{
- $this->dbh = new PDO("mysql:host=localhost;dbname=".$database, $username, $password);
- $this->debug("Connected to database");
- }
- catch(PDOException $e)
- {
- $this->debug($e->getMessage());
- }
- //retrieve list of customers
- $this->retrieveCustomers();
- }
- function __destruct()
- {
- //we close the database upon class destruction
- $this->dbh = null;
- if($this->debugSetting)
- print $this->debugmsg;
- }
- function debug($msg)
- {
- //adds the message to the debugbuffer
- if(is_array($msg))
- {
- foreach($msg as $row)
- {
- $newmsg.=$row."\n";
- }
- $msg = $newmsg;
- }
- $this->debugmsg.="\n".$msg;
- }
- function retrieveCustomers()
- {
- //returns the customers in form of array
- $sql = "select * from customers order by name asc;";
- foreach($this->dbh->query($sql) as $customer)
- {
- $this->customers[] = new Customer($customer['id'],$customer['name'],$customer['contact_person'],$customer['email'],$customer['phonenumber'],$customer['orgnr']);
- $this->debug("Added ".$customer['name']." to list of customers");
- }
- }
- function getCustomers()
- {
- $returnArr =array();
- foreach($this->customers as $customer)
- {
- $returnArr[] = array("id" => $customer->getId(), "name" => $customer->getName());
- }
- return $returnArr;
- }
- }
- class Customer{
- function __construct($id,$name,$contactPerson,$email,$phonenumber,$orgnr)
- {
- $this->id = $id;
- $this->name = $name;
- $this->contactPerson = $contactPerson;
- $this->email = $email;
- $this->phonenumber = $phonenumber;
- $this->orgnr = $orgnr;
- }
- function getName()
- {
- return $this->name;
- }
- function getContactPerson()
- {
- return $this->contactPerson;
- }
- function getEmail()
- {
- return $this->email;
- }
- function getPhonenumber()
- {
- return $this->phonenumber;
- }
- function getOrgnr()
- {
- return $this->orgnr;
- }
- function getId()
- {
- return $this->id;
- }
- function setName($name)
- {
- $this->name = $name;
- }
- function setContactPerson($contactPerson)
- {
- $this->contactPerson = $contactPerson;
- }
- function setEmail($email)
- {
- $this->email = $email;
- }
- function setPhonenumber($phonenumber)
- {
- $this->phonenumber = $phonenumber;
- }
- function setOrgnr($orgnr)
- {
- $this->orgnr = $orgnr;
- }
- function setId($id)
- {
- $this->id = $id;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement