Home  >  Article  >  Backend Development  >  Using ThinkPHP5 to implement the processing method of students' unsubmitted homework and submitted homework information in the homework management system

Using ThinkPHP5 to implement the processing method of students' unsubmitted homework and submitted homework information in the homework management system

不言
不言Original
2018-06-08 09:48:141372browse

This article mainly introduces the thinkingPHP5 implementation of the method of handling students' unpaid homework and handed-in homework information in the homework management system, involving thinkPHP's implementation skills for data table query and traversal operations. Friends in need can refer to the following

The example of this article describes the method of using ThinkPHP5 to handle students' unsubmitted homework and handed-in homework information in the homework management system. Share it with everyone for your reference, the details are as follows:

In the homework management system, after students log in to the personal center, they can view their submitted homework and unsubmitted homework through the menu on the left. So how to query these data in the system? First, we need to figure out the relationship between the three tables of Student, Class, and Submit.

1. Every student belongs to a class

2. Every student in the class will be assigned the same homework

3. After students submit their homework, they will Add response records to the submission table, such as student ID, assignment ID, submitted content, etc.

You can follow the following steps to obtain the submitted homework and unsubmitted homework of students

1. Get all the homework of 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 can be seen from the above code lesson, first according to Obtain student information through the student ID ($stuno), obtain the class information of the student through the class ID (clas_id) saved in the student information table, and finally obtain the many-to-many relationship between the class and the homework sheet (see the Thinkphp5 official manual for details about the model The related part of the content) to obtain all the assignments assigned by the student's class.

2. Get students’ unsubmitted assignments

//获取某学生所有未交作业
 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]);//删除已提交作业
  }
 }
 return $alltask;
 }

This function first calls the function to obtain all assignments ($this->getTasks($stuno)) to obtain all assignments in the student’s class. This data set is a two-dimensional array. Traverse the two-dimensional array to see if there is any homework in the two-dimensional array that has been submitted to Submit by the student. If so, delete the element.

3. Obtain the homework submitted by students

With the above two functions, it becomes simple to obtain the homework submitted by the students. The two-dimensional array obtained by the first function is subtracted from the second The arrays returned by the two functions are the collection of homework that students have submitted. Just do the difference of the two-dimensional arrays

//获取某学生所有已交作业(所有作业和未交作业的差集)
 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 entire content of this article. I hope it will be helpful to everyone's learning. More Please pay attention to the PHP Chinese website for related content!

Related recommendations:

ThinkPHP realizes the conversion of database query result data into the corresponding type

thinkPHP3.2.3 combines with Laypage to realize the paging function

The above is the detailed content of Using ThinkPHP5 to implement the processing method of students' unsubmitted homework and submitted homework information in the homework management system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn