Example #1
0
 /**
  * @param $value
  * @param $primary
  * @param array $row
  * @param Entity\Field | Entity\EnumField | Entity\BooleanField $field
  * @return bool|string
  */
 public function validate($value, $primary, array $row, Entity\Field $field)
 {
     if (in_array($value, $field->getValues(), true) || $value == '') {
         return true;
     }
     return $this->getErrorMessage($value, $field);
 }
Example #2
0
 /**
  * @param $value
  * @param \Freetrix\Main\Entity\Field $field
  * @param null|string $errorPhrase
  * @param null|array $additionalTemplates
  *
  * @return string
  */
 protected function getErrorMessage($value, Entity\Field $field, $errorPhrase = null, $additionalTemplates = null)
 {
     if ($errorPhrase === null) {
         $errorPhrase = $this->errorPhrase !== null ? $this->errorPhrase : Loc::getMessage($this->errorPhraseCode);
     }
     $langValues = array('#VALUE#' => $value, '#FIELD_NAME#' => $field->getName(), '#FIELD_TITLE#' => $field->getTitle());
     if (is_array($additionalTemplates)) {
         $langValues += $additionalTemplates;
     }
     return str_replace(array_keys($langValues), array_values($langValues), $errorPhrase);
 }
Example #3
0
 public function validate($value, $primary, array $row, Entity\Field $field)
 {
     $entity = $field->getEntity();
     $primaryNames = $entity->getPrimaryArray();
     $query = new Entity\Query($entity);
     $query->setSelect($primaryNames);
     $query->setFilter(array('=' . $field->getName() => $value));
     $query->setLimit(2);
     $result = $query->exec();
     while ($existing = $result->fetch()) {
         // check primary
         foreach ($existing as $k => $v) {
             if (!isset($primary[$k]) || $primary[$k] != $existing[$k]) {
                 return $this->getErrorMessage($value, $field);
             }
         }
     }
     return true;
 }