Commit aef1e7f5 authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-57457 mod_book: Chapters are not userdata plus some improvements

parent 0e8c334e
......@@ -31,9 +31,6 @@ class backup_book_activity_structure_step extends backup_activity_structure_step
protected function define_structure() {
// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated.
$book = new backup_nested_element('book', array('id'), array(
'name', 'intro', 'introformat', 'numbering', 'navstyle',
......@@ -61,7 +58,7 @@ class backup_book_activity_structure_step extends backup_activity_structure_step
$tags->add_child($tag);
// All these source definitions only happen if we are including user info.
if ($userinfo && core_tag_tag::is_enabled('mod_book', 'book_chapters')) {
if (core_tag_tag::is_enabled('mod_book', 'book_chapters')) {
$tag->set_source_sql('SELECT t.id, ti.itemid, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
......
......@@ -31,14 +31,10 @@ class restore_book_activity_structure_step extends restore_activity_structure_st
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('book', '/activity/book');
$paths[] = new restore_path_element('book_chapter', '/activity/book/chapters/chapter');
if ($userinfo) {
$paths[] = new restore_path_element('book_chapter_tag', '/activity/book/chaptertags/tag');
}
$paths[] = new restore_path_element('book_chapter_tag', '/activity/book/chaptertags/tag');
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
......
......@@ -45,6 +45,7 @@ $PAGE->set_pagelayout('admin'); // TODO: Something. This is a bloody hack!
if ($chapterid) {
$chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id), '*', MUST_EXIST);
$chapter->tags = core_tag_tag::get_item_tags_array('mod_book', 'book_chapters', $chapter->id);
} else {
$chapter = new stdClass();
$chapter->id = null;
......@@ -76,9 +77,7 @@ if ($mform->is_cancelled()) {
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
$chapter = $DB->get_record('book_chapters', array('id' => $data->id));
if (core_tag_tag::is_enabled('mod_book', 'book_chapters')) {
core_tag_tag::set_item_tags('mod_book', 'book_chapters', $chapter->id, $context, $data->tags);
}
core_tag_tag::set_item_tags('mod_book', 'book_chapters', $chapter->id, $context, $data->tags);
\mod_book\event\chapter_updated::create_from_chapter($book, $context, $chapter)->trigger();
} else {
......@@ -105,9 +104,7 @@ if ($mform->is_cancelled()) {
$DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
$chapter = $DB->get_record('book_chapters', array('id' => $data->id));
if (core_tag_tag::is_enabled('mod_book', 'book_chapters') && isset($data->tags)) {
core_tag_tag::set_item_tags('mod_book', 'book_chapters', $chapter->id, $context, $data->tags);
}
core_tag_tag::set_item_tags('mod_book', 'book_chapters', $chapter->id, $context, $data->tags);
\mod_book\event\chapter_created::create_from_chapter($book, $context, $chapter)->trigger();
}
......@@ -127,11 +124,6 @@ if ($chapters = book_preload_chapters($book)) {
echo $OUTPUT->header();
echo $OUTPUT->heading($book->name);
if (core_tag_tag::is_enabled('mod_book', 'book_chapters')) {
$data = new StdClass();
$data->tags = core_tag_tag::get_item_tags_array('mod_book', 'book_chapters', $chapter->id);
}
$mform->set_data($data);
$mform->display();
echo $OUTPUT->footer();
......@@ -60,10 +60,9 @@ class book_chapter_edit_form extends moodleform {
if (core_tag_tag::is_enabled('mod_book', 'book_chapters')) {
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
$mform->addElement('tags', 'tags', get_string('tags'),
array('itemtype' => 'book_chapters', 'component' => 'mod_book'));
}
$mform->addElement('tags', 'tags', get_string('tags'),
array('itemtype' => 'book_chapters', 'component' => 'mod_book'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
......
......@@ -17,7 +17,7 @@ Feature: Edited book chapters handle tags correctly
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I am on "Course 1" course homepage
And I turn editing mode on
And I add a "Book" to section "1" and I fill the form with:
| Name | Test book |
......@@ -26,7 +26,7 @@ Feature: Edited book chapters handle tags correctly
Scenario: Book chapter edition of custom tags works as expected
Given I log in as "teacher1"
And I follow "Course 1"
And I am on "Course 1" course homepage
And I follow "Test book"
And I set the following fields to these values:
| Chapter title | Dummy first chapter |
......@@ -52,7 +52,7 @@ Feature: Edited book chapters handle tags correctly
And I press "Continue"
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I am on "Course 1" course homepage
And I follow "Test book"
And I click on ".form-autocomplete-downarrow" "css_element"
And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment