function parse_file($now, $filekey, $fun) { $lines = file($this->files[$filekey]); try { $lines = $this->get_lines($filekey, $lines); } catch (Exception $e) { $this->errorlog[] = $e->getMessage(); return; } $count = CoursePrefsConfig::findByUnique($filekey . '_lines'); foreach ($lines as $line) { $count->setValue($count->getValue() + 1); $this->{$fun}($now, $line); // Update counter $count->save(); } }
static function getNamedValue($name) { return CoursePrefsConfig::findByUnique($name)->getValue(); }
function validation($data) { global $USER; $errorlog = array(); $form_errorlog = $this->_form->_errors; $user = CoursePrefsUser::findByUnique($USER->username); $courses = $user->getCoursesAsTeacher(); $this->course_create = array(); $this->course_enroll = array(); $enroll_default = CoursePrefsConfig::getNamedValue('course_enroll_days'); $create_default = CoursePrefsConfig::getNamedValue('course_create_days'); // Parse form submission and glean necessary information foreach ($data as $key => $value) { $matches = array(); if (preg_match(CREATE_DAYS_PATTERN, $key, $matches) && $courses[$matches[2]]) { if (!$this->course_create[$matches[1]]) { $this->course_create[$matches[1]] = array(); } $this->course_create[$matches[1]][$matches[2]] = $value; } else { if (preg_match(ENROLL_DAYS_PATTERN, $key, $matches) && $courses[$matches[2]]) { if (!$this->course_enroll[$matches[1]]) { $this->course_enroll[$matches[1]] = array(); } $this->course_enroll[$matches[1]][$matches[2]] = $value; } } } // Iterate over semesters and check course-specific settings are valid foreach ($this->course_create as $semestersid => $courses) { // Check whether the courses' creation value is greater than or equal to its enrollment value foreach ($courses as $coursesid => $value) { /*// Skip course if either of its create or enroll fields weren't submitted properly if ($form_errorlog[$semestersid . CREATE_DAYS_FIELD . $coursesid] || $form_errorlog[$semestersid . ENROLL_DAYS_FIELD . $coursesid]) { continue; }*/ $course_create_days = $this->course_create[$semestersid][$coursesid]; $course_enroll_days = $this->course_enroll[$semestersid][$coursesid]; if ($course_create_days === '0' || $course_enroll_days === '0') { unset($this->course_enroll[$semestersid][$coursesid]); unset($this->course_create[$semestersid][$coursesid]); $errorlog[$semestersid . COURSE_GROUP . $coursesid] = get_string('err_negative_number', 'block_courseprefs'); continue; } if ($course_create_days == '') { $this->course_create[$semestersid][$coursesid] = $create_default; } if ($course_enroll_days == '') { $this->course_enroll[$semestersid][$coursesid] = $enroll_default; } /* if ($course_create_days == '' && $course_enroll_days != '') { $a->name = 'Create'; $errorlog[$semestersid . COURSE_GROUP . $coursesid] = get_string('err_days_invalid', 'block_courseprefs', $a); } else if ($course_enroll_days == '' && $course_create_days!='') { $a->name = 'Enroll'; $errorlog[$semestersid . COURSE_GROUP . $coursesid] = get_string('err_days_invalid', 'block_courseprefs', $a); } */ // Log an error if the course's enrollment value is greater than the creation value if ($course_create_days < $course_enroll_days) { $errorlog[$semestersid . COURSE_GROUP . $coursesid] = get_string('err_create_enroll_compare', 'block_courseprefs'); } } } return $errorlog; }
if (!$configs[$key]) { $config = new CoursePrefsConfig($key, $value); } else { if ($configs[$key]) { $config = $configs[$key]; $config->setValue($value); } else { continue; } } $config->save(); } //Redirect back redirect("{$CFG->wwwroot}"); } else { if (!$form->is_submitted()) { //Load the form with the correct values $form_data = array(); $configs = CoursePrefsConfig::findAll(); foreach ($configs as $config) { $form_data[$config->getName()] = $config->getValue(); } $form->set_data($form_data); } } $strcourseprefsconf = get_string('blockname', 'block_courseprefs'); $navigation = array(array('name' => $strcourseprefsconf, 'link' => '', 'type' => 'title'), array('name' => $strcourseprefsconf . ' Settings', 'link' => '', 'type' => 'title')); print_header_simple($strcourseprefsconf, '', build_navigation($navigation)); print_heading('Configuring a ' . $strcourseprefsconf . ' block'); $form->display(); print_footer();