From: jamiesensei Date: Wed, 22 Aug 2007 04:28:26 +0000 (+0000) Subject: MDL-10938. 'only strings from lang files can be used as feedback in environment check... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=afb36bca448fc79c4a08714dd333451a16579417;p=moodle.git MDL-10938. 'only strings from lang files can be used as feedback in environment check. Some way is needed to include data from custom check function - a $a param to pass to get_string'. Custom check for questions uses new functionality to print more complex strings as feedback. --- diff --git a/lib/environmentlib.php b/lib/environmentlib.php index 1b903f5315..ae5d52e274 100644 --- a/lib/environmentlib.php +++ b/lib/environmentlib.php @@ -239,26 +239,18 @@ function print_moodle_environment($result, $environment_results) { $status = ''.$status.''; /// Here we'll store all the feedback found $feedbacktext = ''; - ///Process the feedback if necessary - if ($feedbackstr = $environment_result->getFeedbackStr()) { - $feedbacktext .= '

'.get_string($feedbackstr, 'admin').'

'; - } - ///Process the bypass if necessary - if ($bypassstr = $environment_result->getBypassStr()) { - $feedbacktext .= '

'.get_string($bypassstr, 'admin').'

'; - } - ///Process the restrict if necessary - if ($restrictstr = $environment_result->getRestrictStr()) { - $feedbacktext .= '

'.get_string($restrictstr, 'admin').'

'; - } - if ($feedbacktext) { - $report = $report .$feedbacktext; - } + ///Append the feedback if there is some + $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype); + ///Append the bypass if there is some + $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn'); + ///Append the restrict if there is some + $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error'); + + $report .= $feedbacktext; /// Add the row to the table if ($environment_result->getPart() == 'custom_check'){ $otherdata[$messagetype][] = array ($info, $report, $status); - } else { $serverdata[$messagetype][] = array ($type, $info, $report, $status); } @@ -999,15 +991,22 @@ class environment_results { /** * Set the feedback string - * @param string the feedback string + * @param mixed the feedback string that will be fetched from the admin lang file. + * pass just the string or pass an array of params for get_string + * You always should put your string in admin.php but a third param is useful + * to pass an $a object / string to get_string */ function setFeedbackStr($str) { $this->feedback_str=$str; } + /** * Set the bypass string - * @param string the bypass string + * @param string the bypass string that will be fetched from the admin lang file. + * pass just the string or pass an array of params for get_string + * You always should put your string in admin.php but a third param is useful + * to pass an $a object / string to get_string */ function setBypassStr($str) { $this->bypass_str=$str; @@ -1015,7 +1014,10 @@ class environment_results { /** * Set the restrict string - * @param string the restrict string + * @param string the restrict string that will be fetched from the admin lang file. + * pass just the string or pass an array of params for get_string + * You always should put your string in admin.php but a third param is useful + * to pass an $a object / string to get_string */ function setRestrictStr($str) { $this->restrict_str=$str; @@ -1079,7 +1081,8 @@ class environment_results { /** * Get the feedback string - * @return string feedback string + * @return mixed feedback string (can be an array of params for get_string or a single string to fetch from + * admin.php lang file). */ function getFeedbackStr() { return $this->feedback_str; @@ -1087,7 +1090,8 @@ class environment_results { /** * Get the bypass string - * @return string bypass string + * @return mixed bypass string (can be an array of params for get_string or a single string to fetch from + * admin.php lang file). */ function getBypassStr() { return $this->bypass_str; @@ -1095,11 +1099,32 @@ class environment_results { /** * Get the restrict string - * @return string restrict string + * @return mixed restrict string (can be an array of params for get_string or a single string to fetch from + * admin.php lang file). */ function getRestrictStr() { return $this->restrict_str; } + + /** + * @param mixed $string params for get_string, either a string to fetch from admin.php or an array of + * params for get_string. + * @param string $class css class(es) for message. + * @return string feedback string fetched from lang file wrapped in p tag with class $class or returns + * empty string if $string is empty. + */ + function strToReport($string, $class){ + if (!empty($string)){ + if (is_array($string)){ + $str = call_user_func_array('get_string', $string); + } else { + $str = get_string($string, 'admin'); + } + return '

'.$str.'

'; + } else { + return ''; + } + } } /// Here all the bypass functions are coded to be used by the environment diff --git a/question/upgrade.php b/question/upgrade.php index c05f9894d7..641c1781d0 100644 --- a/question/upgrade.php +++ b/question/upgrade.php @@ -90,7 +90,7 @@ function question_random_check($result){ $a->reporturl = "{$CFG->wwwroot}/{$CFG->admin}/report/question/"; $lang = str_replace('_utf8', '', current_language()); $a->docsurl = "{$CFG->docroot}/$lang/admin/report/question/index"; - $result->feedback_str = get_string('questioncwqpfscheck', 'admin', $a); + $result->setFeedbackStr(array('questioncwqpfscheck', 'admin', $a)); $result->setStatus(false);//fail test } return $result;