mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
Merge branch 'MDL-58920-calculated-question-edit-name-multilang' of https://github.com/lucaboesch/moodle
This commit is contained in:
commit
ffd795ab95
2 changed files with 45 additions and 14 deletions
|
@ -1623,13 +1623,8 @@ class qtype_calculated extends question_type {
|
||||||
<td align=\"left\">";
|
<td align=\"left\">";
|
||||||
foreach ($datasetdef->questions as $qu) {
|
foreach ($datasetdef->questions as $qu) {
|
||||||
// Limit the name length displayed.
|
// Limit the name length displayed.
|
||||||
if (!empty($qu->name)) {
|
$questionname = $this->get_short_question_name($qu->name, $lnamemax);
|
||||||
$qu->name = (strlen($qu->name) > $lnamemax) ?
|
$text .= " {$questionname} <br/>";
|
||||||
substr($qu->name, 0, $lnamemax).'...' : $qu->name;
|
|
||||||
} else {
|
|
||||||
$qu->name = '';
|
|
||||||
}
|
|
||||||
$text .= " {$qu->name} <br/>";
|
|
||||||
}
|
}
|
||||||
$text .= "</td></tr>";
|
$text .= "</td></tr>";
|
||||||
}
|
}
|
||||||
|
@ -1640,6 +1635,26 @@ class qtype_calculated extends question_type {
|
||||||
return $text;
|
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
|
* This function build a table showing the available category shareable
|
||||||
* wild cards, their name, their definition (Min, Max, Decimal) , the item count
|
* wild cards, their name, their definition (Min, Max, Decimal) , the item count
|
||||||
|
@ -1705,17 +1720,12 @@ class qtype_calculated extends question_type {
|
||||||
$line = 0;
|
$line = 0;
|
||||||
foreach ($datasetdef->questions as $qu) {
|
foreach ($datasetdef->questions as $qu) {
|
||||||
// Limit the name length displayed.
|
// Limit the name length displayed.
|
||||||
if (!empty($qu->name)) {
|
$questionname = $this->get_short_question_name($qu->name, $lnamemax);
|
||||||
$qu->name = (strlen($qu->name) > $lnamemax) ?
|
|
||||||
substr($qu->name, 0, $lnamemax).'...' : $qu->name;
|
|
||||||
} else {
|
|
||||||
$qu->name = '';
|
|
||||||
}
|
|
||||||
if ($line) {
|
if ($line) {
|
||||||
$text .= "<tr>";
|
$text .= "<tr>";
|
||||||
}
|
}
|
||||||
$line++;
|
$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.
|
// TODO MDL-43779 should not have quiz-specific code here.
|
||||||
$nbofquiz = $DB->count_records('quiz_slots', array('questionid' => $qu->id));
|
$nbofquiz = $DB->count_records('quiz_slots', array('questionid' => $qu->id));
|
||||||
$nbofattempts = $DB->count_records_sql("
|
$nbofattempts = $DB->count_records_sql("
|
||||||
|
|
|
@ -106,4 +106,25 @@ class qtype_calculated_test extends advanced_testcase {
|
||||||
),
|
),
|
||||||
), $this->qtype->get_possible_responses($q));
|
), $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…
Add table
Add a link
Reference in a new issue