11 define(
"TITLE_SIZE_DASHBOARD", _(
"Folder and upload dashboard"));
26 $this->Name =
"size_dashboard";
27 $this->Title = TITLE_SIZE_DASHBOARD;
28 $this->MenuList =
"Admin::Dashboards::Folder/Upload Proportions";
29 $this->Dependency = array();
31 parent::__construct();
32 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
33 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
43 $sql =
'INNER JOIN upload ON upload.pfile_fk=pfile.pfile_pk '.
44 'INNER JOIN foldercontents ON upload.upload_pk=foldercontents.child_id '.
45 'INNER JOIN upload_clearing ON upload.upload_pk=upload_clearing.upload_fk '.
47 $statementName = __METHOD__.
"GetFolderSize";
48 $folderSizesql =
'SELECT SUM(pfile_size) FROM pfile '.$sql;
49 $row = $this->
dbManager->getSingleRow($folderSizesql,array($folderId),$statementName);
52 $dispSql =
"SELECT DISTINCT ON (upload.upload_pk) upload_pk, upload_filename, pfile_size, " .
53 "to_char(upload_ts, 'YYYY-MM-DD HH24:MI:SS') AS upload_ts, status_fk FROM pfile " . $sql .
" ORDER BY upload.upload_pk";
54 $statementNameDisp = __METHOD__ .
"GetEachUploadSize";
55 $results = $this->
dbManager->getRows($dispSql, [$folderId], $statementNameDisp);
57 $uploadIds = array_column($results,
'upload_pk');
58 $durationBatch = $this->uploadDao->getClearingDurationsBatch($uploadIds);
61 foreach ($results as $result) {
62 $clearingDuration = $durationBatch[$result[
"upload_pk"]] ?? [
'NA', 0];
63 $var .=
"<tr><td align='left'>" . $result[
'upload_pk'] .
64 "</td><td align='left'>" . $result[
'upload_filename'] .
65 "</td><td align='left' data-order='{$result['pfile_size']}'>" .
67 "</td><td align='left' data-order='{$clearingDuration[1]}'>$clearingDuration[0]</td>
68 <td align='left'>{$result['upload_ts']}</td><td align='left'>" . $this->
ConvertStatusToString($result[
'status_fk']) .
71 return [$var, $folderSize];
82 "SELECT DISTINCT ON (upload.upload_pk) upload_pk, upload_filename, pfile_size, to_char(upload_ts, 'YYYY-MM-DD HH24:MI:SS') AS upload_ts, status_fk " .
84 "INNER JOIN upload ON upload.pfile_fk=pfile.pfile_pk " .
85 "INNER JOIN foldercontents ON upload.upload_pk=foldercontents.child_id " .
86 "INNER JOIN upload_clearing ON upload.upload_pk=upload_clearing.upload_fk " .
87 "WHERE parent_fk=$1 ORDER BY upload.upload_pk",
89 __METHOD__ .
"ExportData"
92 $uploadIds = array_column($results,
'upload_pk');
93 $durationBatch = $this->uploadDao->getClearingDurationsBatch($uploadIds);
96 foreach ($results as $row) {
97 $clearingDuration = $durationBatch[$row[
"upload_pk"]] ?? [
'NA', 0];
99 'uploadid' => $row[
'upload_pk'],
100 'name' => $row[
'upload_filename'],
101 'size' => $row[
'pfile_size'],
102 'duration' => $clearingDuration[1],
103 'date' => $row[
'upload_ts'],
124 $statusString =
'Open';
126 $statusString =
'In progress';
127 }
else if ($status == 3) {
128 $statusString =
'Closed';
129 }
else if ($status == 4) {
130 $statusString =
'Rejected';
133 return $statusString;
142 header(
'Content-Type: text/csv');
143 header(
'Content-Disposition: attachment; filename="folder_export.csv"');
145 $output = fopen(
'php://output',
'w');
146 fputcsv($output, [
'Upload id',
'Upload name',
'Size (bytes)',
'Clearing duration (seconds)',
'Upload date',
'Upload status']);
148 foreach ($data as $row) {
168 header(
'Content-Type: application/json');
169 header(
'Content-Disposition: attachment; filename="folder_export.json"');
170 echo json_encode($data, JSON_PRETTY_PRINT);
180 if (!empty($exportFormat) && in_array($exportFormat, [
'csv',
'json'])) {
186 if (empty($folderId)) {
192 $formVars[
"onchangeURI"] =
Traceback_uri() .
"?mod=" . $this->Name .
"&selectfolderid=";
194 $formVars[
"tableVars"] = $tableVars;
195 $formVars[
"wholeFolderSize"] = $wholeFolderSize;
196 $formVars[
"currentFolderId"] = $folderId;
198 return $this->
renderString(
"admin-folder-size-form.html.twig", $formVars);
This is the Plugin class. All plugins should:
renderString($templateName, $vars=null)
getFolderAndUploadSize($folderId)
Given a folder's ID function will get size of the folder and uploads under it.
__construct()
base constructor. Most plugins will just use this
Output()
Generate the text for this plugin.
outputJSON($data)
Outputs data in JSON format.
ConvertStatusToString($status)
convert numaric status into string.
generateExportData($folderId, $format)
Generate export data in CSV or JSON format for a given folder ID.
outputCSV($data)
Outputs data in CSV format.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
HumanSize( $bytes)
Translate a byte number to a proper type, xxx bytes to xxx B/KB/MB/GB/TB/PB.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
fo_dbManager * dbManager
fo_dbManager object