/**
  * 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;
 }
예제 #2
0
 /**
  * Validate a single value
  *
  * This function needs to throw a validation exception when validation fails.
  * The exception message will be prefixed by the appropriate field on output
  *
  * @param string|int $rawvalue
  * @return int|string
  * @throws ValidationException
  */
 public function validate($rawvalue)
 {
     $rawvalue = parent::validate($rawvalue);
     list($rawvalue) = explode(' ', $rawvalue, 2);
     // strip off time if there is any
     list($year, $month, $day) = explode('-', $rawvalue, 3);
     if (!checkdate((int) $month, (int) $day, (int) $year)) {
         throw new ValidationException('invalid date format');
     }
     return sprintf('%d-%02d-%02d', $year, $month, $day);
 }
예제 #3
0
 /**
  * Checks against the allowed mime types
  *
  * @param string $rawvalue
  * @return int|string
  */
 public function validate($rawvalue)
 {
     $rawvalue = parent::validate($rawvalue);
     if (!trim($this->config['mime'])) {
         return $rawvalue;
     }
     $allows = explode(',', $this->config['mime']);
     $allows = array_map('trim', $allows);
     $allows = array_filter($allows);
     list(, $mime, ) = mimetype($rawvalue, false);
     foreach ($allows as $allow) {
         if (strpos($mime, $allow) === 0) {
             return $rawvalue;
         }
     }
     throw new ValidationException('Media mime type', $mime, $this->config['mime']);
 }
예제 #4
0
 /**
  * Sort by lookup table
  *
  * @param QueryBuilder $QB
  * @param string $tablealias
  * @param string $colname
  * @param string $order
  */
 public function sort(QueryBuilder $QB, $tablealias, $colname, $order)
 {
     if (!$this->usesLookup()) {
         parent::sort($QB, $tablealias, $colname, $order);
         return;
     }
     $schema = 'data_' . $this->schema->getTable();
     $field = $this->column->getColName();
     $rightalias = $QB->generateTableAlias();
     $QB->addLeftJoin($tablealias, $schema, $rightalias, "{$tablealias}.{$colname} = {$rightalias}.pid");
     $this->column->getType()->sort($QB, $rightalias, $field, $order);
 }