function action_prereqedit()
 {
     $curid = $this->required_param('id', PARAM_INT);
     $curcrsid = $this->required_param('association_id', PARAM_INT);
     $curcrs = new curriculumcourse($curcrsid);
     $curcrs->seturl(null, array('s' => $this->pagename, 'action' => 'prereqedit', 'id' => $curid));
     $prereqform = $curcrs->create_prerequisite_form();
     if ($prereqform->is_cancelled()) {
         $this->action_default();
         return;
     } else {
         if ($prereqform->is_submitted() && $prereqform->is_validated()) {
             $form_data = $prereqform->get_data();
             $output = '';
             $added = 0;
             $deleted = 0;
             /// Process requested prerequisite deletions.
             if (!empty($form_data->remove) && isset($form_data->sprereqs)) {
                 $sprereqs = $form_data->sprereqs;
             } else {
                 $sprereqs = array();
             }
             foreach ($sprereqs as $sprereq) {
                 if ($curcrs->del_prerequisite($sprereq)) {
                     $deleted++;
                 }
             }
             /// Process requested prerequisite additions.
             if (!empty($form_data->add) && isset($form_data->prereqs)) {
                 $prereqs = $form_data->prereqs;
             } else {
                 $prereqs = array();
             }
             foreach ($prereqs as $prereq) {
                 if (coursepage::_has_capability('block/curr_admin:course:view', $prereq) && $curcrs->add_prerequisite($prereq, !empty($form_data->add_to_curriculum))) {
                     $added++;
                 }
             }
             if ($deleted > 0) {
                 $delString = $deleted > 1 ? 'deleted_prerequisites' : 'deleted_prerequisite';
                 $output .= get_string($delString, 'block_curr_admin', $deleted);
             }
             if ($added > 0) {
                 $addString = $added > 1 ? 'added_prerequisites' : 'added_prerequisite';
                 $output .= ($deleted > 0 ? ' / ' : '') . get_string($addString, 'block_curr_admin', $added);
             }
             if ($deleted > 0 || $added > 0) {
                 $output .= "\n";
             }
             $curriculum = $curcrs->curriculum;
             if ($curriculum->iscustom) {
                 $curassid = $CURMAN->db->get_field(CURASSTABLE, 'id', 'curriculumid', $curriculum->id);
                 $stucur = new curriculumstudent($curassid);
                 redirect('index.php?s=stucur&section=curr&id=' . $stucur->id . '&action=edit', $output, 3);
             }
             echo $output;
             // recreate the form, to reflect changes in the lists
             $prereqform = $curcrs->create_prerequisite_form();
         }
     }
     $prereqform->display();
 }
Пример #2
0
 /**
  * Display form to manage prerequisites.
  */
 public function display_prereqedit()
 {
     $curid = $this->required_param('id', PARAM_INT);
     $curcrsid = $this->required_param('association_id', PARAM_INT);
     $curcrs = new curriculumcourse($curcrsid);
     $curcrs->seturl(null, array('s' => $this->pagename, 'action' => 'prereqedit', 'id' => $curid));
     $prereqform = $curcrs->create_prerequisite_form();
     if ($prereqform->is_cancelled()) {
         $this->display_default();
         return;
     } else {
         if ($prereqform->is_submitted() && $prereqform->is_validated()) {
             $formdata = $prereqform->get_data();
             $output = '';
             $added = 0;
             $deleted = 0;
             // Process requested prerequisite deletions.
             if (!empty($formdata->remove) && isset($formdata->sprereqs)) {
                 $sprereqs = $formdata->sprereqs;
             } else {
                 $sprereqs = array();
             }
             foreach ($sprereqs as $sprereq) {
                 if ($curcrs->del_prerequisite($sprereq)) {
                     $deleted++;
                 }
             }
             // Process requested prerequisite additions.
             if (!empty($formdata->add) && isset($formdata->prereqs)) {
                 $prereqs = $formdata->prereqs;
             } else {
                 $prereqs = array();
             }
             // TODO: Ugly, this needs to be overhauled.
             $cpage = new coursepage();
             foreach ($prereqs as $prereq) {
                 if ($cpage->_has_capability('local/elisprogram:course_view', $prereq) && $curcrs->add_prerequisite($prereq, !empty($formdata->add_to_curriculum))) {
                     $added++;
                 }
             }
             if ($deleted > 0) {
                 $delstring = $deleted > 1 ? 'deleted_prerequisites' : 'deleted_prerequisite';
                 $output .= get_string($delstring, 'local_elisprogram', $deleted);
             }
             if ($added > 0) {
                 $addstring = $added > 1 ? 'added_prerequisites' : 'added_prerequisite';
                 $output .= ($deleted > 0 ? ' / ' : '') . get_string($addstring, 'local_elisprogram', $added);
             }
             if ($deleted > 0 || $added > 0) {
                 $output .= "\n";
             }
             $curriculum = $curcrs->curriculum;
             if ($curriculum->iscustom) {
                 $curassid = $this->_db->get_field(curriculumstudent::TABLE, 'id', array('curriculumid' => $curriculum->id));
                 $stucur = new curriculumstudent($curassid);
                 redirect('index.php?s=stucur&section=curr&id=' . $stucur->id . '&action=edit', $output, 3);
             }
             echo $output;
             // Recreate the form, to reflect changes in the lists.
             $prereqform = $curcrs->create_prerequisite_form();
         }
     }
     $prereqform->display();
 }