Commit 33b1f3b0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Simplify get_my_files_data a bit

parent 5b22917e
...@@ -153,34 +153,24 @@ class ArtefactTypeFileBase extends ArtefactType { ...@@ -153,34 +153,24 @@ class ArtefactTypeFileBase extends ArtefactType {
$prefix = get_config('dbprefix'); $prefix = get_config('dbprefix');
if ($parentfolderid) { $foldersql = $parentfolderid ? ' = ' . $parentfolderid : ' IS NULL';
$foldersql = ' = ' . $parentfolderid;
} // if blogs are installed then also return the number of blog
else { // posts each file is attached to
$foldersql = ' IS NULL'; $bloginstalled = get_field('artefact_installed', 'active', 'name', 'blog');
}
// if blogs are installed then return whether the files are
// attached to blog posts
if (get_field('artefact_installed', 'active', 'name', 'blog')) {
$blogpostsql = ', COUNT (b.*) AS attachcount';
$blogpostjoin = 'LEFT OUTER JOIN ' . $prefix . 'artefact_blog_blogpost_file b ON b.file = a.id';
}
else {
$blogpostsql = '';
$blogpostjoin = '';
}
$filetypesql = "('" . join("','", PluginArtefactFile::get_artefact_types()) . "')"; $filetypesql = "('" . join("','", PluginArtefactFile::get_artefact_types()) . "')";
$filedata = get_records_sql_array('SELECT $filedata = get_records_sql_array('SELECT
a.id, a.artefacttype, a.mtime, f.size, a.title, a.description, a.id, a.artefacttype, a.mtime, f.size, a.title, a.description,
COUNT(c.*) AS childcount ' . $blogpostsql . ' COUNT(c.*) AS childcount '
. ($bloginstalled ? ', COUNT (b.*) AS attachcount' : '') . '
FROM ' . $prefix . 'artefact a FROM ' . $prefix . 'artefact a
LEFT OUTER JOIN ' . $prefix . 'artefact_file_files f ON f.artefact = a.id LEFT OUTER JOIN ' . $prefix . 'artefact_file_files f ON f.artefact = a.id
LEFT OUTER JOIN ' . $prefix . 'artefact c ON c.parent = a.id LEFT OUTER JOIN ' . $prefix . 'artefact c ON c.parent = a.id '
' . $blogpostjoin . ' . ($bloginstalled ? ('LEFT OUTER JOIN ' . $prefix .
WHERE a.owner = ' . $userid . ' 'artefact_blog_blogpost_file b ON b.file = a.id') : '') . '
AND a.parent' . $foldersql . ' WHERE a.parent' . $foldersql . '
AND a.owner = ' . $userid . '
AND a.artefacttype IN ' . $filetypesql . ' AND a.artefacttype IN ' . $filetypesql . '
GROUP BY GROUP BY
1, 2, 3, 4, 5, 6;', ''); 1, 2, 3, 4, 5, 6;', '');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment