Skip to content

Commit

Permalink
MDL-57457 mod_book: Chapters are not userdata plus some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 21, 2017
1 parent 0e8c334 commit aef1e7f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
5 changes: 1 addition & 4 deletions mod/book/backup/moodle2/backup_book_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -61,7 +58,7 @@ protected function define_structure() {
$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
Expand Down
6 changes: 1 addition & 5 deletions mod/book/backup/moodle2/restore_book_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 3 additions & 11 deletions mod/book/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

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;
Expand Down Expand Up @@ -76,9 +77,7 @@
$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 {
Expand All @@ -105,9 +104,7 @@
$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();
}
Expand All @@ -127,11 +124,6 @@
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();
5 changes: 2 additions & 3 deletions mod/book/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ function definition() {

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);
Expand Down
6 changes: 3 additions & 3 deletions mod/book/tests/behat/edit_tags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand All @@ -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"
Expand Down

0 comments on commit aef1e7f

Please sign in to comment.