From ae538df7a37ff7621234e73464d12459617081b3 Mon Sep 17 00:00:00 2001 From: ykorvel Date: Thu, 29 Nov 2012 12:28:36 +0200 Subject: [PATCH] Bug fixing: file size --- .../classes/controller/filemanager.php | 9 +++--- .../classes/controller/labyrinthmanager.php | 5 ++-- .../classes/model/leap/map/element.php | 30 ++++--------------- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/www/application/classes/controller/filemanager.php b/www/application/classes/controller/filemanager.php index 68f09db4..82082e3b 100644 --- a/www/application/classes/controller/filemanager.php +++ b/www/application/classes/controller/filemanager.php @@ -26,14 +26,13 @@ public function action_index() { $mapId = $this->request->param('id', NULL); if($mapId != NULL) { $this->templateData['map'] = DB_ORM::model('map', array((int)$mapId)); - - $fileInfo = DB_ORM::model('map_element')->getFilesSize(); + + $this->templateData['files'] = DB_ORM::model('map_element')->getAllFilesByMap((int)$mapId); + $fileInfo = DB_ORM::model('map_element')->getFilesSize($this->templateData['files']); $this->templateData['files_size'] = DB_ORM::model('map_element')->sizeFormat($fileInfo['size']); $this->templateData['files_count'] = $fileInfo['count']; - - $this->templateData['files'] = DB_ORM::model('map_element')->getAllFilesByMap((int)$mapId); - + $fileView = View::factory('labyrinth/file/view'); $fileView->set('templateData', $this->templateData); diff --git a/www/application/classes/controller/labyrinthmanager.php b/www/application/classes/controller/labyrinthmanager.php index 78be6a89..4d5d69a1 100644 --- a/www/application/classes/controller/labyrinthmanager.php +++ b/www/application/classes/controller/labyrinthmanager.php @@ -139,13 +139,12 @@ public function action_caseWizard(){ if ($receivedMapId != NULL){ $this->templateData['map'] = DB_ORM::model('map', array((int)$receivedMapId)); - $fileInfo = DB_ORM::model('map_element')->getFilesSize(); + $this->templateData['files'] = DB_ORM::model('map_element')->getAllFilesByMap((int)$receivedMapId); + $fileInfo = DB_ORM::model('map_element')->getFilesSize($this->templateData['files']); $this->templateData['files_size'] = DB_ORM::model('map_element')->sizeFormat($fileInfo['size']); $this->templateData['files_count'] = $fileInfo['count']; - $this->templateData['files'] = DB_ORM::model('map_element')->getAllFilesByMap((int)$receivedMapId); - $fileView = View::factory('labyrinth/casewizard/file/view'); $fileView->set('templateData', $this->templateData); diff --git a/www/application/classes/model/leap/map/element.php b/www/application/classes/model/leap/map/element.php index 9987cb75..a21da4ce 100644 --- a/www/application/classes/model/leap/map/element.php +++ b/www/application/classes/model/leap/map/element.php @@ -260,32 +260,14 @@ public function deleteFile($fileId) { unlink(DOCROOT.'/'.$this->path); } - public function getFilesSize() { + public function getFilesSize($filesArray) { $totalsize = 0; - $totalcount = 0; - $dircount = 0; - $path = DOCROOT.'/files/'; - if ($handle = opendir($path)) { - while (false !== ($file = readdir($handle))) { - $nextpath = $path . '/' . $file; - if ($file != '.' && $file != '..' && !is_link ($nextpath)) { - if (is_dir ($nextpath)) { - $dircount++; - $result = $this->getFilesSize($nextpath); - $totalsize += $result['size']; - $totalcount += $result['count']; - $dircount += $result['dircount']; - } else if (is_file ($nextpath)) { - $totalsize += filesize ($nextpath); - $totalcount++; - } - } - } - } - closedir ($handle); + foreach($filesArray as $file){ + $totalsize += filesize(DOCROOT.$file->path); + } + $total['size'] = $totalsize; - $total['count'] = $totalcount; - $total['dircount'] = $dircount; + $total['count'] = count($filesArray); return $total; }