Skip to content

Commit

Permalink
MDL-61476 mod_glossary: Support tags in entries export
Browse files Browse the repository at this point in the history
  • Loading branch information
dthies authored and stronk7 committed Apr 9, 2018
1 parent 3857876 commit ff9019a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mod/glossary/import.php
Expand Up @@ -280,6 +280,19 @@
$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 ) {
Expand Down
10 changes: 10 additions & 0 deletions mod/glossary/lib.php
Expand Up @@ -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);
}
}
Expand Down
13 changes: 13 additions & 0 deletions mod/glossary/tests/behat/import_entries.feature
Expand Up @@ -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"
34 changes: 34 additions & 0 deletions mod/glossary/tests/fixtures/musicians.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<GLOSSARY>
<INFO>
<NAME>Musicians</NAME>
<INTRO></INTRO>
<INTROFORMAT>1</INTROFORMAT>
<ALLOWDUPLICATEDENTRIES>0</ALLOWDUPLICATEDENTRIES>
<DISPLAYFORMAT>dictionary</DISPLAYFORMAT>
<SHOWSPECIAL>1</SHOWSPECIAL>
<SHOWALPHABET>1</SHOWALPHABET>
<SHOWALL>1</SHOWALL>
<ALLOWCOMMENTS>0</ALLOWCOMMENTS>
<USEDYNALINK>1</USEDYNALINK>
<DEFAULTAPPROVAL>1</DEFAULTAPPROVAL>
<GLOBALGLOSSARY>0</GLOBALGLOSSARY>
<ENTBYPAGE>10</ENTBYPAGE>
<ENTRIES>
<ENTRY>
<CONCEPT>Paul McCartney</CONCEPT>
<DEFINITION>&lt;p&gt;Popular British composer, guitarist, and vocalist. &lt;br&gt;&lt;/p&gt;</DEFINITION>
<FORMAT>1</FORMAT>
<USEDYNALINK>1</USEDYNALINK>
<CASESENSITIVE>0</CASESENSITIVE>
<FULLMATCH>0</FULLMATCH>
<TEACHERENTRY>1</TEACHERENTRY>
<TAGS>
<TAG>Beatles</TAG>
<TAG>The Quarrymen</TAG>
<TAG>Wings</TAG>
</TAGS>
</ENTRY>
</ENTRIES>
</INFO>
</GLOSSARY>

0 comments on commit ff9019a

Please sign in to comment.