public function validation($data, $files) { $errors = parent::validation($data, $files); if (!self::file_uploaded($data['bgimage'])) { $errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_' . $this->qtype()); } $allchoices = array(); for ($i = 0; $i < $data['nodropzone']; $i++) { $ytoppresent = trim($data['drops'][$i]['ytop']) !== ''; $xleftpresent = trim($data['drops'][$i]['ytop']) !== ''; $labelpresent = trim($data['drops'][$i]['droplabel']) !== ''; $choice = $data['drops'][$i]['choice']; $imagechoicepresent = $choice !== '0'; if ($imagechoicepresent) { if (!$ytoppresent) { $errors["drops[{$i}]"] = get_string('formerror_noytop', 'qtype_ddimageortext'); } if (!$xleftpresent) { $errors["drops[{$i}]"] = get_string('formerror_noxleft', 'qtype_ddimageortext'); } if ($data['dragitemtype'][$choice - 1] != 'word' && !self::file_uploaded($data['dragitem'][$choice - 1])) { $errors['dragitem[' . ($choice - 1) . ']'] = get_string('formerror_nofile', 'qtype_ddimageortext', $i); } if (isset($allchoices[$choice]) && !$data['drags'][$choice - 1]['infinite']) { $errors["drops[{$i}]"] = get_string('formerror_multipledraginstance', 'qtype_ddimageortext', $choice); $errors['drops[' . $allchoices[$choice] . ']'] = get_string('formerror_multipledraginstance', 'qtype_ddimageortext', $choice); $errors['drags[' . ($choice - 1) . ']'] = get_string('formerror_multipledraginstance2', 'qtype_ddimageortext', $choice); } $allchoices[$choice] = $i; } else { if ($ytoppresent || $xleftpresent || $labelpresent) { $errors["drops[{$i}]"] = get_string('formerror_noimageselected', 'qtype_ddimageortext'); } } } for ($dragindex = 0; $dragindex < $data['noitems']; $dragindex++) { $label = $data['drags'][$dragindex]['draglabel']; if ($data['dragitemtype'][$dragindex] == 'word') { $allowedtags = '<br><sub><sup><b><i><strong><em>'; $errormessage = get_string('formerror_disallowedtags', 'qtype_ddimageortext'); } else { $allowedtags = ''; $errormessage = get_string('formerror_noallowedtags', 'qtype_ddimageortext'); } if ($label != strip_tags($label, $allowedtags)) { $errors["drags[{$dragindex}]"] = $errormessage; } } return $errors; }
public function validation($data, $files) { $errors = parent::validation($data, $files); $bgimagesize = $this->get_image_size_in_draft_area($data['bgimage']); if ($bgimagesize === null) { $errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_ddmarker'); } $allchoices = array(); for ($i = 0; $i < $data['nodropzone']; $i++) { $choice = $data['drops'][$i]['choice']; $choicepresent = $choice !== '0'; if ($choicepresent) { //test coords here if ($bgimagesize !== null) { $shape = $data['drops'][$i]['shape']; $coordsstring = $data['drops'][$i]['coords']; $shapeobj = qtype_ddmarker_shape::create($shape, $coordsstring); $interpretererror = $shapeobj->get_coords_interpreter_error(); if ($interpretererror !== false) { $errors["drops[{$i}]"] = $interpretererror; } else { if (!$shapeobj->inside_width_height($bgimagesize)) { $errorcode = 'shapeoutsideboundsofbgimage'; $errors["drops[{$i}]"] = get_string('formerror_' . $errorcode, 'qtype_ddmarker'); } } } } else { if (trim($data['drops'][$i]['coords']) !== '') { $errorcode = 'noitemselected'; $errors["drops[{$i}]"] = get_string('formerror_' . $errorcode, 'qtype_ddmarker'); } } } for ($dragindex = 0; $dragindex < $data['noitems']; $dragindex++) { $label = $data['drags'][$dragindex]['label']; if ($label != strip_tags($label, QTYPE_DDMARKER_ALLOWED_TAGS_IN_MARKER)) { $errors["drags[{$dragindex}]"] = get_string('formerror_onlysometagsallowed', 'qtype_ddmarker', QTYPE_DDMARKER_ALLOWED_TAGS_IN_MARKER); } } return $errors; }