MDL-38659 environment: verify feedback matches levels

This commit is contained in:
Eloy Lafuente (stronk7)
2013-03-26 15:34:06 +01:00
parent 38495379a8
commit d9b9ef5d4e
+15
View File
@@ -70,6 +70,10 @@ defined('MOODLE_INTERNAL') || die();
define('CUSTOM_CHECK_FUNCTION_MISSING', 14);
/** XML Processing Error */
define('NO_PHP_SETTINGS_NAME_FOUND', 15);
/** XML Processing Error */
define('INCORRECT_FEEDBACK_FOR_REQUIRED', 16);
/** XML Processing Error */
define('INCORRECT_FEEDBACK_FOR_OPTIONAL', 17);
/// Define algorithm used to select the xml file
/** To select the newer file available to perform checks */
@@ -1066,6 +1070,8 @@ function process_environment_restrict($xml, &$result) {
* This function will detect if there is some message available to be added to the
* result in order to clarify enviromental details.
*
* @uses INCORRECT_FEEDBACK_FOR_REQUIRED
* @uses INCORRECT_FEEDBACK_FOR_OPTIONAL
* @param string xmldata containing the feedback data
* @param object reult object to be updated
*/
@@ -1075,6 +1081,15 @@ function process_environment_messages($xml, &$result) {
if (is_array($xml['#']) && isset($xml['#']['FEEDBACK'][0]['#'])) {
$feedbackxml = $xml['#']['FEEDBACK'][0]['#'];
// Detect some incorrect feedback combinations.
if ($result->getLevel() == 'required' and isset($feedbackxml['ON_CHECK'])) {
$result->setStatus(false);
$result->setErrorCode(INCORRECT_FEEDBACK_FOR_REQUIRED);
} else if ($result->getLevel() == 'optional' and isset($feedbackxml['ON_ERROR'])) {
$result->setStatus(false);
$result->setErrorCode(INCORRECT_FEEDBACK_FOR_OPTIONAL);
}
if (!$result->status and $result->getLevel() == 'required') {
if (isset($feedbackxml['ON_ERROR'][0]['@']['message'])) {
$result->setFeedbackStr($feedbackxml['ON_ERROR'][0]['@']['message']);