progetto201 API
|
USERCOLOR: manages user's color. More...
Functions | |
get_usercolor ($t_conn_res) | |
Returns the UI color data inside the 'data' property of an array. More... | |
post_usercolor ($t_conn_res) | |
Set's the new UI color passed by the client. More... | |
Variables | |
$response = array('errors' => array()) | |
Prepare default response array with no errors. More... | |
USERCOLOR: manages user's color.
Client perspective:
This script sets the returned content type to JSON, includes the db_connection.php script
It is used to connect to MySQL and execute basic SELECT queries
and then defines the response array.
Two functions are defined:
get_usercolor($t_conn_res)
Selects the user color from the database so that the script can echo it
post_usercolor($t_conn_res)
Sets the user color inside the options table (colors param must be passed)
If the script isn't included it tries to connect to the database, and checks the request method:
When the called function ends the connection to the DB gets terminated, and data (or errors) is collected inside the response array. The response array gets echoed to the client in JSON format
Errors list:
get_usercolor | ( | $t_conn_res | ) |
Returns the UI color data inside the 'data' property of an array.
The function, using the mysqli object inside the parameter $t_conn_res ($t_conn_res['connect_obj']), executes the query '$query' which collects the color previously selected by the user.
There is always a value (the default one is 'red').
If the query execution throws an error the error is collected inside the 'errors' property of the array (which is also an array). The errors inside the 'errors' array have three properties:
the message is in english, language translation is going to be managed from the frontend
The user's color data is an array and is structured as following:
format of color_hex:
#RRGGBB
Example with no errors
If there are errors they will be pushed inside the errors array. Possible returned errors:
array | $t_conn_res | array with the connection object (connection was successful) |
post_usercolor | ( | $t_conn_res | ) |
Set's the new UI color passed by the client.
The function checks if a POST parameter called 'color' was passed, if so it executes the query that makes sure that the color exists inside the colors table and modifies the set color inside the options table. For last it checks if the query modified one row (as expected) and returns the color inside the 'data' property of the returned array.
Example with no errors
If there are errors they will be pushed inside the errors array. Possible returned errors:
The errors inside the 'errors' array have three properties:
the message is in english, language translation is going to be managed from the frontend
array | $t_conn_res | array with the connection object |
$response = array('errors' => array()) |
Prepare default response array with no errors.