$errors[] = get_string('err_invalid_section', 'block_courseprefs', $a); continue; } if (array_key_exists($sectionsid, $splits)) { $split = $splits[$sectionsid]; if ($i != $split->getGroupingsId()) { reset_prefs(array($split)); $split->setId(null); $split->setGroupingsId($i); } $split->setShellName($data->{'bucket_' . $i . '_name'}); $split->setStatus('todo'); insert_into_array($sections[$sectionsid], $changed_splits, $split->getShellName()); } else { $split = new CoursePrefsSplit($user->getId(), $sectionsid, $i, $data->{'bucket_' . $i . '_name'}, 'todo'); insert_into_array($sections[$sectionsid], $new_splits, $split->getShellName()); } // Try to save try { $split->save(); } catch (Exception $e) { $errors[] = 'Error trying to insert a split record.'; } } } $params = array($changed_splits, $new_splits, $errors); build_form('finished_content', $params, 'Next', ''); print_footer(); function insert_into_array($object, &$array, $key = null) { if ($key) {
continue; } $section = $sections[$sectionsid]; $suggested_idnumber = "{$section->year}{$section->name}{$user->getUsername()}cl{$i}"; if (array_key_exists($sectionsid, $crosslisted)) { $cr = $crosslisted[$sectionsid]; if ($suggested_idnumber == $cr->getIdnumber()) { $cr->setShellName($data->{'bucket_' . $i . '_name'}); $cr->setStatus('todo'); } else { reset_prefs(array($cr)); } insert_into_array($section, $changed_cr, $cr->getShellName()); } else { $cr = new CoursePrefsCrosslist($user->getId(), $sectionsid, 'todo', $data->{'bucket_' . $i . '_name'}, $suggested_idnumber); insert_into_array($section, $new_cr, $cr->getShellName()); } try { $cr->save(); } catch (Exception $e) { $errors[] = 'Could not save a cross list entry!'; } } } $params = array($changed_cr, $new_cr, $errors); build_form('finished_content', $params, 'Next', '', 'GET', 'crosslist.php'); print_footer(); function insert_into_array($object, &$array, $key = null) { if ($key) { if (!array_key_exists($key, $array)) {