Skip to content

Commit

Permalink
MDL-10938. 'only strings from lang files can be used as feedback in e…
Browse files Browse the repository at this point in the history
…nvironment 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.
  • Loading branch information
jamiesensei committed Aug 22, 2007
1 parent 8a67b03 commit afb36bc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
69 changes: 47 additions & 22 deletions lib/environmentlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,18 @@ function print_moodle_environment($result, $environment_results) {
$status = '<span class="'.$messagetype.'">'.$status.'</span>';
/// Here we'll store all the feedback found
$feedbacktext = '';
///Process the feedback if necessary
if ($feedbackstr = $environment_result->getFeedbackStr()) {
$feedbacktext .= '<p class="'.$messagetype.'">'.get_string($feedbackstr, 'admin').'</p>';
}
///Process the bypass if necessary
if ($bypassstr = $environment_result->getBypassStr()) {
$feedbacktext .= '<p class="warn">'.get_string($bypassstr, 'admin').'</p>';
}
///Process the restrict if necessary
if ($restrictstr = $environment_result->getRestrictStr()) {
$feedbacktext .= '<p class="error">'.get_string($restrictstr, 'admin').'</p>';
}
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);
}
Expand Down Expand Up @@ -999,23 +991,33 @@ function setInfo($info) {

/**
* 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;
}

/**
* 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;
Expand Down Expand Up @@ -1079,27 +1081,50 @@ function getPart() {

/**
* 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;
}

/**
* 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;
}

/**
* 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 '<p class="'.$class.'">'.$str.'</p>';
} else {
return '';
}
}
}

/// Here all the bypass functions are coded to be used by the environment
Expand Down
2 changes: 1 addition & 1 deletion question/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit afb36bc

Please sign in to comment.