本文整理汇总了PHP中eZContentObjectAttribute::setValidationError方法的典型用法代码示例。如果您正苦于以下问题:PHP eZContentObjectAttribute::setValidationError方法的具体用法?PHP eZContentObjectAttribute::setValidationError怎么用?PHP eZContentObjectAttribute::setValidationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZContentObjectAttribute
的用法示例。
在下文中一共展示了eZContentObjectAttribute::setValidationError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateObjectAttributeHTTPInput
/**
* Validate post data, these are then used by
* {@link eZGmapLocationType::fetchObjectAttributeHTTPInput()}
*
* @param eZHTTPTool $http
* @param string $base
* @param eZContentObjectAttribute $contentObjectAttribute
*/
function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
$latitude = '';
$longitude = '';
$classAttribute = $contentObjectAttribute->contentClassAttribute();
if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) &&
$http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) )
{
$latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
$longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
}
if ( $latitude === '' || $longitude === '' )
{
if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'extension/ezgmaplocation/datatype',
'Missing Latitude/Longitude input.' ) );
return eZInputValidator::STATE_INVALID;
}
}
else if ( !is_numeric( $latitude ) || !is_numeric( $longitude ) )
{
$contentObjectAttribute->setValidationError( ezpI18n::tr( 'extension/ezgmaplocation/datatype',
'Invalid Latitude/Longitude input.' ) );
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例2: validateObjectAttribute
/**
* Validates the data structure and returns true if it is valid for this datatype
*
* @param eZContentObjectAttribute $contentObjectAttribute
* @param string $idString
* @param string $keywordString
* @param string $parentString
* @param string $localeString
*
* @return bool
*/
private function validateObjectAttribute($contentObjectAttribute, $idString, $keywordString, $parentString, $localeString)
{
$classAttribute = $contentObjectAttribute->contentClassAttribute();
// we cannot use empty() here as there can be cases where $parentString or $idString can be "0",
// which evaluates to false with empty(), which is wrong for our use case
if (strlen($keywordString) == 0 && strlen($parentString) == 0 && strlen($idString) == 0 && strlen($localeString) == 0) {
if ($contentObjectAttribute->validateIsRequired()) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'At least one tag is required to be added.'));
return eZInputValidator::STATE_INVALID;
}
} else {
if (strlen($keywordString) == 0 || strlen($parentString) == 0 || strlen($idString) == 0 || strlen($localeString) == 0) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'Attribute contains invalid data.'));
return eZInputValidator::STATE_INVALID;
} else {
$idArray = explode('|#', $idString);
$keywordArray = explode('|#', $keywordString);
$parentArray = explode('|#', $parentString);
$localeArray = explode('|#', $localeString);
if (count($keywordArray) != count($idArray) || count($parentArray) != count($idArray) || count($localeArray) != count($idArray)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'Attribute contains invalid data.'));
return eZInputValidator::STATE_INVALID;
}
$maxTags = (int) $classAttribute->attribute(self::MAX_TAGS_FIELD);
if ($maxTags > 0 && (count($idArray) > $maxTags || count($keywordArray) > $maxTags || count($parentArray) > $maxTags || count($localeArray) > $maxTags)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/eztags/datatypes', 'Up to %1 tags are allowed to be added.', null, array('%1' => $maxTags)));
return eZInputValidator::STATE_INVALID;
}
}
}
return eZInputValidator::STATE_ACCEPTED;
}
示例3: validateIntegerHTTPInput
/**
* Validates $data with the constraints defined on the class attribute
*
* @param $data
* @param eZContentObjectAttribute $contentObjectAttribute
* @param eZContentClassAttribute $classAttribute
*
* @return int
*/
function validateIntegerHTTPInput($data, $contentObjectAttribute, $classAttribute)
{
$min = $classAttribute->attribute(self::MIN_VALUE_FIELD);
$max = $classAttribute->attribute(self::MAX_VALUE_FIELD);
$input_state = $classAttribute->attribute(self::INPUT_STATE_FIELD);
switch ($input_state) {
case self::NO_MIN_MAX_VALUE:
$this->IntegerValidator->setRange(false, false);
$state = $this->IntegerValidator->validate($data);
if ($state === eZInputValidator::STATE_INVALID || $state === eZInputValidator::STATE_INTERMEDIATE) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input is not a valid integer.'));
} else {
return $state;
}
break;
case self::HAS_MIN_VALUE:
$this->IntegerValidator->setRange($min, false);
$state = $this->IntegerValidator->validate($data);
if ($state === eZInputValidator::STATE_ACCEPTED) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The number must be greater than %1'), $min);
}
break;
case self::HAS_MAX_VALUE:
$this->IntegerValidator->setRange(false, $max);
$state = $this->IntegerValidator->validate($data);
if ($state === 1) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The number must be less than %1'), $max);
}
break;
case self::HAS_MIN_MAX_VALUE:
$this->IntegerValidator->setRange($min, $max);
$state = $this->IntegerValidator->validate($data);
if ($state === 1) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The number is not within the required range %1 - %2'), $min, $max);
}
break;
}
return eZInputValidator::STATE_INVALID;
}
示例4: validateStringHTTPInput
/**
* Validates $data with the constraints defined on the class attribute
*
* @param $data
* @param eZContentObjectAttribute $contentObjectAttribute
* @param eZContentClassAttribute $classAttribute
*
* @return int
*/
function validateStringHTTPInput($data, $contentObjectAttribute, $classAttribute)
{
$maxLen = $classAttribute->attribute(self::MAX_LEN_FIELD);
$textCodec = eZTextCodec::instance(false);
if ($textCodec->strlen($data) > $maxLen and $maxLen > 0) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input text is too long. The maximum number of characters allowed is %1.'), $maxLen);
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例5: validateObjectAttributeHTTPInput
/**
* Validates the input and returns true if the input was valid for this datatype
*
* @param eZHTTPTool $http
* @param string $base
* @param eZContentObjectAttribute $contentObjectAttribute
* @return bool
*/
function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
$classAttribute = $contentObjectAttribute->contentClassAttribute();
if ($http->hasPostVariable($base . '_eztags_data_text_' . $contentObjectAttribute->attribute('id')) && $http->hasPostVariable($base . '_eztags_data_text2_' . $contentObjectAttribute->attribute('id')) && $http->hasPostVariable($base . '_eztags_data_text3_' . $contentObjectAttribute->attribute('id'))) {
$data = trim($http->postVariable($base . '_eztags_data_text_' . $contentObjectAttribute->attribute('id')));
$data2 = trim($http->postVariable($base . '_eztags_data_text2_' . $contentObjectAttribute->attribute('id')));
$data3 = trim($http->postVariable($base . '_eztags_data_text3_' . $contentObjectAttribute->attribute('id')));
if (strlen($data) == 0 && strlen($data2) == 0 && strlen($data3) == 0) {
if ($contentObjectAttribute->validateIsRequired()) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
return eZInputValidator::STATE_INVALID;
}
} else {
if (!(strlen($data) > 0 && strlen($data2) > 0 && strlen($data3) > 0)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
return eZInputValidator::STATE_INVALID;
} else {
$dataArray = explode('|#', $data);
$data2Array = explode('|#', $data2);
$data3Array = explode('|#', $data3);
if (count($data2Array) != count($dataArray) || count($data3Array) != count($dataArray)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
return eZInputValidator::STATE_INVALID;
}
$maxTags = (int) $classAttribute->attribute(self::MAX_TAGS_FIELD);
if ($maxTags > 0 && (count($dataArray) > $maxTags || count($data2Array) > $maxTags || count($data3Array) > $maxTags)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
return eZInputValidator::STATE_INVALID;
}
}
}
} else {
if ($contentObjectAttribute->validateIsRequired()) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Input required.'));
return eZInputValidator::STATE_INVALID;
}
}
return eZInputValidator::STATE_ACCEPTED;
}
示例6: validateObjectAttributeHTTPInput
/**
* Validates the input and returns the validity status code
*
* @param eZHTTPTool $http
* @param string $base
* @param eZContentObjectAttribute $contentObjectAttribute
*
* @return int
*/
function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
$classList = $http->postVariable($base . self::CLASS_LIST_VARIABLE . $contentObjectAttribute->attribute("id"), array());
$classList = !is_array($classList) ? array() : $classList;
if (empty($classList) && $contentObjectAttribute->validateIsRequired()) {
$contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
return eZInputValidator::STATE_INVALID;
}
$invalidClassIdentifiers = array();
foreach ($classList as $classIdentifier) {
if (!eZContentClass::exists($classIdentifier, eZContentClass::VERSION_STATUS_DEFINED, false, true)) {
$invalidClassIdentifiers[] = $classIdentifier;
}
}
if (!empty($invalidClassIdentifiers)) {
if (count($invalidClassIdentifiers) == 1) {
$contentObjectAttribute->setValidationError(ezpI18n::tr("extension/ngclasslist/datatypes", "Class with identifier '%identifier%' does not exist", null, array("%identifier%" => $invalidClassIdentifiers[0])));
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr("extension/ngclasslist/datatypes", "Classes with '%identifiers%' identifiers do not exist", null, array("%identifiers%" => implode(", ", $invalidClassIdentifiers))));
}
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例7: validateObjectAttributeHTTPInput
/**
* Validates input on content object level
* Checks if entered color code is a valid color code
* @param eZHTTPTool $http
* @param string $base POST variable name prefix (Always "ContentObjectAttribute")
* @param eZContentObjectAttribute $contentObjectAttribute
* @return eZInputValidator::STATE_ACCEPTED|eZInputValidator::STATE_INVALID|eZInputValidator::STATE_INTERMEDIATE
*/
public function validateObjectAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
$classAttribute = $contentObjectAttribute->contentClassAttribute();
if ($http->hasPostVariable($base . self::CONTENT_FIELD_VARIABLE . $contentObjectAttribute->attribute("id"))) {
$data = $http->postVariable($base . self::CONTENT_FIELD_VARIABLE . $contentObjectAttribute->attribute("id"));
$data = str_replace(" ", "", $data);
$pattern = '/^#[a-f0-9]{6}$/i';
if ($data == "") {
return eZInputValidator::STATE_ACCEPTED;
} elseif (strlen($data) > 7 || preg_match($pattern, $data, $matches) == 0) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Invalid input'));
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例8: validateConfirmation
protected static function validateConfirmation(eZHTTPTool $http, $base, eZContentObjectAttribute $attribute, $isCollection = false)
{
$field = $attributeName = $base . '_attributeconfirmation_' . $attribute->attribute('id');
$value = $http->postVariable($field, null);
if (empty($value)) {
if ((bool) $attribute->attribute('is_required')) {
$attribute->setValidationError(ezpI18n::tr('extension/attributeconfirmation', 'Input required.'));
return eZInputValidator::STATE_INVALID;
} else {
return eZInputValidator::STATE_ACCEPTED;
}
}
$attributeToConfirm = $attribute->attribute('contentclass_attribute')->attribute(self::FIELD_ATTRIBUTE);
$attributeToConfirmValue = null;
$version = $attribute->attribute('object_version');
$dataMap = $version->attribute('data_map');
if ($isCollection) {
if (isset($dataMap[$attributeToConfirm])) {
$attributeID = $dataMap[$attributeToConfirm]->attribute('id');
$fields = array_keys($_POST);
foreach ($fields as $field) {
if (preg_match('/^' . $base . '.*' . $attributeID . '$/i', $field) === 1) {
$attributeToConfirmValue = $http->postVariable($field, null);
break;
}
}
}
} else {
if (isset($dataMap[$attributeToConfirm])) {
$attributeToConfirmValue = $dataMap[$attributeToConfirm]->attribute('content');
}
}
if (empty($attributeToConfirmValue)) {
return eZInputValidator::STATE_ACCEPTED;
}
if ($attributeToConfirmValue != $value) {
$attribute->setValidationError(ezpI18n::tr('extension/attributeconfirmation', 'Input does not match.'));
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例9: validateFloatHTTPInput
/**
* Validates $data with the constraints defined on the class attribute
*
* @param $data
* @param eZContentObjectAttribute $contentObjectAttribute
* @param eZContentClassAttribute $classAttribute
*
* @return int
*/
function validateFloatHTTPInput($data, $contentObjectAttribute, $classAttribute)
{
$min = $classAttribute->attribute(self::MIN_FIELD);
$max = $classAttribute->attribute(self::MAX_FIELD);
$inputState = $classAttribute->attribute(self::INPUT_STATE_FIELD);
switch ($inputState) {
case self::NO_MIN_MAX_VALUE:
$state = $this->FloatValidator->validate($data);
if ($state === eZInputValidator::STATE_ACCEPTED) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The given input is not a floating point number.'));
}
break;
case self::HAS_MIN_VALUE:
$this->FloatValidator->setRange($min, false);
$state = $this->FloatValidator->validate($data);
if ($state === eZInputValidator::STATE_ACCEPTED) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input must be greater than %1'), $min);
}
break;
case self::HAS_MAX_VALUE:
$this->FloatValidator->setRange(false, $max);
$state = $this->FloatValidator->validate($data);
if ($state === eZInputValidator::STATE_ACCEPTED) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input must be less than %1'), $max);
}
break;
case self::HAS_MIN_MAX_VALUE:
$this->FloatValidator->setRange($min, $max);
$state = $this->FloatValidator->validate($data);
if ($state === eZInputValidator::STATE_ACCEPTED) {
return eZInputValidator::STATE_ACCEPTED;
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'The input is not in defined range %1 - %2'), $min, $max);
}
break;
}
return eZInputValidator::STATE_INVALID;
}
示例10: validateCollectionAttributeHTTPInput
/**
* Validates the input for collection attribute and returns the validity status code
*
* @param eZHTTPTool $http
* @param string $base
* @param eZContentObjectAttribute $contentObjectAttribute
*
* @return int
*/
function validateCollectionAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
if ($http->hasPostVariable($base . self::OIB_VARIABLE . $contentObjectAttribute->attribute("id"))) {
$data = trim($http->postVariable($base . self::OIB_VARIABLE . $contentObjectAttribute->attribute("id")));
if (empty($data)) {
if ($contentObjectAttribute->validateIsRequired()) {
$contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
return eZInputValidator::STATE_INVALID;
}
} else {
if (!$this->validateOib($data)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr("extension/ngoib/datatypes", "Personal identification number is not valid."));
return eZInputValidator::STATE_INVALID;
}
}
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例11: validateAttributeHTTPInput
/**
* Validates content object attribute HTTP input
*
* @param eZHTTPTool $http
* @param string $base
* @param eZContentObjectAttribute $contentObjectAttribute
* @param bool $isInformationCollection
*
* @return int
*/
protected function validateAttributeHTTPInput($http, $base, $contentObjectAttribute, $isInformationCollection = false)
{
/** @var eZContentClassAttribute $classAttribute */
$classAttribute = $contentObjectAttribute->contentClassAttribute();
$classContent = $classAttribute->content();
$infoCollectionCheck = $isInformationCollection == $classAttribute->attribute('is_information_collector');
$isRequired = $contentObjectAttribute->validateIsRequired();
$selectionName = join('_', array($base, 'sckenhancedselection_selection', $contentObjectAttribute->attribute('id')));
if ($http->hasPostVariable($selectionName)) {
$selection = $http->postVariable($selectionName);
if ($infoCollectionCheck) {
switch (true) {
case $isRequired === true && count($selection) == 0:
case $isRequired === true && count($selection) == 1 && empty($selection[0]):
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'This is a required field.'));
return eZInputValidator::STATE_INVALID;
}
}
} else {
if ($infoCollectionCheck && $isRequired && $classContent['is_multiselect'] == 1) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'This is a required field.'));
} else {
if ($infoCollectionCheck && $isRequired) {
$contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'No POST variable. Please check your configuration.'));
} else {
return eZInputValidator::STATE_ACCEPTED;
}
}
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}
示例12: validateCollectionAttributeHTTPInput
/**
* Validates the input for collection attribute and returns the validity status code
*
* @param eZHTTPTool $http
* @param string $base
* @param eZContentObjectAttribute $contentObjectAttribute
*
* @return int
*/
function validateCollectionAttributeHTTPInput($http, $base, $contentObjectAttribute)
{
if ($http->hasPostVariable($base . self::FMCP_VAR . $contentObjectAttribute->attribute("id"))) {
$data = trim($http->postVariable($base . self::FMCP_VAR . $contentObjectAttribute->attribute("id")));
if (empty($data)) {
if ($contentObjectAttribute->validateIsRequired()) {
$contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
return eZInputValidator::STATE_INVALID;
}
} else {
if (!$this->validateColor($data)) {
$contentObjectAttribute->setValidationError(ezpI18n::tr("extension/fmColorpicker/datatypes", "the color code is not valid."));
return eZInputValidator::STATE_INVALID;
}
}
} else {
$contentObjectAttribute->setValidationError(ezpI18n::tr("kernel/classes/datatypes", "Input required."));
return eZInputValidator::STATE_INVALID;
}
return eZInputValidator::STATE_ACCEPTED;
}