|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Claudio Cardinale <[email protected]> |
|
5
|
|
|
* Date: 18/12/15 |
|
6
|
|
|
* Time: 15.20 |
|
7
|
|
|
* This program is free software; you can redistribute it and/or |
|
8
|
|
|
* modify it under the terms of the GNU General Public License |
|
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
10
|
|
|
* of the License, or (at your option) any later version. |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with this program; if not, write to the Free Software |
|
17
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace plunner\Console\Commands\Optimise; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Path |
|
24
|
|
|
* tmp path where csv files for the solver task |
|
25
|
|
|
* @package plunner\Console\Commands\Optimise |
|
26
|
|
|
* @author Claudio Cardinale <[email protected]> |
|
27
|
|
|
* @copyright 2015 Claudio Cardinale |
|
28
|
|
|
* @version 1.0.0 |
|
29
|
|
|
*/ |
|
30
|
|
|
class Path |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $path; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Path constructor. |
|
39
|
|
|
* @param string $path |
|
40
|
|
|
*/ |
|
41
|
4 |
|
private function __construct($path) |
|
42
|
|
|
{ |
|
43
|
4 |
|
$this->path = $path; |
|
44
|
4 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @throws OptimiseException |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function __destruct() |
|
50
|
|
|
{ |
|
51
|
2 |
|
if ($this->path && is_dir($this->path) && !self::delTree($this->path)) |
|
52
|
2 |
|
throw new OptimiseException('problems during removing of path directory'); |
|
53
|
2 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
4 |
|
public function getPath() |
|
59
|
|
|
{ |
|
60
|
4 |
|
return $this->path; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $path |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setPath($path) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->path = $path; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @throws OptimiseException on problems during creation of tmp dir |
|
74
|
|
|
*/ |
|
75
|
4 |
|
static public function createPath() |
|
76
|
|
|
{ |
|
77
|
4 |
|
$path = new Path(tempnam(sys_get_temp_dir(), 'OPT')); //TODO check the return in case of errors this return false on failure |
|
78
|
4 |
|
unlink($path->getPath()); //remove file to create a dir |
|
79
|
4 |
|
if(file_exists($path->getPath())) |
|
80
|
4 |
|
throw new OptimiseException('problem during creation of tmp dir (the directory already exists)'); |
|
81
|
4 |
|
if(!@mkdir($path->getPath())) |
|
82
|
4 |
|
throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');; |
|
83
|
4 |
|
if(! is_dir($path->getPath())) |
|
84
|
4 |
|
throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)'); |
|
85
|
4 |
|
return $path; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* remove a no empty dir |
|
90
|
|
|
* @param $dir |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
2 |
|
private static function delTree($dir) { |
|
94
|
2 |
|
$files = array_diff(scandir($dir), array('.','..')); |
|
95
|
2 |
|
foreach ($files as $file) { |
|
96
|
2 |
|
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file"); |
|
97
|
2 |
|
} |
|
98
|
2 |
|
return rmdir($dir); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
4 |
|
public function getModelPath() |
|
106
|
|
|
{ |
|
107
|
4 |
|
return $this->path.'/model.mod'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
4 |
|
public function getUsersPath() |
|
114
|
|
|
{ |
|
115
|
4 |
|
return $this->path.'/Users.csv'; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
4 |
|
public function getMeetingsPath() |
|
122
|
|
|
{ |
|
123
|
4 |
|
return $this->path.'/Meeting.csv'; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
4 |
|
public function getMeetingsDurationPath() |
|
130
|
|
|
{ |
|
131
|
4 |
|
return $this->path.'/MeetingsDuration.csv'; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
4 |
|
public function getMeetingsAvailabilityPath() |
|
138
|
|
|
{ |
|
139
|
4 |
|
return $this->path.'/MeetingsAvailability.csv'; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
4 |
|
public function getUsersAvailabilityPath() |
|
146
|
|
|
{ |
|
147
|
4 |
|
return $this->path.'/UsersAvailability.csv'; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
4 |
|
public function getUsersMeetingsPath() |
|
154
|
|
|
{ |
|
155
|
4 |
|
return $this->path.'/UsersMeetings.csv'; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
4 |
|
public function getXPath() |
|
162
|
|
|
{ |
|
163
|
4 |
|
return $this->path.'/x.csv'; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return string |
|
168
|
|
|
*/ |
|
169
|
4 |
|
public function getYPath() |
|
170
|
|
|
{ |
|
171
|
4 |
|
return $this->path.'/y.csv'; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return string |
|
176
|
|
|
*/ |
|
177
|
4 |
|
public function getOutputPath() |
|
178
|
|
|
{ |
|
179
|
4 |
|
return $this->path.'/out.txt'; |
|
180
|
|
|
} |
|
181
|
|
|
} |