本文整理汇总了PHP中ValidationResult::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ValidationResult::create方法的具体用法?PHP ValidationResult::create怎么用?PHP ValidationResult::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValidationResult
的用法示例。
在下文中一共展示了ValidationResult::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateData
/**
* @param Order $order
* @param array $data
*
* @throws ValidationException
*/
public function validateData(Order $order, array $data)
{
$result = ValidationResult::create();
$existingID = !empty($data[$this->addresstype . "AddressID"]) ? (int) $data[$this->addresstype . "AddressID"] : 0;
if ($existingID) {
// If existing address selected, check that it exists in $member->AddressBook
if (!Member::currentUserID() || !Member::currentUser()->AddressBook()->byID($existingID)) {
$result->error("Invalid address supplied", $this->addresstype . "AddressID");
throw new ValidationException($result);
}
} else {
// Otherwise, require the normal address fields
$required = parent::getRequiredFields($order);
$addressLabels = singleton('Address')->fieldLabels(false);
foreach ($required as $fieldName) {
if (empty($data[$fieldName])) {
// attempt to get the translated field name
$fieldLabel = isset($addressLabels[$fieldName]) ? $addressLabels[$fieldName] : $fieldName;
$errorMessage = _t('Form.FIELDISREQUIRED', '{name} is required', array('name' => $fieldLabel));
$result->error($errorMessage, $fieldName);
throw new ValidationException($result);
}
}
}
}
示例2: validateData
public function validateData(Order $order, array $data)
{
if (isset($data['RegisterAnAccount']) && $data['RegisterAnAccount']) {
return parent::validateData($order, $data);
}
return ValidationResult::create();
}
开发者ID:helpfulrobot,项目名称:milkyway-multimedia-ss-shop-checkout-extras,代码行数:7,代码来源:DependantMembershipCheckoutComponent.php
示例3: validateData
public function validateData(Order $order, array $data)
{
if (Member::currentUserID()) {
return;
}
$result = ValidationResult::create();
if (Checkout::membership_required() || !empty($data['Password'])) {
$member = Member::create($data);
$idfield = Member::config()->unique_identifier_field;
$idval = $data[$idfield];
if (ShopMember::get_by_identifier($idval)) {
// get localized field labels
$fieldLabels = $member->fieldLabels(false);
// if a localized value exists, use this for our error-message
$fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
$result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval), $idval);
}
$passwordresult = $this->passwordvalidator->validate($data['Password'], $member);
if (!$passwordresult->valid()) {
$result->error($passwordresult->message(), "Password");
}
}
if (!$result->valid()) {
throw new ValidationException($result);
}
}
示例4: validate
/**
* Validate
* @return ValidationResult
**/
protected function validate()
{
$valid = true;
$message = null;
$result = ValidationResult::create($valid, $message);
return $result;
}
示例5: validate
/**
* @param String $password
* @param Member $member
* @return ValidationResult
*/
public function validate($password, $member)
{
$valid = ValidationResult::create();
if ($this->minLength) {
if (strlen($password) < $this->minLength) {
$valid->error(sprintf(_t('PasswordValidator.TOOSHORT', 'Password is too short, it must be %s or more characters long'), $this->minLength), 'TOO_SHORT');
}
}
if ($this->minScore) {
$score = 0;
$missedTests = array();
foreach ($this->testNames as $name) {
if (preg_match(self::config()->character_strength_tests[$name], $password)) {
$score++;
} else {
$missedTests[] = _t('PasswordValidator.STRENGTHTEST' . strtoupper($name), $name, 'The user needs to add this to their password for more complexity');
}
}
if ($score < $this->minScore) {
$valid->error(sprintf(_t('PasswordValidator.LOWCHARSTRENGTH', 'Please increase password strength by adding some of the following characters: %s'), implode(', ', $missedTests)), 'LOW_CHARACTER_STRENGTH');
}
}
if ($this->historicalPasswordCount) {
$previousPasswords = MemberPassword::get()->where(array('"MemberPassword"."MemberID"' => $member->ID))->sort('"Created" DESC, "ID" DESC')->limit($this->historicalPasswordCount);
if ($previousPasswords) {
foreach ($previousPasswords as $previousPasswords) {
if ($previousPasswords->checkPassword($password)) {
$valid->error(_t('PasswordValidator.PREVPASSWORD', 'You\'ve already used that password in the past, please choose a new password'), 'PREVIOUS_PASSWORD');
break;
}
}
}
}
return $valid;
}
示例6: validate
public function validate()
{
if ($this->pages > 100) {
$result = ValidationResult::create(false, 'Too many pages');
} else {
$result = ValidationResult::create(true);
}
return $result;
}
示例7: validateData
public function validateData(Order $order, array $data)
{
$result = ValidationResult::create();
//TODO: validate credit card data
if (!Helper::validateLuhn($data['number'])) {
$result->error(_t('OnsitePaymentCheckoutComponent.CREDIT_CARD_INVALID', 'Credit card is invalid'));
throw new ValidationException($result);
}
}
示例8: validate
/**
* @return ValidationResult
*/
protected function validate()
{
$result = ValidationResult::create();
$link = trim($this->Link);
if (empty($link)) {
return $result->error('you must set an url for Presentation Link!');
}
if (filter_var($link, FILTER_VALIDATE_URL) === false) {
return $result->error('you must set a valid url for Presentation Link!');
}
return $result;
}
示例9: validateData
public function validateData(Order $order, array $data)
{
$result = ValidationResult::create();
if (!isset($data['PaymentMethod'])) {
$result->error(_t('PaymentCheckoutComponent.NO_PAYMENT_METHOD', "Payment method not provided"), "PaymentMethod");
throw new ValidationException($result);
}
$methods = GatewayInfo::get_supported_gateways();
if (!isset($methods[$data['PaymentMethod']])) {
$result->error(_t('PaymentCheckoutComponent.UNSUPPORTED_GATEWAY', "Gateway not supported"), "PaymentMethod");
throw new ValidationException($result);
}
}
示例10: validateData
public function validateData(Order $order, array $data)
{
$result = ValidationResult::create();
if (!isset($data['PaymentMethod'])) {
$result->error(_t('PaymentCheckoutComponent.NoPaymentMethod', "Payment method not provided"), "PaymentMethod");
throw new ValidationException($result);
}
$methods = GatewayInfo::getSupportedGateways();
if (!isset($methods[$data['PaymentMethod']])) {
$result->error(_t('PaymentCheckoutComponent.UnsupportedGateway', "Gateway not supported"), "PaymentMethod");
throw new ValidationException($result);
}
}
示例11: validate
protected function validate()
{
$valid = ValidationResult::create();
if (!$valid->valid()) {
return $valid;
}
if (empty($this->Name)) {
return $valid->error('Name is empty!');
}
$res = DB::query("SELECT COUNT(Q.ID) FROM RSVPQuestionTemplate Q\n INNER JOIN `RSVPTemplate` T ON T.ID = Q.RSVPTemplateID\n WHERE Q.Name = '{$this->Name}' AND Q.ID <> {$this->ID} AND Q.RSVPTemplateID = {$this->RSVPTemplateID}")->value();
if (intval($res) > 0) {
return $valid->error('There is already another Question on the rsvp form with that name!');
}
return $valid;
}
示例12: validate
protected function validate()
{
$valid = ValidationResult::create();
if (!$valid->valid()) {
return $valid;
}
if (empty($this->Name)) {
return $valid->error('Name is empty!');
}
$res = DB::query("SELECT COUNT(Q.ID) FROM SurveyQuestionTemplate Q\n INNER JOIN `SurveyStepTemplate` S ON S.ID = Q.StepID\n INNER JOIN `SurveyTemplate` T ON T.ID = S.`SurveyTemplateID`\n WHERE Q.Name = '{$this->Name}' AND Q.ID <> {$this->ID};")->value();
if (intval($res) > 0) {
return $valid->error('There is already another Question on the survey with that name!');
}
return $valid;
}
示例13: validate
protected function validate()
{
$valid = ValidationResult::create();
if (empty($this->EntityName)) {
return $valid->error('Entity Name is empty!');
}
if (!preg_match('/^[a-z_091A-Z]*$/', $this->EntityName)) {
return $valid->error('Entity Name has an Invalid Format!');
}
$title = $this->EntityName;
$id = $this->ID;
$owner_id = $this->ParentID;
$res = DB::query("SELECT COUNT(ID) FROM EntitySurveyTemplate WHERE EntityName = '{$title}' AND ID <> {$id} AND ParentID = {$owner_id}")->value();
if (intval($res) > 0) {
return $valid->error('There is already another entity survey with that name!');
}
return $valid;
}
示例14: create
/**
* Create member account from data array.
* Data must contain unique identifier.
*
* @throws ValidationException
*
* @param $data - map of member data
*
* @return Member|boolean - new member (not saved to db), or false if there is an error.
*/
public function create($data)
{
$result = ValidationResult::create();
if (!Checkout::member_creation_enabled()) {
$result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed"));
throw new ValidationException($result);
}
$idfield = Config::inst()->get('Member', 'unique_identifier_field');
if (!isset($data[$idfield]) || empty($data[$idfield])) {
$result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield));
throw new ValidationException($result);
}
if (!isset($data['Password']) || empty($data['Password'])) {
$result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required"));
throw new ValidationException($result);
}
$idval = $data[$idfield];
if ($member = ShopMember::get_by_identifier($idval)) {
// get localized field labels
$fieldLabels = $member->fieldLabels(false);
// if a localized value exists, use this for our error-message
$fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
$result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval));
throw new ValidationException($result);
}
$member = Member::create(Convert::raw2sql($data));
// 3.2 changed validate to protected which made this fall through the DataExtension and error out
$validation = $member->hasMethod('doValidate') ? $member->doValidate() : $member->validate();
if (!$validation->valid()) {
//TODO need to handle i18n here?
$result->error($validation->message());
}
if (!$result->valid()) {
throw new ValidationException($result);
}
return $member;
}
示例15: create
/**
* Create member account from data array.
* Data must contain unique identifier.
*
* @throws ValidationException
*
* @param $data - map of member data
*
* @return Member|boolean - new member (not saved to db), or false if there is an error.
*/
public function create($data)
{
$result = ValidationResult::create();
if (!Checkout::member_creation_enabled()) {
$result->error(_t("Checkout.MembershipIsNotAllowed", "Creating new memberships is not allowed"));
throw new ValidationException($result);
}
$idfield = Config::inst()->get('Member', 'unique_identifier_field');
if (!isset($data[$idfield]) || empty($data[$idfield])) {
$result->error(_t('Checkout.IdFieldNotFound', 'Required field not found: {IdentifierField}', 'Identifier is the field that holds the unique user-identifier, commonly this is \'Email\'', array('IdentifierField' => $idfield)));
throw new ValidationException($result);
}
if (!isset($data['Password']) || empty($data['Password'])) {
$result->error(_t("Checkout.PasswordRequired", "A password is required"));
throw new ValidationException($result);
}
$idval = $data[$idfield];
if ($member = ShopMember::get_by_identifier($idval)) {
// get localized field labels
$fieldLabels = $member->fieldLabels(false);
// if a localized value exists, use this for our error-message
$fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
$result->error(_t('Checkout.MemberExists', 'A member already exists with the {Field} {Identifier}', '', array('Field' => $fieldLabel, 'Identifier' => $idval)));
throw new ValidationException($result);
}
$member = Member::create(Convert::raw2sql($data));
// 3.2 changed validate to protected which made this fall through the DataExtension and error out
$validation = $member->hasMethod('doValidate') ? $member->doValidate() : $member->validate();
if (!$validation->valid()) {
//TODO need to handle i18n here?
$result->error($validation->message());
}
if (!$result->valid()) {
throw new ValidationException($result);
}
return $member;
}