Permalink
Browse files

Merge branch 'MDL-26229_restore_attempts_wip' of git://github.com/str…

…onk7/moodle
  • Loading branch information...
2 parents e027bfc + 7cff492 commit 995b6ff605eeeb5cfb0afef9ea67de7482af7634 @skodak skodak committed Feb 14, 2011
@@ -94,6 +94,10 @@ protected function add_used($element) {
}
protected function check_and_set_used($element) {
+ // First of all, check the element being added doesn't conflict with own final elements
+ if (array_key_exists($element->get_name(), $this->final_elements)) {
+ throw new base_element_struct_exception('baseelementchildnameconflict', $element->get_name());
+ }
$grandparent = $this->get_grandoptigroupelement_or_grandparent();
if ($existing = array_intersect($grandparent->get_used(), $element->get_used())) { // Check the element isn't being used already
throw new base_element_struct_exception('baseelementexisting', implode($existing));
@@ -393,5 +393,16 @@ function test_wrong_tree() {
$this->assertTrue($e instanceof base_element_parent_exception);
}
+ // Add child element already used by own final elements
+ $nested = new mock_base_nested_element('PARENT1', null, array('FINAL1', 'FINAL2'));
+ $child = new mock_base_nested_element('FINAL2', null, array('FINAL3', 'FINAL4'));
+ try {
+ $nested->add_child($child);
+ $this->fail("Expecting base_element_struct_exception exception, none occurred");
+ } catch (Exception $e) {
+ $this->assertTrue($e instanceof base_element_struct_exception);
+ $this->assertEqual($e->errorcode, 'baseelementchildnameconflict');
+ $this->assertEqual($e->a, 'FINAL2');
+ }
}
}
@@ -104,13 +104,18 @@ public function process_chunk($data) {
$alltagswhitespace = false;
continue;
}
+
// If the path including the tag name matches another selected path
- // (registered or parent) delete it, another chunk will contain that info
+ // (registered or parent) and is null or begins with linefeed, we know it's part
+ // of another chunk, delete it, another chunk will contain that info
if ($this->path_is_selected($path . '/' . $key) ||
$this->path_is_selected_parent($path . '/' . $key)) {
- unset($data['tags'][$key]);
- continue;
+ if (!isset($value['cdata']) || substr($value['cdata'], 0, 1) === "\n") {
+ unset($data['tags'][$key]);
+ continue;
+ }
}
+
// Convert to simple name => value array
$data['tags'][$key] = isset($value['cdata']) ? $value['cdata'] : null;
@@ -201,7 +201,12 @@ protected function start_tag($parser, $tag, $attributes) {
// Entering a new inner level, publish all the information available
if ($this->level > $this->prevlevel) {
if (!empty($this->currtag) && (!empty($this->currtag['attrs']) || !empty($this->currtag['cdata']))) {
- $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ // We always add the last not-empty repetition. Empty ones are ignored.
+ if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
+ // Do nothing, the tag already exists and the repetition is empty
+ } else {
+ $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ }
}
if (!empty($this->topush['tags'])) {
$this->publish($this->topush);
@@ -233,7 +238,12 @@ protected function end_tag($parser, $tag) {
// Ending rencently started tag, add value to current tag
if ($this->level == $this->prevlevel) {
$this->currtag['cdata'] = $this->postprocess_cdata($this->accum);
- $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ // We always add the last not-empty repetition. Empty ones are ignored.
+ if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
+ // Do nothing, the tag already exists and the repetition is empty
+ } else {
+ $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ }
$this->currtag = array();
}
@@ -106,6 +106,9 @@
<name>4</name><!-- Only last will be processed. We don't allow repeated final tags in our parser -->
<value>4</value>
<value>5</value><!-- Only last will be processed. We don't allow repeated final tags in our parser -->
+ <value>
+
+ </value><!-- If one tag already is set and the repeated is empty, the original value is kept -->
</othertest>
</glossary>
</activity>
@@ -76,8 +76,11 @@ protected function define_structure() {
'minquestions','maxpages','timed','maxtime','retake','activitylink',
'mediafile','mediaheight','mediawidth','mediaclose','slideshow',
'width','height','bgcolor','displayleft','displayleftif','progressbar',
- 'highscores','maxhighscores','available','deadline','timemodified'
+ 'showhighscores','maxhighscores','available','deadline','timemodified'
));
+ // Tell the lesson element about the showhighscores elements mapping to the highscores
+ // database field.
+ $lesson->set_source_alias('highscores', 'showhighscores');
// The lesson_pages table
// Grouped within a `pages` element, important to note that page is relational
@@ -62,6 +62,13 @@ protected function process_lesson($data) {
$data->deadline = $this->apply_date_offset($data->deadline);
$data->timemodified = $this->apply_date_offset($data->timemodified);
+ // lesson->highscores can come both in data->highscores and
+ // data->showhighscores, handle both. MDL-26229
+ if (isset($data->showhighscores)) {
+ $data->highscores = $data->showhighscores;
+ unset($data->showhighscores);
+ }
+
// insert the lesson record
$newitemid = $DB->insert_record('lesson', $data);
// immediately after inserting "activity" record, call this
@@ -39,7 +39,7 @@ protected function define_structure() {
// Define each element separated
$quiz = new backup_nested_element('quiz', array('id'), array(
'name', 'intro', 'introformat', 'timeopen',
- 'timeclose', 'optionflags', 'penaltyscheme', 'attempts',
+ 'timeclose', 'optionflags', 'penaltyscheme', 'attempts_number',
'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints',
'review', 'questionsperpage', 'shufflequestions', 'shuffleanswers',
'questions', 'sumgrades', 'grade', 'timecreated',
@@ -119,6 +119,7 @@ protected function define_structure() {
}
// Define source alias
+ $quiz->set_source_alias('attempts', 'attempts_number');
$grade->set_source_alias('grade', 'gradeval');
$attempt->set_source_alias('attempt', 'attemptnum');
@@ -67,6 +67,13 @@ protected function process_quiz($data) {
$data->questions = $this->questions_recode_layout($data->questions);
+ // quiz->attempts can come both in data->attempts and
+ // data->attempts_number, handle both. MDL-26229
+ if (isset($data->attempts_number)) {
+ $data->attempts = $data->attempts_number;
+ unset($data->attempts_number);
+ }
+
// insert the quiz record
$newitemid = $DB->insert_record('quiz', $data);
// immediately after inserting "activity" record, call this

0 comments on commit 995b6ff

Please sign in to comment.