/** * @param Exporter $exporter * * @return void */ public function handle(Exporter $exporter) { $params = $exporter->getParams(); $this->setProject($exporter->getParams('route.project')); $query = $this->project->issues()->select(array_keys($this->columns)); // Filter issues $this->project->filterTitleOrBody($query, $params['keyword']); $this->project->filterAssignTo($query, $params['keyword']); $this->project->filterTitleOrBody($query, $params['keyword']); // Fetch issues $this->issues = $query->get(); // Create CSV file $exporter->sheet($this->project->name, function (LaravelExcelWorksheet $sheet) { // Global sheet styles $this->globalStyle($sheet); // Title $sheet->mergeCells('A1:G1'); $sheet->setHeight(1, 50); $sheet->cell('A1', function (CellWriter $cell) { $this->sheetTitle($cell); }); // Header $sheet->row(2, array_map('trans', $this->header)); // Rows $index = 3; foreach ($this->issues as $issue) { $this->sheetRow($sheet, $index, $issue); ++$index; } }); }
/** * @param Exporter $exporter * * @return void */ public function handle(Exporter $exporter) { // Translate export columns $this->columns = array_combine(array_map('trans', array_keys($this->columns)), $this->columns); // Export parameters $params = $exporter->getParams(); /** @var Project $project */ $project = $params['route']['project']; // Query issues select specific columns $query = $project->issues()->select(array_filter($this->columns, function ($column) { return $column !== 'project'; })); // Filter issues $project->filterTags($query, $params['tags']); $project->filterAssignTo($query, $params['assignto']); $project->filterTitleOrBody($query, $params['keyword']); // Fetch issues $issues = $query->get()->map(function (Project\Issue $issue) use($project) { return array_map(function ($column) use($issue, $project) { if ($column == 'project') { return $project->name; } return (string) $issue->{$column}; }, $this->columns); }); // Create CSV file $exporter->sheet('issues', function (LaravelExcelWorksheet $sheet) use($issues) { $sheet->fromArray($issues); }); }
/** * Ajax: generate the issues export file * * @param Project $project * @param Exporter $exporter * @param Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function postExportIssues(Project $project, Exporter $exporter, Request $request) { // Generate export file $info = $exporter->exportFile('Project\\Issue', $request->input('format', Exporter::TYPE_CSV), $request->all()); // Download link $link = link_to($project->to('download_export/' . $info['file']), trans('tinyissue.download_export'), ['class' => 'btn btn-link']); return response()->json(['link' => $link, 'title' => $info['title'], 'file' => $info['file'], 'ext' => $info['ext']]); }