/** * Validate the given data for a single field * * Catches the Validation exceptions and transforms them into proper error messages. * * Blank values are not validated and always pass * * @param AbstractBaseType $type * @param string $label * @param array|string|int &$data may be modified by the validation function * @return bool true if the data validates, otherwise false */ protected function validateField(AbstractBaseType $type, $label, &$data) { $prefix = sprintf($this->hlp->getLang('validation_prefix'), $label); $ok = true; if (is_array($data)) { foreach ($data as &$value) { if (!blank($value)) { try { $value = $type->validate($value); } catch (ValidationException $e) { $this->errors[] = $prefix . $e->getMessage(); $ok = false; } } } return $ok; } if (!blank($data)) { try { $data = $type->validate($data); } catch (ValidationException $e) { $this->errors[] = $prefix . $e->getMessage(); $ok = false; } } return $ok; }
/** * Creates a unique label from the given one * * @param string $wantedlabel * @param array $labels list of already assigned labels (will be filled) * @return string */ protected function fixLabel($wantedlabel, &$labels) { $wantedlabel = trim($wantedlabel); $fixedlabel = $wantedlabel; $idx = 1; while (isset($labels[utf8_strtolower($fixedlabel)])) { $fixedlabel = $wantedlabel . $idx++; } // did we actually do a rename? apply it. if ($fixedlabel != $wantedlabel) { msg(sprintf($this->helper->getLang('duplicate_label'), $wantedlabel, $fixedlabel), -1); $this->data['cols']['label'] = $fixedlabel; } $labels[utf8_strtolower($fixedlabel)] = 1; return $fixedlabel; }