Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
98c49e1a
Commit
98c49e1a
authored
Mar 07, 2019
by
Adrian Greeve
Browse files
Merge branch 'MDL-64026-master' of
git://github.com/jleyva/moodle
parents
f9aeebd1
9b8aed89
Changes
3
Hide whitespace changes
Inline
Side-by-side
course/externallib.php
View file @
98c49e1a
...
...
@@ -318,7 +318,28 @@ class core_course_external extends external_api {
require_once
(
$CFG
->
dirroot
.
'/mod/'
.
$cm
->
modname
.
'/lib.php'
);
$getcontentfunction
=
$cm
->
modname
.
'_export_contents'
;
if
(
function_exists
(
$getcontentfunction
))
{
if
(
empty
(
$filters
[
'excludecontents'
])
and
$contents
=
$getcontentfunction
(
$cm
,
$baseurl
))
{
$contents
=
$getcontentfunction
(
$cm
,
$baseurl
);
$module
[
'contentsinfo'
]
=
array
(
'filescount'
=>
count
(
$contents
),
'filessize'
=>
0
,
'lastmodified'
=>
0
,
'mimetypes'
=>
array
(),
);
foreach
(
$contents
as
$content
)
{
if
(
isset
(
$content
[
'filesize'
]))
{
$module
[
'contentsinfo'
][
'filessize'
]
+=
$content
[
'filesize'
];
}
if
(
isset
(
$content
[
'timemodified'
])
&&
(
$content
[
'timemodified'
]
>
$module
[
'contentsinfo'
][
'lastmodified'
]))
{
$module
[
'contentsinfo'
][
'lastmodified'
]
=
$content
[
'timemodified'
];
}
if
(
isset
(
$content
[
'mimetype'
]))
{
$module
[
'contentsinfo'
][
'mimetypes'
][
$content
[
'mimetype'
]]
=
$content
[
'mimetype'
];
}
}
if
(
empty
(
$filters
[
'excludecontents'
])
and
!
empty
(
$contents
))
{
$module
[
'contents'
]
=
$contents
;
}
else
{
$module
[
'contents'
]
=
array
();
...
...
@@ -470,7 +491,18 @@ class core_course_external extends external_api {
'license'
=>
new
external_value
(
PARAM_TEXT
,
'Content license'
),
)
),
VALUE_DEFAULT
,
array
()
)
),
'contentsinfo'
=>
new
external_single_structure
(
array
(
'filescount'
=>
new
external_value
(
PARAM_INT
,
'Total number of files.'
),
'filessize'
=>
new
external_value
(
PARAM_INT
,
'Total files size.'
),
'lastmodified'
=>
new
external_value
(
PARAM_INT
,
'Last time files were modified.'
),
'mimetypes'
=>
new
external_multiple_structure
(
new
external_value
(
PARAM_RAW
,
'File mime type.'
),
'Files mime types.'
),
),
'Contents summary information.'
,
VALUE_OPTIONAL
),
)
),
'list of module'
)
...
...
course/tests/externallib_test.php
View file @
98c49e1a
...
...
@@ -1264,6 +1264,58 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this
->
assertEquals
(
'text/plain'
,
$customdata
[
'filedetails'
][
'mimetype'
]);
}
/**
* Test contents info is returned.
*/
public
function
test_get_course_contents_contentsinfo
()
{
global
$USER
;
$this
->
resetAfterTest
(
true
);
$this
->
setAdminUser
();
$course
=
self
::
getDataGenerator
()
->
create_course
();
$record
=
new
stdClass
();
$record
->
course
=
$course
->
id
;
// One resource with one file.
$resource1
=
self
::
getDataGenerator
()
->
create_module
(
'resource'
,
$record
);
$timenow
=
time
();
// More type of files.
$record
->
files
=
file_get_unused_draft_itemid
();
$usercontext
=
context_user
::
instance
(
$USER
->
id
);
$extensions
=
array
(
'txt'
,
'png'
,
'pdf'
);
foreach
(
$extensions
as
$key
=>
$extension
)
{
// Add actual file there.
$filerecord
=
array
(
'component'
=>
'user'
,
'filearea'
=>
'draft'
,
'contextid'
=>
$usercontext
->
id
,
'itemid'
=>
$record
->
files
,
'filename'
=>
'resource'
.
$key
.
'.'
.
$extension
,
'filepath'
=>
'/'
);
$fs
=
get_file_storage
();
$fs
->
create_file_from_string
(
$filerecord
,
'Test resource '
.
$key
.
' file'
);
}
$resource2
=
self
::
getDataGenerator
()
->
create_module
(
'resource'
,
$record
);
$result
=
core_course_external
::
get_course_contents
(
$course
->
id
);
$result
=
external_api
::
clean_returnvalue
(
core_course_external
::
get_course_contents_returns
(),
$result
);
$this
->
assertCount
(
2
,
$result
[
0
][
'modules'
]);
foreach
(
$result
[
0
][
'modules'
]
as
$module
)
{
if
(
$module
[
'instance'
]
==
$resource1
->
id
)
{
$this
->
assertEquals
(
1
,
$module
[
'contentsinfo'
][
'filescount'
]);
$this
->
assertGreaterThanOrEqual
(
$timenow
,
$module
[
'contentsinfo'
][
'lastmodified'
]);
$this
->
assertEquals
(
$module
[
'contents'
][
0
][
'filesize'
],
$module
[
'contentsinfo'
][
'filessize'
]);
$this
->
assertEquals
(
array
(
'text/plain'
),
$module
[
'contentsinfo'
][
'mimetypes'
]);
}
else
{
$this
->
assertEquals
(
count
(
$extensions
),
$module
[
'contentsinfo'
][
'filescount'
]);
$filessize
=
$module
[
'contents'
][
0
][
'filesize'
]
+
$module
[
'contents'
][
1
][
'filesize'
]
+
$module
[
'contents'
][
2
][
'filesize'
];
$this
->
assertEquals
(
$filessize
,
$module
[
'contentsinfo'
][
'filessize'
]);
$this
->
assertGreaterThanOrEqual
(
$timenow
,
$module
[
'contentsinfo'
][
'lastmodified'
]);
$this
->
assertEquals
(
array
(
'text/plain'
,
'image/png'
,
'application/pdf'
),
$module
[
'contentsinfo'
][
'mimetypes'
]);
}
}
}
/**
* Test duplicate_course
*/
...
...
course/upgrade.txt
View file @
98c49e1a
...
...
@@ -2,8 +2,10 @@ This files describes API changes in /course/*,
information provided here is intended especially for developers.
=== 3.7 ===
* External function core_course_external::get_course_contents new returns the following additional completiondata field:
- valueused (indicates whether the completion state affects the availability of other content)
* External function core_course_external::get_course_contents now returns a new contentsinfo field with summary files information.
=== 3.6 ===
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment