From ff9019a16b1dbfaac992b33f14096de0865fc819 Mon Sep 17 00:00:00 2001 From: Daniel Thies Date: Wed, 4 Apr 2018 19:26:05 -0500 Subject: [PATCH] MDL-61476 mod_glossary: Support tags in entries export --- mod/glossary/import.php | 13 +++++++ mod/glossary/lib.php | 10 ++++++ .../tests/behat/import_entries.feature | 13 +++++++ mod/glossary/tests/fixtures/musicians.xml | 34 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 mod/glossary/tests/fixtures/musicians.xml diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 136e57e0465..b31241d7276 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -280,6 +280,19 @@ if ($xml = glossary_read_imported_file($result)) { $DB->update_record("glossary_entries", array('id' => $newentry->id, 'attachment' => '1')); } + // Import tags associated with the entry. + if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { + $xmltags = @$xmlentry['#']['TAGS'][0]['#']['TAG']; // Ignore missing TAGS. + $sizeofxmltags = count($xmltags); + for ($k = 0; $k < $sizeofxmltags; $k++) { + // Importing tags. + $tag = $xmltags[$k]['#']; + if (!empty($tag)) { + core_tag_tag::add_item_tag('mod_glossary', 'glossary_entries', $newentry->id, $glossarycontext, $tag); + } + } + } + } else { $entriesrejected++; if ( $newentry->concept and $newentry->definition ) { diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index f8982a8dd6f..cbcc71d0838 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -2383,6 +2383,16 @@ function glossary_generate_export_file($glossary, $ignored = "", $hook = 0) { // Export attachments. $co .= glossary_xml_export_files('ATTACHMENTFILES', 4, $context->id, 'attachment', $entry->id); + // Export tags. + $tags = core_tag_tag::get_item_tags_array('mod_glossary', 'glossary_entries', $entry->id); + if (count($tags)) { + $co .= glossary_start_tag("TAGS", 4, true); + foreach ($tags as $tag) { + $co .= glossary_full_tag("TAG", 5, false, $tag); + } + $co .= glossary_end_tag("TAGS", 4, true); + } + $co .= glossary_end_tag("ENTRY",3,true); } } diff --git a/mod/glossary/tests/behat/import_entries.feature b/mod/glossary/tests/behat/import_entries.feature index c33372c8e20..8bb84b9119e 100644 --- a/mod/glossary/tests/behat/import_entries.feature +++ b/mod/glossary/tests/behat/import_entries.feature @@ -32,3 +32,16 @@ Feature: Importing glossary entries And I am on "Course 1" course homepage And I should see "Added Glossary" in the "Recent activity" "block" And I should see "New glossary entries:" in the "Recent activity" "block" + + @javascript @block_tags + Scenario: Importing glossary entries and checking Tags block + Given I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I add the "Tags" block + And I follow "Glossary 1" + And I navigate to "Import entries" in current page administration + And I upload "mod/glossary/tests/fixtures/musicians.xml" file to "File to import" filemanager + When I press "Submit" + And I am on "Course 1" course homepage + And I click on "Beatles" "link" in the "Tags" "block" + Then I should see "Paul McCartney" diff --git a/mod/glossary/tests/fixtures/musicians.xml b/mod/glossary/tests/fixtures/musicians.xml new file mode 100644 index 00000000000..442590d463b --- /dev/null +++ b/mod/glossary/tests/fixtures/musicians.xml @@ -0,0 +1,34 @@ + + + + Musicians + + 1 + 0 + dictionary + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 10 + + + Paul McCartney + <p>Popular British composer, guitarist, and vocalist. <br></p> + 1 + 1 + 0 + 0 + 1 + + Beatles + The Quarrymen + Wings + + + + +