diff --git a/contentbank/tests/behat/delete_content.feature b/contentbank/tests/behat/delete_content.feature
index 9b142b7b3e6..1a41bb6f267 100644
--- a/contentbank/tests/behat/delete_content.feature
+++ b/contentbank/tests/behat/delete_content.feature
@@ -22,6 +22,7 @@ Feature: Delete H5P file from the content bank
And I click on "Choose a file..." "button"
And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "filltheblanks.h5p" "link"
+ And I set the field "Save as" to "content2delete.h5p"
And I click on "Select this file" "button"
And I click on "Save changes" "button"
@@ -29,15 +30,16 @@ Feature: Delete H5P file from the content bank
Given I open the action menu in "region-main-settings-menu" "region"
And I should see "Delete"
When I choose "Delete" in the open action menu
- And I should see "Are you sure you want to delete the content 'filltheblanks.h5p'"
+ And I should see "Are you sure you want to delete the content 'content2delete.h5p'"
+ And I should not see "The content will only be deleted from the content bank"
And I click on "Cancel" "button" in the "Delete content" "dialogue"
- Then I should see "filltheblanks.h5p"
+ Then I should see "content2delete.h5p"
And I open the action menu in "region-main-settings-menu" "region"
And I choose "Delete" in the open action menu
And I click on "Delete" "button" in the "Delete content" "dialogue"
And I wait until the page is ready
And I should see "The content has been deleted."
- And I should not see "filltheblanks.h5p"
+ And I should not see "content2delete.h5p"
Scenario: Users without the required capability can only delete their own content
Given the following "permission overrides" exist:
@@ -56,8 +58,8 @@ Feature: Delete H5P file from the content bank
And I click on "Save changes" "button"
When I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Content bank" "link" in the "Navigation" "block"
- And I should see "filltheblanks.h5p"
- And I follow "filltheblanks.h5p"
+ And I should see "content2delete.h5p"
+ And I follow "content2delete.h5p"
Then ".header-actions-container" "css_element" should not exist
And I click on "Content bank" "link"
And I click on "Upload" "link"
@@ -68,3 +70,23 @@ Feature: Delete H5P file from the content bank
And I click on "Save changes" "button"
And I open the action menu in "region-main-settings-menu" "region"
And I should see "Delete"
+
+ Scenario: The number of times a content is used is displayed before removing it
+ Given I follow "Dashboard" in the user menu
+ And I follow "Manage private files..."
+ And I click on "Add..." "button"
+ And I select "Content bank" repository in file picker
+ And I click on "content2delete.h5p" "file" in repository content area
+ And I click on "Link to the file" "radio"
+ And I click on "Select this file" "button"
+ And I click on "Save changes" "button"
+ When I click on "Site pages" "list_item" in the "Navigation" "block"
+ And I click on "Content bank" "link" in the "Navigation" "block"
+ And I follow "content2delete.h5p"
+ And I open the action menu in "region-main-settings-menu" "region"
+ And I choose "Delete" in the open action menu
+ Then I should see "Are you sure you want to delete the content 'content2delete.h5p'"
+ And I should see "The content will only be deleted from the content bank"
+ And I click on "Delete" "button" in the "Delete content" "dialogue"
+ And I should see "The content has been deleted."
+ And I should not see "content2delete.h5p"
diff --git a/contentbank/tests/behat/view_preferences.feature b/contentbank/tests/behat/view_preferences.feature
index 44fa8bfc969..8e3d2d7423c 100644
--- a/contentbank/tests/behat/view_preferences.feature
+++ b/contentbank/tests/behat/view_preferences.feature
@@ -1,28 +1,65 @@
-@core @core_contentbank @contentbank_h5p @javascript
+@core @core_contentbank @contentbank_h5p @_file_upload @javascript
Feature: Store the content bank view preference
In order to consistantly view the content bank in icons or details view
As an admin
I need to be able to store my view preference
Background:
- Given the following "contentbank content" exist:
- | contextlevel | reference | contenttype | user | contentname |
- | System | | contenttype_h5p | admin | filltheblanks.h5p |
- | System | | contenttype_h5p | admin | mathsbook.h5p |
-
- Scenario: Admins can order content in the content bank
Given I log in as "admin"
+ And I follow "Manage private files..."
+ And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager
+ And I upload "h5p/tests/fixtures/greeting-card-887.h5p" file to "Files" filemanager
+ And I click on "Save changes" "button"
And I am on site homepage
And I turn editing mode on
And I add the "Navigation" block if not present
+ And I configure the "Navigation" block
+ And I set the following fields to these values:
+ | Page contexts | Display throughout the entire site |
+ And I press "Save changes"
And I expand "Site pages" node
And I click on "Content bank" "link"
+ And I click on "Upload" "link"
+ And I click on "Choose a file..." "button"
+ And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
+ And I click on "filltheblanks.h5p" "link"
+ And I set the field "Save as" to "fib.h5p"
+ And I click on "Select this file" "button"
+ And I click on "Save changes" "button"
+ And I click on "Content bank" "link"
+ And I click on "Upload" "link"
+ And I click on "Choose a file..." "button"
+ And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
+ And I click on "greeting-card-887.h5p" "link"
+ And I set the field "Save as" to "greetingcard.h5p"
+ And I click on "Select this file" "button"
+ And I click on "Save changes" "button"
+
+ Scenario: There are several views for displaying contents into the content bank
+ Given I am on site homepage
+ And I click on "Content bank" "link"
When I click on "Display content bank with file details" "button"
- And I should see "Last modified"
- And I follow "filltheblanks.h5p"
+ Then I should see "Last modified"
+ And I follow "greetingcard.h5p"
And I click on "Content bank" "link"
And I should see "Last modified"
And I click on "Display content bank with icons" "button"
- And I follow "filltheblanks.h5p"
+ And I follow "greetingcard.h5p"
And I click on "Content bank" "link"
And I should not see "Last modified"
+
+ Scenario: Display the number of times a content is used in file details view
+ Given I follow "Dashboard" in the user menu
+ And I follow "Manage private files..."
+ And I click on "Add..." "button"
+ And I select "Content bank" repository in file picker
+ And I click on "fib.h5p" "file" in repository content area
+ And I click on "Link to the file" "radio"
+ And I click on "Select this file" "button"
+ And I click on "Save changes" "button"
+ When I am on site homepage
+ And I expand "Site pages" node
+ And I click on "Content bank" "link"
+ And I click on "Display content bank with file details" "button"
+ Then I should see "1" in the "[data-file='fib.h5p'] .cb-uses" "css_element"
+ And I should see "0" in the "[data-file='greetingcard.h5p'] .cb-uses" "css_element"
diff --git a/contentbank/tests/content_test.php b/contentbank/tests/content_test.php
index 4c7ec2b8a95..7bc2e831f05 100644
--- a/contentbank/tests/content_test.php
+++ b/contentbank/tests/content_test.php
@@ -298,4 +298,60 @@ class core_contenttype_content_testcase extends \advanced_testcase {
$this->assertInstanceOf(get_class($type), $contenttype);
}
+
+ /**
+ * Tests for 'get_uses' behaviour.
+ *
+ * @covers ::get_uses
+ */
+ public function test_get_uses() {
+ $this->resetAfterTest();
+ $this->setAdminUser();
+ $context = context_system::instance();
+
+ // Add some content to the content bank.
+ $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
+ $contents = $generator->generate_contentbank_data('contenttype_testable', 3, 0, $context);
+ $content1 = array_shift($contents);
+
+ // Check content has no references for now.
+ $this->assertCount(0, $content1->get_uses());
+
+ // Add a link to the previous content.
+ $cbfile = $content1->get_file();
+ $cbrecord = array(
+ 'contextid' => $cbfile->get_contextid(),
+ 'component' => $cbfile->get_component(),
+ 'filearea' => $cbfile->get_filearea(),
+ 'itemid' => $cbfile->get_itemid(),
+ 'filepath' => $cbfile->get_filepath(),
+ 'filename' => $cbfile->get_filename(),
+ );
+ $fs = get_file_storage();
+ $ref = $fs->pack_reference($cbrecord);
+
+ $aliasrecord = new stdClass();
+ $aliasrecord->contextid = $context->id;
+ $aliasrecord->component = 'core';
+ $aliasrecord->filearea = 'phpunit';
+ $aliasrecord->filepath = '/foo/';
+ $aliasrecord->filename = 'one.txt';
+ $aliasrecord->itemid = 0;
+
+ $repos = \repository::get_instances(['type' => 'contentbank']);
+ $cbrepo = reset($repos);
+ $this->assertInstanceOf('repository', $cbrepo);
+
+ $alias = $fs->create_file_from_reference($aliasrecord, $cbrepo->id, $ref);
+
+ // Check content now has one reference (the previous alias).
+ $contentuses1 = $content1->get_uses();
+ $this->assertCount(1, $contentuses1);
+ $reffile = reset($contentuses1);
+ $this->assertEquals($alias, $reffile);
+
+ // Check a different content hasn't any reference.
+ $content2 = array_shift($contents);
+ $this->assertCount(0, $content2->get_uses());
+ }
}
diff --git a/contentbank/upgrade.txt b/contentbank/upgrade.txt
new file mode 100644
index 00000000000..a94fbcf61d0
--- /dev/null
+++ b/contentbank/upgrade.txt
@@ -0,0 +1,5 @@
+This files describes API changes in core libraries and APIs,
+information provided here is intended especially for developers.
+
+=== 3.11 ===
+* Added "get_uses()" method to content class to return places where a content is used.
diff --git a/contentbank/view.php b/contentbank/view.php
index 46daffbc5b4..5e4cf3d2f0b 100644
--- a/contentbank/view.php
+++ b/contentbank/view.php
@@ -103,6 +103,7 @@ if ($contenttype->can_delete($content)) {
$attributes = [
'data-action' => 'deletecontent',
'data-contentname' => $content->get_name(),
+ 'data-uses' => count($content->get_uses()),
'data-contentid' => $content->get_id(),
'data-contextid' => $context->id,
];
diff --git a/lang/en/contentbank.php b/lang/en/contentbank.php
index 1eb44630634..648a47429cd 100644
--- a/lang/en/contentbank.php
+++ b/lang/en/contentbank.php
@@ -45,6 +45,7 @@ $string['errordeletingcontentfromcategory'] = 'Error deleting content from categ
$string['errornofile'] = 'A compatible file is needed to create content.';
$string['deletecontent'] = 'Delete content';
$string['deletecontentconfirm'] = 'Are you sure you want to delete the content \'{$a->name}\' and all associated files? This action cannot be undone.';
+$string['deletecontentconfirmlinked'] = 'The content will only be deleted from the content bank. Any places which currently link to it will be automatically updated to use a copy of the content instead.';
$string['displaydetails'] = 'Display content bank with file details';
$string['displayicons'] = 'Display content bank with icons';
$string['file'] = 'Upload content';
@@ -74,3 +75,4 @@ $string['timecreated'] = 'Time created';
$string['type'] = 'Type';
$string['unsupported'] = 'This content type is not supported.';
$string['upload'] = 'Upload';
+$string['uses'] = 'Places linked';
diff --git a/theme/boost/scss/moodle/contentbank.scss b/theme/boost/scss/moodle/contentbank.scss
index 8bed4e2a49a..b56ca61d3ae 100644
--- a/theme/boost/scss/moodle/contentbank.scss
+++ b/theme/boost/scss/moodle/contentbank.scss
@@ -45,6 +45,7 @@
margin-bottom: 0.5rem;
}
.cb-heading,
+ .cb-uses,
.cb-date,
.cb-size,
.cb-type,
@@ -99,12 +100,13 @@
flex: 0 0 40%;
max-width: 40%;
}
+ .cb-uses,
.cb-date,
.cb-size,
.cb-type,
.cb-author {
- flex: 0 0 15%;
- max-width: 15%;
+ flex: 0 0 12%;
+ max-width: 12%;
}
.cb-column.last {
border-right: 0;
diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css
index 045bdff6315..e3a76469231 100644
--- a/theme/boost/style/moodle.css
+++ b/theme/boost/style/moodle.css
@@ -13135,6 +13135,7 @@ table.calendartable caption {
margin-bottom: 0.5rem; }
.content-bank-container.view-grid .cb-heading,
+.content-bank-container.view-grid .cb-uses,
.content-bank-container.view-grid .cb-date,
.content-bank-container.view-grid .cb-size,
.content-bank-container.view-grid .cb-type,
@@ -13176,12 +13177,13 @@ table.calendartable caption {
.content-bank-container.view-list .cb-file {
flex: 0 0 40%;
max-width: 40%; }
+ .content-bank-container.view-list .cb-uses,
.content-bank-container.view-list .cb-date,
.content-bank-container.view-list .cb-size,
.content-bank-container.view-list .cb-type,
.content-bank-container.view-list .cb-author {
- flex: 0 0 15%;
- max-width: 15%; }
+ flex: 0 0 12%;
+ max-width: 12%; }
.content-bank-container.view-list .cb-column.last {
border-right: 0; } }
diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css
index c104721dda9..21d48152b5f 100644
--- a/theme/classic/style/moodle.css
+++ b/theme/classic/style/moodle.css
@@ -13349,6 +13349,7 @@ table.calendartable caption {
margin-bottom: 0.5rem; }
.content-bank-container.view-grid .cb-heading,
+.content-bank-container.view-grid .cb-uses,
.content-bank-container.view-grid .cb-date,
.content-bank-container.view-grid .cb-size,
.content-bank-container.view-grid .cb-type,
@@ -13390,12 +13391,13 @@ table.calendartable caption {
.content-bank-container.view-list .cb-file {
flex: 0 0 40%;
max-width: 40%; }
+ .content-bank-container.view-list .cb-uses,
.content-bank-container.view-list .cb-date,
.content-bank-container.view-list .cb-size,
.content-bank-container.view-list .cb-type,
.content-bank-container.view-list .cb-author {
- flex: 0 0 15%;
- max-width: 15%; }
+ flex: 0 0 12%;
+ max-width: 12%; }
.content-bank-container.view-list .cb-column.last {
border-right: 0; } }