/** * Process the data from the form. * * @param array $data * @return array of warnings */ public function process($data) { $bulk = new bulk_insert($this->item); // Bulk insert messages the data to be passed in // ie: for all grades of empty grades apply the specified value. if ($bulk->is_applied($data)) { $filter = $bulk->get_type($data); $insertvalue = $bulk->get_insert_value($data); // Appropriately massage data that may not exist. if ($this->supports_paging()) { $gradeitem = grade_item::fetch(array('courseid' => $this->courseid, 'id' => $this->item->id)); $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : ''; foreach ($this->items as $itemid => $item) { $field = "finalgrade_{$gradeitem->id}_{$itemid}"; if (isset($data->{$field})) { continue; } $grade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $itemid)); $data->{$field} = empty($grade) ? $null : $grade->finalgrade; $data->{"old{$field}"} = $data->{$field}; preg_match('/_(\\d+)_(\\d+)/', $field, $oldoverride); $oldoverride = 'oldoverride' . $oldoverride[0]; if (empty($data->{$oldoverride})) { $data->{$field} = !isset($grade->rawgrade) ? $null : $grade->rawgrade; } } } foreach ($data as $varname => $value) { if (preg_match('/override_(\\d+)_(\\d+)/', $varname, $matches)) { $data->{$matches}[0] = '1'; } if (!preg_match('/^finalgrade_(\\d+)_/', $varname, $matches)) { continue; } $gradeitem = grade_item::fetch(array('courseid' => $this->courseid, 'id' => $matches[1])); $isscale = $gradeitem->gradetype == GRADE_TYPE_SCALE; $empties = (trim($value) === '' or $isscale and $value == -1); if ($filter == 'all' or $empties) { $data->{$varname} = ($isscale and empty($insertvalue)) ? -1 : $insertvalue; } } } return parent::process($data); }
/** * Process the data from the form. * * @param array $data * @return array of warnings */ public function process($data) { $bulk = new bulk_insert($this->item); // Bulk insert messages the data to be passed in // ie: for all grades of empty grades apply the specified value. if ($bulk->is_applied($data)) { $filter = $bulk->get_type($data); $insertvalue = $bulk->get_insert_value($data); $userid = $this->item->id; foreach ($this->items as $gradeitemid => $gradeitem) { $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : ''; $field = "finalgrade_{$gradeitem->id}_{$this->itemid}"; if (isset($data->{$field})) { continue; } $oldfinalgradefield = "oldfinalgrade_{$gradeitem->id}_{$this->itemid}"; // Bulk grade changes for all grades need to be processed and shouldn't be skipped if they had a previous grade. if ($gradeitem->is_course_item() || $filter != 'all' && !empty($data->{$oldfinalgradefield})) { if ($gradeitem->is_course_item()) { // The course total should not be overridden. unset($data->{$field}); unset($data->oldfinalgradefield); $oldoverride = "oldoverride_{$gradeitem->id}_{$this->itemid}"; unset($data->{$oldoverride}); $oldfeedback = "oldfeedback_{$gradeitem->id}_{$this->itemid}"; unset($data->{$oldfeedback}); } continue; } $grade = grade_grade::fetch(array('itemid' => $gradeitemid, 'userid' => $userid)); $data->{$field} = empty($grade) ? $null : $grade->finalgrade; $data->{"old{$field}"} = $data->{$field}; } foreach ($data as $varname => $value) { if (preg_match('/^oldoverride_(\\d+)_(\\d+)/', $varname, $matches)) { // If we've selected overriding all grades. if ($filter == 'all') { $override = "override_{$matches[1]}_{$matches[2]}"; $data->{$override} = '1'; } } if (!preg_match('/^finalgrade_(\\d+)_(\\d+)/', $varname, $matches)) { continue; } $gradeitem = grade_item::fetch(array('courseid' => $this->courseid, 'id' => $matches[1])); $isscale = $gradeitem->gradetype == GRADE_TYPE_SCALE; $empties = (trim($value) === '' or $isscale and $value == -1); if ($filter == 'all' or $empties) { $data->{$varname} = ($isscale and empty($insertvalue)) ? -1 : $insertvalue; } } } return parent::process($data); }