ThinkPHP5 An example of how to deal with the information of students ' outstanding work and hand-work in the job management system _php

Source: Internet
Author: User
Tags php template smarty template

This paper gives an example of how to deal with the information of students ' ThinkPHP5 and hand-work in the Operation management system. Share to everyone for your reference, specific as follows:

In the job management system, students can view their submitted jobs and uncommitted jobs through the menu on the left by logging on to the personal center. So how do you implement queries for this data in the system? First we need to find out the relationship between the three tables (Student), Class (Class), and homework submission form (submit).

1. Each student belongs to a class

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

3. After the student submits the job, a record of the response is added to the job submission table, such as the student ID, the job ID, the content submitted, and so on.

The following steps can be taken to obtain the student's hand in and the outstanding homework

1. Get all the homework in the student's class

Gets all job public
 function Gettasks ($stuno)
 {
 $stu = $this:: Get ([' Stu_no ' => $stuno])
 in the student's class $clas =clas::get ([' clas_id ' => $stu [' clas_id ']]);
 return $clas->task;
 }

From the above code lesson, first, according to the school number ($stuno) to obtain student information, through the Student information table to save the class ID (clas_id) and then get the student's class information, Finally, through the relationship between the class and the job table (see THINKPHP5 's Official Handbook about the associated part of the model), get all the homework assigned by the student's class.

2. Acquisition of students ' unpaid homework

Get all outstanding jobs for a student public
 function Getunsubmittasks ($stuno)
 {
 $stu = $this:: Getting ([' 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;
 }

The function first calls the function that gets all the jobs ($this->gettasks ($stuno)) to get all the jobs in the student's class. The dataset is a two-dimensional array, traversing the two-dimensional array to see if any of the jobs in the two-dimensional array have been submitted by the student to the submit and delete the element if committed.

3. Get students to hand in their homework

With the above two functions, get the things that have been handed to the job is simple, the first function to obtain a two-dimensional array minus the second function of the array is returned by the students have to work the collection, do the next two-dimensional array of the difference can be

Obtain a student's all handed jobs (the difference set for all jobs and unpaid 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 I use THINKPHP5 to establish student assignment management system practice in the Student Assignment list solution, if you have a better method, welcome criticism correction!

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.