ThinkPHP5 implements the method of handling students who fail to submit homework and submitted homework information in the Job Management System, thinkphp5
This example describes how ThinkPHP5 can process students who have not handed in their homework and submitted their homework information in the Job Management System. We will share this with you for your reference. The details are as follows:
In the Job Management System, after logging on to the personal center, students can view their submitted and unsubmitted jobs in the left-side menu. How can we query the data in the system? First, we need to figure out the relationships between Student, class, and Submit tables.
1. Every student belongs to a class.
2. Each student in the class will be assigned the same assignment.
3. After submitting a assignment, the student adds a response record in the assignment submission table, such as the student ID, assignment ID, and submitted content.
You can follow these steps to obtain the students who have handed in homework and have not handed in homework
1. Obtain all assignments of the student's class
// Obtain all the public function getTasks ($ stuno) {$ stu = $ this: get (['stu _ no' => $ stuno]) of the student's class. $ clas = Clas: get (['clas _ id' => $ stu ['clas _ id']); return $ clas-> task ;}
According to the code above, the student information is obtained based on the student ID ($ stuno), and the class ID (clas_id) saved in the student information table is obtained before the student's class information is obtained, finally, you can use the many-to-many relationship between the class and the job table (For details, refer to the Association Section of the Thinkphp5 official Manual on the Model) to obtain all assignments of the student's class.
2. Obtain the assignments that students have not handed in
// Obtain all unfinished jobs of a student. public function getUnSubmitTasks ($ stuno) {$ stu = $ this: get (['stu _ no' => $ stuno]); $ alltask = $ this-> getTasks ($ stuno); foreach ($ alltask as $ key => $ value) {if (Submit :: get (['Task _ id' => $ value ['Task _ id'], 'stu _ id' => $ stu ['stu _ id']) {unset ($ alltask [$ key]); // Delete submitted jobs} return $ alltask ;}
This function first calls the function ($ this-> getTasks ($ stuno) to obtain all the jobs in the student's class. This dataset is a two-dimensional array that traverses this two-dimensional array to see if there are jobs in this two-dimensional array that the student has submitted to Submit. If yes, this element will be deleted.
3. Obtain assignments that students have handed in
With the above two functions, it is easy to get the tasks that have been handed in. The two-dimensional array obtained by the first function minus the array returned by the second function is the set of tasks that the student has handed in, evaluate the difference of the two-dimensional array.
// Obtain all submitted assignments of a student (the difference set between all assignments and those not submitted). public function getSubmitTasks ($ stuno) {$ unsubmit = $ this-> getUnSubmitTasks ($ stuno ); $ alltasks = $ this-> getTasks ($ stuno); $ submittasks = array (); foreach ($ alltasks as $ key => $ value) {if (! In_array ($ value, $ unsubmit) {$ submittasks [] = $ value ;}} return $ submittasks ;}
The above is my solution to the student assignment list in the practice of using ThinkPHP5 to establish a student assignment management system. If you have a better method, please criticize and correct it!