public static function getAllReportRowsByReportId($report_id = 0, $fileIds = array()) { $excelSheets = array(); $currentReport = self::where('report_id', $report_id)->first(); if ($currentReport && count($currentReport) > 0) { # get all files under this report $reportFiles = ReportFile::getReportFilesById($currentReport->report_id, $fileIds); # get all version and sheets under this report for ($i = 0; $i < count($reportFiles); $i++) { // get current version $currentFileVersion = ReportFileVersion::getCurrentVersion($reportFiles[$i]->file_id); $reportFiles[$i]->currentFileVersion = $currentFileVersion; // get all file versions $allFileVersion = ReportFileVersion::getAllVersion($reportFiles[$i]->file_id); $reportFiles[$i]->allFileVersion = $allFileVersion; // get sheets $reportSheets = ReportFileSheets::getSheetsByVersionId($currentFileVersion->version_id); $reportFiles[$i]->reportSheets = $reportSheets; //self::print_this($reportSheets, '$reportSheets'); foreach ($reportSheets as $sheet) { $currentDataTable = (array) json_decode($sheet->data_table); //self::print_this($currentDataTable, '$currentDataTable'); foreach ($currentDataTable as $row) { //self::print_this($row, '$row'); if (isset($row->A) && $row->A != '') { $excelSheets[$row->A] = (array) $row; } elseif (isset($row->B) && $row->B != '') { $excelSheets[$row->B] = (array) $row; } elseif (isset($row[0]) && $row[0] != '') { $excelSheets[$row[0]] = (array) $row; } elseif (isset($row[1]) && $row[1] != '') { $excelSheets[$row[1]] = (array) $row; } } } } //self::print_this($excelSheets, '$excelSheets'); } return $excelSheets; }
public function view_file_version($file_id, $version_id) { # get all files under this report $reportFiles = ReportFile::getReportFilesByFileId($file_id); # get all version and sheets under this report for ($i = 0; $i < count($reportFiles); $i++) { // get current version $currentFileVersion = ReportFileVersion::getCurrentVersion($file_id); $reportFiles[$i]->currentFileVersion = $currentFileVersion; // get all file versions $allFileVersion = ReportFileVersion::getAllVersion($reportFiles[$i]->file_id); $reportFiles[$i]->allFileVersion = $allFileVersion; // get sheets $reportSheets = ReportFileSheets::getSheetsByVersionId($currentFileVersion->version_id); $reportFiles[$i]->reportSheets = $reportSheets; } $data['current_file_version'] = str_replace(" ", "_", $currentFileVersion->created_at); $data['report_files'] = $reportFiles; return view($this->viewPath . 'view_file_version', $data); }
public function download($id = 0) { $currentReport = ConsolidatedReports::getById($id); $version = ConsolidatedReportsVersion::getById($id); # get table headers $originalReport = Reports::getReportById($currentReport->report_id); $reportFiles = ReportFile::getReportFilesById($originalReport->report_id); $reportColumns = array(); if (isset($reportFiles[0])) { $currentOriginalFile = $reportFiles[0]; $currentFileVersion = ReportFileVersion::getCurrentVersion($currentOriginalFile->file_id); // get sheets $reportColumns = ReportFileSheets::getFirstSheetByVersionId($currentFileVersion->version_id); $reportColumns = json_decode($reportColumns); $reportColumns = json_decode($reportColumns->data_table_columns); } # get table data $dataTable = json_decode($version->table_data); $report = ExcelExporter::formatFileArrays($dataTable); # combine headers and data $finalDataTable = array_merge($reportColumns, $report); # file name here $filename = "{$originalReport->incident_name} - Incident Number {$originalReport->incident_number}"; ExcelExporter::exportFileTest($finalDataTable, $filename); //$reformattedReport = }