This article mainly introduces the method of ThinkPHP5 to deal with the non-hand assignment and the homework information in the job management system, and involves the implementation skills of thinkphp query and traversal operation for the data table, the friends can refer to the following
In this paper, we describe the method of ThinkPHP5 to deal with the non-hand assignment and the homework information in the job management system. Share to everyone for your reference, as follows:
In the job management system, students log in to the personal center and can view their submitted jobs and uncommitted jobs from the menu on the left. So how does this data query be implemented in the system? First we need to figure out the relationship between the three tables of students (Student), Class (Class), Job submission form (submit).
1. Each student belongs to a class
2. Every student in the class will be assigned the same assignment.
3. When a student submits a job, a response record is added to the job submission form, such as the student's ID, the job ID, the submitted content, and so on.
You can follow the steps below to obtain student hand-over and non-handed assignments.
1. Get all the jobs in your student's class
Get all jobs in the student's class public function Gettasks ($stuno) {$stu = $this:: Get ([' stu_no ' = $stuno]); $clas =clas::get ([' Clas_ id ' = ' $stu [' clas_id ']]); return $clas->task; }
As seen in the code lesson above, first obtain student information according to the number ($stuno), through the Student information table saved class ID (clas_id) to obtain the student's class information, Finally, through the many-to-many relationship between the class and the homework table (see the THINKPHP5 official manual on the model's relevance section), get all the assignments that the student's class is assigned to.
2. Obtaining student's non-delivery assignments
Get a student all non-handed jobs 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 job }} return $alltask;}
The function first calls the function that gets all the jobs ($this->gettasks ($stuno)) to get all the jobs in the student's class. This data set is a two-dimensional array that iterates through the two-dimensional array to see if any of the jobs in the two-dimensional array have been submitted to the submission by the student and delete the element if committed.
3. Get students to hand in homework
With the above two functions, it is easy to get the work done, the first function to get the two-dimensional array minus the second function returned by the array is the student has handed over the work of the collection, do the next two-dimensional array of the difference can be
Get a student all handed jobs (difference set for all jobs and non-handed jobs) 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 the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!