8. Polls - software-projects-qubit/Software-Project-1.0 GitHub Wiki
SRC POLLS
POST POLLS
We use the PHP script called polls. We post a poll by first getting the ACTION attribute from the interaction of the user with the app interface, we store that a $choice attribute. $choice can take POST_POLL OR READ_ALL_POLLS. POST_POLL will be the $choice this time and using the switch statement logic, we will use the case of POST_POLL. We request the SRC_MEMBER_USER which is the name of a certain SRC member, we store that in $member_username. We get the POST_TITLE and store it in $post_title, we also get the POLL_DESC which is the polls description details detailing how everything should be done and this is store in $poll_desc, we also get POLL_CHOICE which is the choice(s) that the SRC member chooses to have in that certain poll; you can have Single select(to choose only one option at a time) or have multi-select(multiple options at a time), and that is stored in $poll_choices. POLL_TYPE is self-explanatory and it is stored in $poll_type. We finally get POLL_DATE and POLL_TIME which are stored in $poll_date and $poll_time respectively. We then take all of these attributes values, bind them into a statement called $stmt(prevents SQL injection), then turn them into an array of arguments and insert them into our SRC_POLL_TABLE using the database manager which takes both the $stmt and $args. We then break out of the switch case statement since we are done
READ POLL
We use $choice which stores the ACTION that the SRC member intends on doing. The ACTION should be READ_ALL_POLLS, which then according to our switch statement, this section of the code will be executed. We use $stmt to store the statement to be run by our database manager. We select * from the SRC_POLL_TABLE, that means we fetch everything from the SRC_POLL table using our database manager which uses the $stmt and $args(they will be empty). We then break out of the switch case statement since we are done.
STUDENT POLLS
POST POLLS
We use the PHP script called polls. We post a poll by first getting the ACTION attribute from the interaction of the Student with the app interface, we store that a $choice attribute. $choice can take POST_POLL OR READ_ALL_POLLS. POST_POLL will be the $choice this time and using the switch statement logic, we will use the case of POST_POLL. We request the STUDENT_USERNAME which is the name of a certain Student, we store that in $student_username. We get the POST_TITLE and store it in $post_title, we also get the POLL_DESC which is the polls description details detailing how everything should be done and this is store in $poll_desc, we also get POLL_CHOICE which is the choice(s) that the student chooses to have in that certain poll; you can have Single select(to choose only one option at a time) or have multi-select(multiple options at a time), and that is stored in $poll_choices. POLL_TYPE is self-explanatory and it is stored in $poll_type. We finally get POLL_DATE and POLL_TIME which are stored in $poll_date and $poll_time respectively. We then take all of these attributes values, bind them into a statement called $stmt(prevents SQL injection), then turn them into an array of arguments and insert them into our STUDENT_POLL_TABLE using the database manager which takes both the $stmt and $args. We then break out of the switch case statement since we are done
READ POLL
We use $choice which stores the ACTION that the Student intends on doing. The ACTION should be READ_ALL_POLLS, which then according to our switch statement, this section of the code will be executed. We use $stmt to store the statement to be run by our database manager. We select * from the STUDENT_POLL_TABLE, that means we fetch everything from the SRC_POLL table using our database manager which uses the $stmt and $args(they will be empty). We then break out of the switch case statement since we are done.