$students = Enrollment::all();
foreach ($students as $student) {
$assign_course_id = $student->course_id;
$assign_user_id = $student->user_id;
//echo $assign_user_id;
$assign_jobs = Submission::all();
$collection = collect($assign_jobs);
$merged = $collection->merge($assign_jobs)->random(2);
//echo $merged;
if (count($merged) > 0) {
for ($i = 0; $i < sizeof($merged); $i++) {
$jobid = $merged[$i]->id;
foreach ($merged as $job) {
if ($assign_user_id !== $job->user_id) {
$newjob = New PeerMarking;
$newjob->submission_id = $jobid;
$newjob->course_id = $assign_course_id;
$newjob->user_id = $assign_user_id;
$newjob->save();
//echo $assign_user_id;
}
// $merged = $collection->merge($assign_jobs)->random(2);
//
// $newjob = New AssignJob;
// $newjob->submission_id = $jobid;
// $newjob->course_id = $assign_course_id;
// $newjob->user_id = $assign_user_id;
// $newjob->save();
}
}
}
}
我想为当前在校的学生分配工作。 一名学生获得两次提交,一次提交将被标记两次。 学生只能获得别人的工作,不能获得自己的工作。 现在,我的数据库如下所示: