-
Notifications
You must be signed in to change notification settings - Fork 8
Controller.php
- This document provides an overview of the file's structure and functionality.
- Controller.php contains all the functions used by every other part of the website.
-
Controller.PHP contains a few global properties
global $userInfoglobal $pdo
Check if a variable is safe to evaluate
Parameters
$var : mixed
Return boolean
- True if $var is safe and exists, otherwise false
Converts html chars to prevent html injection (supports up to 1d arrays)
Parameters
-
$params : any param- Any param to escape html injection
Return N/A
Iterates through details from db to ensure every key exists for the Customer object
Parameters
-
$details : array- Details array from the database
Return Customer|null
- A customer object with all details, or null if any didn't exist
Iterates through details from db to ensure every key exists for the Admin object
Parameters
-
$details : array- Details array from the database
Return Admin|null
- An admin object with all details, or null if any didn't exist
Puts all relevent user info into the global userInfo array
Parameters N/A
Return N/A
Checks if the user is logged in
Parameters N/A
Return boolean
- True if logged in, false if not
Attempts to log the user in using supplied credentials
Parameters
-
$user : string- Customer's username or email
-
$pass : string- Customer's password
Return boolean
- True if login succeeded, otherwise false
Registers users to the database if supplied information passes all checks
Parameters
-
$details : array- Associative array with relevent info (most likely just $_POST)
Return string
- Empty if succeeds (ie. evaluates to false), or a string to indicate where it failed
Get count of all customers in the database
Parameters N/A
Return int|boolean
- The count of customers if success, otherwise false
Get all customers in the database
Parameters N/A
Return array|boolean
- Array of customers if success, otherwise false
Updates a specified field in the database for a customer
Parameters
-
$details : array- Associative array containing field to change, new value and other relevant info
Return string
- Empty if succeeded, or a string to indicate where it failed
Deletes a customer and their associated orders
Parameters
-
$customerID : int- The customer's ID
Return string
- Empty if success, otherwise err message
Gets customer by their ID
Parameters
- ``$customerID : int`
- The ID of the customer
Return Customer|boolean
- The customer if success, otherwise false
Unsets both global arrays and destroys the session
Parameters N/A
Return N/A
Creates a product object with all details (minus cateogries and images) if exists
Parameters
-
$details : array- Details array from db
Return Product|null
- Product with required details, or null
Creates a productReview object with all details if exists
Parameters
-
$details : array- Details array from db
Return ProductReview|null
- Product with required details, or null
Sorts through the images of a product and finds the main one
Parameters
-
$images : array- The productImages as an array
-
$product : Product- The Product object to add to
Return N/A
Adds the images to the product
Parameters
-
$product : Prodcut- The product
Return N/A
Gets product from the database, regardless of stock
Parameters
-
$productID : int- ID of the product
Return Product|boolean
- Product if success, otherwise false
--INTERNAL USE ONLY-- Filters array to only have stocked products
Parameters
-
$products : array- Array of products to filter (will overwrite)
Return string|boolean
- True if success, otherwise a string for failu
Gets every product in the database, regardless of stock
Parameters N/A
Return array|boolean
- Array of products if succeeded, otherwise false
Get count of all products in the database
Parameters N/A
Return int|boolean
- The count of products if success, otherwise false
Gets every product in the database where stock > 0
Parameter N/A
Return array|boolean
- 2d array if succeeded, otherwise false
Gets all categories from the database
Parameters N/A
Return array|boolean
- Array of categories if succeeded, otherwise false
Adds a category to the prodcut via it's categoryID
Parameters
-
$product : Product- the product
Return string
- Empty if success, otherwise indicates failure
Adds categories to the products
Parameters
-
$products : array- The products array
return string
- Empty if success, otherwise indicates failure
Gets all products by category, regardless of stock
Parameters
-
$category : string- Category of the product (component, accessory etc.)
Return array|string
- Array of products if succeeded, otherwise a string where it failed
Gets all products by category where stock > 0
Parameters
-
$category : string- Category of the product (component, accessory etc)
Return array|string
- Array of products succeeded, otherwise string for failure
--INTERNAL USE ONLY-- Removes the product from the array by PID
Parameters
-
$products : array- the products array
-
productID : int- the ID of the product to remove
Return string
- Empty if success, otherwise indicates failure
Gets 3 random products, including from other categories if needed
Parameters
-
$productID : int- the ID of the product
Return array|string
- Array with 3 products if success, otherwise indicates failure
Checks if a customer has bought the product, and has not already left a review
Parameters
-
$customerID : int- the unique identifier of the customer
-
$productID : int- the unique identifier of the product
return boolean
- True if they are allowed to, otherwise false
--INTERNAL USE ONLY-- Checks all vars for leaving a review
Parameters
-
$productID : int- The product's ID
-
$customerID : int- The customer's ID
-
$rating : int- The rating value
-
$review : string- The review
Return string
- Empty if ok, otherwise an error message
Creates a rating for a product
Parameters
-
$productID : int- The product's ID
-
$customerID : int- The customer's ID
-
$rating : int- The rating value
-
$review : string- The review
Return string
- Empty if success, otherwise an error message
Updates a rating for a product
Parameters
-
$productID : int- The product's ID
-
$customerID : int- The customer's ID
-
$rating : int- The rating value
-
$review : string- The review
Return string
- Empty if success, otherwise an error message
Deletes a product review
Parameters
-
$productID : int- The product's ID
-
$customerID : int- The customer's ID
Return boolean
- True if success, otherwise false
Gets all productReviews by a customer
Parameters
-
$customerID : int- The customer's ID
Return array|boolean
- Array of ProductReview objects, or false
Gets all reviews on a product with a certain rating
Parameters
-
$productID : int- the product's ID
-
$rating : int- the rating value
return array|boolean
- Array of ProductReview objects, or false