Skip to content

Commit

Permalink
Bug fixing: file size
Browse files Browse the repository at this point in the history
  • Loading branch information
ykorvel committed Nov 29, 2012
1 parent 27a2086 commit ae538df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
9 changes: 4 additions & 5 deletions www/application/classes/controller/filemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions www/application/classes/controller/labyrinthmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
30 changes: 6 additions & 24 deletions www/application/classes/model/leap/map/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ae538df

Please sign in to comment.