Last active
December 26, 2015 09:49
-
-
Save overnin/7132571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// in the validation rule | |
.... | |
'content' => array( | |
'requiredConditional' => array( | |
'rule' => array('requiredConditionalFieldOrValue', 'type-interaction', 'announcement', 'question-answer', 'question-answer-keyword'), | |
'message' => 'The interaction required a content.', | |
), | |
'notempty' => array( | |
'rule' => 'notempty', | |
'message' => 'Content field cannot be empty.' | |
), | |
'validApostrophe' => array( | |
'rule' => array('notRegex', VusionConst::APOSTROPHE_REGEX), | |
'message' => VusionConst::APOSTROPHE_FAIL_MESSAGE | |
), | |
'validCustomizedContent' => array( | |
'rule' => array('validCustomizeContent', VusionConst::DOMAIN_NOT_RESPONSE) | |
'message' => 'noMessage' | |
), | |
), | |
.... | |
public $validateFeedback = array( | |
'content' => array( | |
'notempty' => array( | |
'rule' => 'notempty', | |
'message' => 'Content field cannot be empty.' | |
), | |
'validApostrophe' => array( | |
'rule' => array('notRegex', VusionConst::APOSTROPHE_REGEX), | |
'message' => VusionConst::APOSTROPHE_FAIL_MESSAGE | |
), | |
'validCustomizeContent' => array( | |
'rule' => array('validCustomizeContent', VusionConst::DOMAIN_ALL) | |
'message' => 'noMessage' | |
), | |
) | |
); | |
// now the function | |
public function validCustomizeContent($field, $allowedDomain, $data) | |
{ | |
if (isset($data[$field])) { | |
preg_match_all(VusionConst::CONTENT_VARIABLE_MATCHER_REGEX, $data[$field], $matches, PREG_SET_ORDER); | |
$allowed = array("domain", "key1", "key2", "keys3", "otherkey"); | |
foreach($matches as $match) { | |
$match = array_intersect_key($match, array_flip($allowed)); | |
foreach ($match as $key=>$value) { | |
if (!preg_match(VusionConst::CONTENT_VARIABLE_KEY_REGEX, $value)) { | |
return __("To be used as customized content, '%s' can only be composed of letter(s), digit(s) and/or space(s).", $value); | |
} | |
} | |
if (!preg_match($allowedDomain, $match['domain'])) { | |
return __("To be used as customized content, '%s' can only be either: %s.", $match['domain'], implode(',', $allowedDomain)); | |
} | |
if ($match['domain'] == 'participant') { | |
if (isset($match['key2'])) { | |
return VusionConst::CONTENT_VARIABLE_DOMAIN_PARTICIPANT_FAIL; | |
} | |
} else if ($match['domain'] == 'contentVariable') { | |
if (isset($match['otherkey'])) { | |
return VusionConst::CONTENT_VARIABLE_DOMAIN_CONTENTVARIABLE_FAIL; | |
} | |
} | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment