mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-58920 questions: Calculated question name passing multilang.
In "Shared wild cards" table calculated question name do pass format_string to process multilang tags. Thus, not breaking the layout any more.
This commit is contained in:
parent
17fb1d84a2
commit
06147c5ab3
@ -1623,13 +1623,8 @@ class qtype_calculated extends question_type {
|
||||
<td align=\"left\">";
|
||||
foreach ($datasetdef->questions as $qu) {
|
||||
// Limit the name length displayed.
|
||||
if (!empty($qu->name)) {
|
||||
$qu->name = (strlen($qu->name) > $lnamemax) ?
|
||||
substr($qu->name, 0, $lnamemax).'...' : $qu->name;
|
||||
} else {
|
||||
$qu->name = '';
|
||||
}
|
||||
$text .= " {$qu->name} <br/>";
|
||||
$questionname = $this->get_short_question_name($qu->name, $lnamemax);
|
||||
$text .= " {$questionname} <br/>";
|
||||
}
|
||||
$text .= "</td></tr>";
|
||||
}
|
||||
@ -1640,6 +1635,26 @@ class qtype_calculated extends question_type {
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function shortens a question name if it exceeds the character limit.
|
||||
*
|
||||
* @param string $stringtoshorten the string to be shortened.
|
||||
* @param int $characterlimit the character limit.
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_question_name($stringtoshorten, $characterlimit)
|
||||
{
|
||||
if (!empty($stringtoshorten)) {
|
||||
$returnstring = format_string($stringtoshorten);
|
||||
if (strlen($returnstring) > $characterlimit) {
|
||||
$returnstring = shorten_text($returnstring, $characterlimit, true);
|
||||
}
|
||||
return $returnstring;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function build a table showing the available category shareable
|
||||
* wild cards, their name, their definition (Min, Max, Decimal) , the item count
|
||||
@ -1705,17 +1720,12 @@ class qtype_calculated extends question_type {
|
||||
$line = 0;
|
||||
foreach ($datasetdef->questions as $qu) {
|
||||
// Limit the name length displayed.
|
||||
if (!empty($qu->name)) {
|
||||
$qu->name = (strlen($qu->name) > $lnamemax) ?
|
||||
substr($qu->name, 0, $lnamemax).'...' : $qu->name;
|
||||
} else {
|
||||
$qu->name = '';
|
||||
}
|
||||
$questionname = $this->get_short_question_name($qu->name, $lnamemax);
|
||||
if ($line) {
|
||||
$text .= "<tr>";
|
||||
}
|
||||
$line++;
|
||||
$text .= "<td align=\"left\" style=\"white-space:nowrap;\">{$qu->name}</td>";
|
||||
$text .= "<td align=\"left\" style=\"white-space:nowrap;\">{$questionname}</td>";
|
||||
// TODO MDL-43779 should not have quiz-specific code here.
|
||||
$nbofquiz = $DB->count_records('quiz_slots', array('questionid' => $qu->id));
|
||||
$nbofattempts = $DB->count_records_sql("
|
||||
|
@ -106,4 +106,25 @@ class qtype_calculated_test extends advanced_testcase {
|
||||
),
|
||||
), $this->qtype->get_possible_responses($q));
|
||||
}
|
||||
|
||||
public function test_get_short_question_name() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Enable multilang filter to on content and heading.
|
||||
filter_set_global_state('multilang', TEXTFILTER_ON);
|
||||
filter_set_applies_to_strings('multilang', 1);
|
||||
$filtermanager = filter_manager::instance();
|
||||
$filtermanager->reset_caches();
|
||||
|
||||
$context = context_system::instance();
|
||||
|
||||
$longmultilangquestionname = "<span lang=\"en\" class=\"multilang\">Lorem ipsum dolor sit amet, consetetur sadipscing elitr</span><span lang=\"fr\" class=\"multilang\">Lorem ipsum dolor sit amet, consetetur sadipscing elitr</span>";
|
||||
$shortmultilangquestionname = "<span lang=\"en\" class=\"multilang\">Lorem ipsum</span><span lang=\"fr\" class=\"multilang\">Lorem ipsum</span>";
|
||||
$longquestionname = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr";
|
||||
$shortquestionname = "Lorem ipsum";
|
||||
$this->assertEquals("Lorem ipsum dolor...", $this->qtype->get_short_question_name($longmultilangquestionname, 20));
|
||||
$this->assertEquals("Lorem ipsum", $this->qtype->get_short_question_name($shortmultilangquestionname, 20));
|
||||
$this->assertEquals("Lorem ipsum dolor...", $this->qtype->get_short_question_name($longquestionname, 20));
|
||||
$this->assertEquals("Lorem ipsum", $this->qtype->get_short_question_name($shortquestionname, 20));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user