mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-64820 filestorage: add multi item support to get_area_files
This commit is contained in:
parent
a30570c555
commit
cba111b376
2 changed files with 10 additions and 3 deletions
|
@ -598,7 +598,7 @@ class file_storage {
|
||||||
* @param int $contextid context ID
|
* @param int $contextid context ID
|
||||||
* @param string $component component
|
* @param string $component component
|
||||||
* @param mixed $filearea file area/s, you cannot specify multiple fileareas as well as an itemid
|
* @param mixed $filearea file area/s, you cannot specify multiple fileareas as well as an itemid
|
||||||
* @param int $itemid item ID or all files if not specified
|
* @param int|int[]|false $itemid item ID(s) or all files if not specified
|
||||||
* @param string $sort A fragment of SQL to use for sorting
|
* @param string $sort A fragment of SQL to use for sorting
|
||||||
* @param bool $includedirs whether or not include directories
|
* @param bool $includedirs whether or not include directories
|
||||||
* @param int $updatedsince return files updated since this time
|
* @param int $updatedsince return files updated since this time
|
||||||
|
@ -617,8 +617,10 @@ class file_storage {
|
||||||
if ($itemid !== false && is_array($filearea)) {
|
if ($itemid !== false && is_array($filearea)) {
|
||||||
throw new coding_exception('You cannot specify multiple fileareas as well as an itemid.');
|
throw new coding_exception('You cannot specify multiple fileareas as well as an itemid.');
|
||||||
} else if ($itemid !== false) {
|
} else if ($itemid !== false) {
|
||||||
$itemidsql = ' AND f.itemid = :itemid ';
|
$itemids = is_array($itemid) ? $itemid : [$itemid];
|
||||||
$conditions['itemid'] = $itemid;
|
list($itemidinorequalsql, $itemidconditions) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED);
|
||||||
|
$itemidsql = " AND f.itemid {$itemidinorequalsql}";
|
||||||
|
$conditions = array_merge($conditions, $itemidconditions);
|
||||||
} else {
|
} else {
|
||||||
$itemidsql = '';
|
$itemidsql = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,6 +591,11 @@ class core_externallib_testcase extends advanced_testcase {
|
||||||
$files = external_util::get_area_files($context, $component, $filearea, false);
|
$files = external_util::get_area_files($context, $component, $filearea, false);
|
||||||
$this->assertEquals($expectedfiles, $files);
|
$this->assertEquals($expectedfiles, $files);
|
||||||
|
|
||||||
|
$DB->method('get_in_or_equal')->willReturn([
|
||||||
|
'= :mock1',
|
||||||
|
['mock1' => $itemid]
|
||||||
|
]);
|
||||||
|
|
||||||
// Get just the file indicated by $itemid.
|
// Get just the file indicated by $itemid.
|
||||||
$files = external_util::get_area_files($context, $component, $filearea, $itemid);
|
$files = external_util::get_area_files($context, $component, $filearea, $itemid);
|
||||||
$this->assertEquals($expectedfiles, $files);
|
$this->assertEquals($expectedfiles, $files);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue