1 | <?php |
||
15 | class Controller |
||
16 | { |
||
17 | /** |
||
18 | * Flysystem lib |
||
19 | * @var Filesystem |
||
20 | */ |
||
21 | private $system; |
||
22 | |||
23 | /** |
||
24 | * Receives dependencies |
||
25 | * |
||
26 | * @param Filesystem $system |
||
27 | */ |
||
28 | public function __construct(Filesystem $system) |
||
29 | { |
||
30 | $this->system = $system; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Gets the array of the local lessons & series. |
||
35 | * |
||
36 | * @return array |
||
37 | */ |
||
38 | public function getAllLessons() |
||
39 | { |
||
40 | $array = []; |
||
41 | $array['lessons'] = $this->getLessons(true); |
||
42 | $array['series'] = $this->getSeries(true); |
||
43 | |||
44 | Downloader::$totalLocalLessons = count($array['lessons']); |
||
45 | |||
46 | return $array; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Get the series |
||
51 | * |
||
52 | * @param bool $skip |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | private function getSeries($skip = false) |
||
86 | |||
87 | /** |
||
88 | * Gets the lessons in the folder. |
||
89 | * |
||
90 | * @param bool $skip |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | public function getLessons($skip = false) |
||
116 | |||
117 | /** |
||
118 | * Create skip file to lessons |
||
119 | */ |
||
120 | public function writeSkipLessons() |
||
132 | |||
133 | /** |
||
134 | * run write commands |
||
135 | */ |
||
136 | public function writeSkipFiles() |
||
137 | { |
||
138 | Utils::box('Creating skip files'); |
||
139 | |||
140 | $this->writeSkipSeries(); |
||
141 | Utils::write('Skip files for series created'); |
||
142 | |||
143 | $this->writeSkipLessons(); |
||
144 | Utils::write('Skip files for lesson created'); |
||
145 | |||
146 | Utils::box('Finished'); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Create skip file to lessons |
||
151 | */ |
||
152 | public function writeSkipSeries() |
||
164 | |||
165 | /** |
||
166 | * Get skiped lessons |
||
167 | * @return array |
||
168 | */ |
||
169 | public function getSkipLessons() |
||
170 | { |
||
171 | return $this->getSkipedData(LESSONS_FOLDER . '/.skip'); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Get skiped series |
||
176 | * @return array |
||
177 | */ |
||
178 | public function getSkipSeries() |
||
179 | { |
||
180 | return $this->getSkipedData(SERIES_FOLDER . '/.skip'); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * Read skip file |
||
185 | * |
||
186 | * @param $pathToSkipFile |
||
187 | * @return array|mixed |
||
188 | */ |
||
189 | private function getSkipedData($pathToSkipFile) { |
||
190 | |||
191 | if ($this->system->has($pathToSkipFile)) { |
||
192 | $content = $this->system->read($pathToSkipFile); |
||
193 | |||
194 | return unserialize($content); |
||
195 | } |
||
196 | |||
197 | return []; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Rename lessons, adding 0 padding to the number. |
||
202 | */ |
||
203 | public function renameLessonsWithRightPadding() |
||
226 | |||
227 | /** |
||
228 | * Create series folder if not exists. |
||
229 | * |
||
230 | * @param $serie |
||
231 | */ |
||
232 | public function createSerieFolderIfNotExists($serie) |
||
233 | { |
||
234 | $this->createFolderIfNotExists(SERIES_FOLDER . '/' . $serie); |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * Create folder if not exists. |
||
239 | * |
||
240 | * @param $folder |
||
241 | */ |
||
242 | public function createFolderIfNotExists($folder) |
||
248 | } |
||
249 |