Skip to content

Commit 30504ef

Browse files
committed
export download urls
1 parent 7acee10 commit 30504ef

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

controllers/Exports.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Martin\Forms\Controllers;
44

5-
use Response;
6-
use BackendMenu;
75
use SplTempFileObject;
86
use League\Csv\AbstractCsv;
97
use Backend\Classes\Controller;
108
use Martin\Forms\Models\Record;
9+
use Backend\Facades\BackendMenu;
1110
use League\Csv\Writer as CsvWriter;
1211

1312
class Exports extends Controller
@@ -53,7 +52,7 @@ public function csv()
5352
}
5453

5554
// FILTER DELETED
56-
if ($deleted = post('Record.options_deleted')) {
55+
if (post('Record.options_deleted')) {
5756
$records->withTrashed();
5857
}
5958

@@ -89,11 +88,14 @@ public function csv()
8988
$record = $filteredRecords->first();
9089
$headers = array_merge($headers, array_keys($record->form_data_arr));
9190

91+
// ADD FILES HEADER
92+
$headers[] = e(trans('martin.forms::lang.controllers.records.columns.files'));
93+
9294
// ADD HEADERS
9395
$csv->insertOne($headers);
9496

9597
// WRITE CSV LINES
96-
foreach ($records->get()->toArray() as $row) {
98+
foreach ($records->get() as $row) {
9799
$data = (array) json_decode($row['form_data']);
98100

99101
// IF DATA IS ARRAY CONVERT TO JSON STRING
@@ -108,6 +110,11 @@ public function csv()
108110
array_unshift($data, $row['id'], $row['group'], $row['ip'], $row['created_at']);
109111
}
110112

113+
// ADD ATTACHED FILES
114+
if (count($row->files) > 0) {
115+
$data[] = $row->filesList();
116+
}
117+
111118
$csv->insertOne($data);
112119
}
113120

models/Record.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Martin\Forms\Models;
44

5+
use Backend\Facades\Backend;
56
use Winter\Storm\Database\Model;
67

78
class Record extends Model
@@ -30,4 +31,11 @@ public function getGroupsOptions()
3031
{
3132
return $this->filterGroups();
3233
}
34+
35+
public function filesList()
36+
{
37+
return $this->files->map(function ($file) {
38+
return Backend::url('martin/forms/records/download', [$this->id, $file->id]);
39+
})->implode(',');
40+
}
3341
}

0 commit comments

Comments
 (0)