IHMInputOutputDownloadObjectClass.php
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @class IHMInputOutputDownloadObjectClass
* @brief Class that's implement an InputOutputInterface used to treat a get download object request
* @details
*/
class IHMInputOutputDownloadObjectClass implements InputOutputInterface
{
/*
* @brief Get working dir name
*/
protected function getWorkingDirName()
{
return $this->requestDirPrefix."DownloadData_";
}
/*
* @brief Get full working dir path
*/
protected function getWorkingPath()
{
return IHMConfigClass::getRequestPath().$this->getWorkingDirName().'/';
}
public function getInputData($input, $function, $requestId = ""){
if (is_dir(IHMConfigClass::getDownloadTmpPath())) {
foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.zip') as $filename) unlink($filename);
foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.tar.gz') as $filename) unlink($filename);
}
else {
mkdir(IHMConfigClass::getDownloadTmpPath());
}
$this->downloadObjectData = new DownloadObjectRequestDataClass();
if($input->nodeType == "download" && $input->downloadSrc == "2")
{
// Set type
$this->downloadObjectData->setType(DownloadObjectTypeEnumClass::ASTROIMG);
// Set list of links to download
if(sizeof($input->list) > 0){
foreach ($input->list as $file) {
$this->downloadObjectData->addFile($file->name, $file->url);
}
}
}
else {
throw new Exception('Unknown download data type.');
}
$outputFileName = "".$this->downloadObjectData->getType()."_".time();
// Set working dir
$this->downloadObjectData->setWorkingPath($this->getWorkingPath());
// Set compression format
switch ($input->compression) {
case DownloadObjectFormatEnumClass::ZIP:
$this->downloadObjectData->setCompressionFormat(DownloadObjectFormatEnumClass::ZIP);
$extension = ".zip";
break;
default:
throw new Exception('Unknown compression format type.');
}
// Set output
$outputPath = IHMConfigClass::getDownloadTmpPath() . $outputFileName . $extension;
$this->downloadObjectData->setOutputPath($outputPath);
return $this->downloadObjectData;
}
public function getOutput($data)
{
if (!$data->getSuccess())
return array(
'success' => false,
'message' => $data->getLastErrorMessage());
return array(
'success' => true,
'download' => str_replace(IHM_SRC_DIR, '', $data->getOutputPath()),
);
}
}