4 |
4 |
namespace App\AdminModule\Components;
|
5 |
5 |
|
6 |
6 |
|
|
7 |
use App\Enum\EFlashMessage;
|
|
8 |
use App\Enum\ESurfaceTypes;
|
7 |
9 |
use App\Model\Repository\BookRepository;
|
8 |
10 |
use App\Model\Repository\BookTypeRepository;
|
|
11 |
use App\Model\Repository\LineRepository;
|
9 |
12 |
use App\Model\Repository\MuseumRepository;
|
10 |
13 |
use App\Model\Repository\OriginRepository;
|
11 |
14 |
use App\Model\Repository\TransliterationRepository;
|
... | ... | |
36 |
39 |
* @var BookTypeRepository
|
37 |
40 |
*/
|
38 |
41 |
private $bookTypeRepository;
|
|
42 |
/**
|
|
43 |
* @var LineRepository
|
|
44 |
*/
|
|
45 |
private $lineRepository;
|
|
46 |
|
|
47 |
const EXPORT_FILE_PATH = __DIR__ . '/../../../../temp/export/';
|
|
48 |
const EXPORT_FILE_TYPE = '.txt';
|
39 |
49 |
|
40 |
50 |
public function __construct(TransliterationRepository $transliterationRepository,
|
41 |
51 |
BookRepository $bookRepository,
|
42 |
52 |
MuseumRepository $museumRepository,
|
43 |
53 |
OriginRepository $originRepository,
|
44 |
|
BookTypeRepository $bookTypeRepository
|
|
54 |
BookTypeRepository $bookTypeRepository,
|
|
55 |
LineRepository $lineRepository
|
45 |
56 |
)
|
46 |
57 |
{
|
47 |
58 |
$this->transliterationRepository = $transliterationRepository;
|
... | ... | |
49 |
60 |
$this->museumRepository = $museumRepository;
|
50 |
61 |
$this->originRepository = $originRepository;
|
51 |
62 |
$this->bookTypeRepository = $bookTypeRepository;
|
|
63 |
$this->lineRepository = $lineRepository;
|
52 |
64 |
|
53 |
65 |
parent::__construct(FALSE);
|
54 |
66 |
}
|
... | ... | |
172 |
184 |
->setConfirm('Do you really want to delete transliteration?')
|
173 |
185 |
->setTitle('Delete')
|
174 |
186 |
->setClass('btn btn-xs btn-danger ajax');
|
|
187 |
|
|
188 |
$this->addExportCallback(
|
|
189 |
'Export dat',
|
|
190 |
function ($dataSource, $grid)
|
|
191 |
{
|
|
192 |
$this->exportData($dataSource, $grid);
|
|
193 |
},
|
|
194 |
TRUE);
|
175 |
195 |
}
|
176 |
196 |
|
177 |
197 |
/**
|
... | ... | |
221 |
241 |
return "";
|
222 |
242 |
}
|
223 |
243 |
}
|
|
244 |
|
|
245 |
/**
|
|
246 |
* @param $dataSource
|
|
247 |
* @param DataGrid $grid
|
|
248 |
*/
|
|
249 |
private function exportData($dataSource, $grid)
|
|
250 |
{
|
|
251 |
$exportData = [];
|
|
252 |
/** @var ActiveRow $activeRow */
|
|
253 |
foreach ($dataSource as $activeRow)
|
|
254 |
{
|
|
255 |
$lines = $this->lineRepository->getAllLinesForTransliteration($activeRow->getPrimary());
|
|
256 |
$chapterLines = [];
|
|
257 |
foreach ($lines as $line)
|
|
258 |
{
|
|
259 |
$chapterLines[$line->object_type][$line->surface_type][] = array('transliteration' => $line->transliteration, 'line_number' => $line->line_number);
|
|
260 |
}
|
|
261 |
$exportData[] = [
|
|
262 |
'bookName' => $activeRow->ref('id_book')->book_abrev,
|
|
263 |
'chapter' => $activeRow->chapter,
|
|
264 |
'transliterationData' => $chapterLines
|
|
265 |
];
|
|
266 |
}
|
|
267 |
|
|
268 |
$uniqueBooks = array_unique(array_map(function ($i) { return $i['bookName']; }, $exportData));
|
|
269 |
|
|
270 |
$currentDate = new \DateTime();
|
|
271 |
$exportFileName = 'text-export-' .
|
|
272 |
$currentDate->format('Y-m-d-H-i-s') .
|
|
273 |
self::EXPORT_FILE_TYPE;
|
|
274 |
try
|
|
275 |
{
|
|
276 |
if (!file_exists(self::EXPORT_FILE_PATH)) {
|
|
277 |
mkdir(self::EXPORT_FILE_PATH, 0777, true);
|
|
278 |
}
|
|
279 |
$exportFile = fopen(self::EXPORT_FILE_PATH . $exportFileName, 'w');
|
|
280 |
foreach ($uniqueBooks as $book)
|
|
281 |
{
|
|
282 |
$bookData = [];
|
|
283 |
foreach ($exportData as $data)
|
|
284 |
{
|
|
285 |
if ($data['bookName'] == $book)
|
|
286 |
{
|
|
287 |
$bookData[] = $data;
|
|
288 |
}
|
|
289 |
}
|
|
290 |
fwrite($exportFile, "|" . $book . "\n");
|
|
291 |
foreach ($bookData as $chapterData)
|
|
292 |
{
|
|
293 |
fwrite($exportFile, "|" . $chapterData['chapter'] . "\n");
|
|
294 |
foreach ($chapterData['transliterationData'] as $surfaces)
|
|
295 |
{
|
|
296 |
foreach ($surfaces as $type => $surface)
|
|
297 |
{
|
|
298 |
for ($i = 0; $i < sizeof($surface); $i++)
|
|
299 |
{
|
|
300 |
$line =
|
|
301 |
$surface[$i][LineRepository::COLUMN_LINE_NUMBER] .
|
|
302 |
" " .
|
|
303 |
$surface[$i][LineRepository::COLUMN_TRANSLITERATION];
|
|
304 |
if($i == 0 && $type != ESurfaceTypes::OBVERSE) {
|
|
305 |
$line .= " " . ESurfaceTypes::getTypeAbbrevForExport($type);
|
|
306 |
}
|
|
307 |
fwrite($exportFile, $line . "\n");
|
|
308 |
}
|
|
309 |
}
|
|
310 |
}
|
|
311 |
}
|
|
312 |
fwrite($exportFile, "\n");
|
|
313 |
}
|
|
314 |
|
|
315 |
fclose($exportFile);
|
|
316 |
header("Content-type: text/plain");
|
|
317 |
header("Content-disposition: attachment; filename = " . $exportFileName);
|
|
318 |
readfile(self::EXPORT_FILE_PATH . $exportFileName);
|
|
319 |
die();
|
|
320 |
}
|
|
321 |
catch (\Exception $e)
|
|
322 |
{
|
|
323 |
$this->presenter->flashMessage('There was an error creating the export file', EFlashMessage::ERROR);
|
|
324 |
}
|
|
325 |
|
|
326 |
$this->presenter->flashMessage('There was an error downloading the export file', EFlashMessage::ERROR);
|
|
327 |
}
|
224 |
328 |
}
|
225 |
329 |
|
226 |
330 |
interface ITransliterationGridFactory
|
Re #7511 Export vyfiltrovaných textů v gridu