/** * Unassign the courses from the program. * @param array $elements An array of course information to unassign from the program. * @param bool $bulkaction Whether this is a bulk-action or not. * @return array An array to format as JSON and return to the Javascript. */ protected function _respond_to_js(array $elements, $bulkaction) { global $DB; $programid = required_param('id', PARAM_INT); foreach ($elements as $courseid => $label) { if ($this->can_unassign($programid, $courseid) === true) { $assignrec = $DB->get_record(curriculumcourse::TABLE, array('curriculumid' => $programid, 'courseid' => $courseid)); $curriculumcourse = new curriculumcourse($assignrec); $curriculumcourse->delete(); } } return array('result' => 'success', 'msg' => 'Success'); }