#Getting Started:# The questions can be answered within the appropriate file. (I.e. Question 1 can be answered in the file: question_1.php) unless otherwise stated in the question.
Each file will contain further instructions on where to insert your code.
#Question 1:# Given a MySQL database with the following tables:
CREATE TABLE `customer` (
`customer_id` INT(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`last_name` VARCHAR(255) NOT NULL,
`customer_occupation_id` INT(11) DEFAULT NULL,
PRIMARY KEY (`customer_id`)
)
CREATE TABLE `customer_occupation` (
`customer_occupation_id` INT(11) NOT NULL AUTO_INCREMENT,
`occupation_name` VARCHAR(255) NOT NULL,
`salary` INT(7) NOT NULL,
PRIMARY KEY (`customer_occupation_id`)
)
Modify the file question_1.php to show the list of all customers from the table customer
together with their occupations from the customer_occupation
table in the MySQL database to display on a web page.
A database connection will need to be created
If the customer does not have a matching occupation, please list them as 'un-employed'
Finally, include an optional GET parameter named occupation_name
which can be accepted from the user to filter and display any customers with a matching occupation_name
I.e: A request such as: /question_1.php?occupation_name=Manager will display all customers with an occupation of: "Manager"
#Question 2:# There are 3 types of customers:
- Bronze
- Silver
- Gold
Whenever a deposit is made:
- Bronze customers do not receive any extra credits
- Silver customers get 5% extra credit added their account balance (e.g. depositing $100 gives them $105)
- Gold customers get 10% extra credit added to their account balance (e.g. depositing $100 gives them $110)
Using question_2.php, create sub-classes of the Customer class for the 3 customer types - Bronze_Customer, Silver_Customer, and Gold_Customer
Create the deposit method(s) called deposit()
that takes the deposit amount as its argument and increments the $balance of the object by the deposit amount PLUS the extra credit (if any)
#Question 3:# The first character of the customer IDs represents the customer type:
- B for Bronze
- S for Silver
- G for Gold
The customer ID is then followed by a set of numbers (no longer than 10 characters total).
So a customer with customer ID: 'B2345' is a Bronze customer, 'S5678' is a Silver customer, and 'G1234' is a Gold customer.
Use your file question_2.php and create a factory method called 'get_instance()' to instantiate the correct object (Gold, Silver or Bronze customer) given a customer ID described above.
When an invalid customer ID is passed to the factory method, make it throw an InvalidArgument exception
#Question 4:# When a new customer is created, a unique username needs to be generated for the customer.
As per the requirements around customer IDs outlined in Question 3 the customer's username needs to begin with a specified character as follows:
- B for Bronze
- S for Silver
- G for Gold
The username is then followed by a set of alphanumeric characters (no longer than 30 characters total). It cannot contain any special characters or spaces.
For example, a Bronze customer may have the following generated username: B2b6483600ewq6
Utilize the customer class(es) you have setup in question_2.php and add any required additional methods/members to these classes where appropriate in order to provide method(s) called generate_username()
which will generate and return a valid username as a string
#Assumed database credentials:# Host: localhost / 127.0.0.1 Port: 3306 Username: test Password: test Schema: test
#Some assumed coding standards:# DocBlocks are required for all functions/classes. All DocBlocks must comply with PHPDoc standard. Please assume Register Globals is disabled within your PHP environment - you must utilize superglobals where appropriate.