我想为类表创建一个等待列表。因此,如果已报名上课的学生人数已满,则所有新注册的学生都将被放入候补表。管理员可以指定一个班级是否有候补名单。如果管理员批准了该学生,则可以将其注册为该班级。类控制器中的add函数是
public function add()
{
$class = $this->Classes->newEntity();
if ($this->request->is('post')) {
$class = $this->Classes->patchEntity($class, $this->request->getData());
if ($this->Classes->save($class)) {
$this->Flash->success(__('The class has been saved.'));
$this->loadModel('Lessons');
$date = $class->start_date;
// Create lessons for eack week of the class
while($date <= $class->end_date) {
// Get the next lesson date after the start of the user's enrolment, then each week afterward using the loop
$lesson = $this->Lessons->newEntity();
$lesson->class_id = $class->id;
$lesson->teacher_id = $class->teacher_id;
$lesson->lesson_date = $date;
$this->Lessons->save($lesson);
$date = $date->modify('+1 week');
}
$choice = $class->waitlist;
if ($choice == "yes"){
$this ->loadModel('Waitlist');
}
return $this->redirect(['controller' => 'schools', 'action' => 'view', $class->school_id]);
}
$this->Flash->error(__('The class could not be saved. Please, try again.'));
}
$schools = $this->Classes->Schools->find('list', ['limit' => 200]);
$this->loadModel('Teachers');
$teachers = $this->Teachers->find('list');
$this->set(compact('class', 'schools', 'teachers'));
$this->set('_serialize', ['class']);
}
waitlist表具有以下字段:waitlist_id
,class_id
,student_id
和index
。
类表中的字段waitlist_id
是外键。