Overview
Comment:Fix issues in user export when list is empty, and fix CSV export when iterator is empty
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 586553935df83ae709b311171dc61fb3c80ea390
User & Date: bohwaz on 2020-12-05 11:14:48
Other Links: branch diff | manifest | tags
Context
2020-12-05
11:20
Fix error message when trying to add a duplicate service for user check-in: 787bae113c user: bohwaz tags: dev
11:14
Fix issues in user export when list is empty, and fix CSV export when iterator is empty check-in: 586553935d user: bohwaz tags: dev
10:44
Fix clickable row in tables that are not lists check-in: 5467e536da user: bohwaz tags: dev, 1.0.0-rc6
Changes

Modified src/include/lib/Garradin/CSV.php from [0895323879] to [b79b34dab0].

146
147
148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
	static public function toCSV(string $name, iterable $iterator, ?array $header = null, ?callable $row_map_callback = null): void
	{
		header('Content-type: application/csv');
		header(sprintf('Content-Disposition: attachment; filename="%s.csv"', $name));

		$fp = fopen('php://output', 'w');

		if ($header)
		{
			fputs($fp, self::row($header));
		}


		foreach ($iterator as $row)
		{
			foreach ($row as $key => &$v) {
				if (is_object($v)&& $v instanceof \DateTimeInterface) {
					$v = $v->format('d/m/Y');
				}
			}

			$row = self::rowToArray($row, $row_map_callback);

			if (!$header)
			{
				fputs($fp, self::row(array_keys($row)));
				$header = true;
			}

			fputs($fp, self::row($row));

		}

		fclose($fp);
	}

	static public function toODS(string $name, iterable $iterator, ?array $header = null, ?callable $row_map_callback = null): void
	{
		header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
		header(sprintf('Content-Disposition: attachment; filename="%s.ods"', $name));

		$ods = new ODSWriter;
		$ods->table_name = $name;

		if ($header)
		{
			$ods->add((array) $header);
		}


		foreach ($iterator as $row)
		{
			$row = self::rowToArray($row, $row_map_callback);

			if (!$header)
			{
				$ods->add(array_keys($row));
				$header = true;
			}

			$ods->add((array) $row);

		}

		$ods->output();
	}

	static public function importUpload(array $file, array $expected_columns): \Generator
	{







|
<



>
|
<
|
|
|
|
|

|

|
|
|
|
|

|
>













|
<



>
|
<
|

|
|
|
|
|

|
>







146
147
148
149
150
151
152
153

154
155
156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
	static public function toCSV(string $name, iterable $iterator, ?array $header = null, ?callable $row_map_callback = null): void
	{
		header('Content-type: application/csv');
		header(sprintf('Content-Disposition: attachment; filename="%s.csv"', $name));

		$fp = fopen('php://output', 'w');

		if ($header) {

			fputs($fp, self::row($header));
		}

		if ($iterator->valid()) {
			foreach ($iterator as $row) {

				foreach ($row as $key => &$v) {
					if (is_object($v)&& $v instanceof \DateTimeInterface) {
						$v = $v->format('d/m/Y');
					}
				}

				$row = self::rowToArray($row, $row_map_callback);

				if (!$header)
				{
					fputs($fp, self::row(array_keys($row)));
					$header = true;
				}

				fputs($fp, self::row($row));
			}
		}

		fclose($fp);
	}

	static public function toODS(string $name, iterable $iterator, ?array $header = null, ?callable $row_map_callback = null): void
	{
		header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
		header(sprintf('Content-Disposition: attachment; filename="%s.ods"', $name));

		$ods = new ODSWriter;
		$ods->table_name = $name;

		if ($header) {

			$ods->add((array) $header);
		}

		if ($iterator->valid()) {
			foreach ($iterator as $row) {

				$row = self::rowToArray($row, $row_map_callback);

				if (!$header)
				{
					$ods->add(array_keys($row));
					$header = true;
				}

				$ods->add((array) $row);
			}
		}

		$ods->output();
	}

	static public function importUpload(array $file, array $expected_columns): \Generator
	{

Modified src/include/lib/Garradin/Membres/Import.php from [0c863b55dc] to [99caaf5adf].

201
202
203
204
205
206
207
208
209
210








211
212
213
214


215
216
217
218
219
220
221

	protected function export(array $list = null)
	{
		$db = DB::getInstance();

		$champs = Config::getInstance()->get('champs_membres')->getKeys();
		$champs = array_map([$db, 'quoteIdentifier'], $champs);
		$champs_sql = 'm.' . implode(', m.', $champs);
		$where = $list ? 'WHERE ' . $db->where('m.id', $list) : '';









		$res = $db->iterate('SELECT ' . $champs_sql . ', c.nom AS "Cat├ęgorie membre" FROM membres AS m
			INNER JOIN membres_categories AS c ON m.id_categorie = c.id
			' . $where . '
			ORDER BY c.id;');



		return [
			array_keys((array) $res->current()),
			$res,
			sprintf('Export membres - %s - %s', Config::getInstance()->get('nom_asso'), date('Y-m-d')),
		];
	}







|
<

>
>
>
>
>
>
>
>
|

<
|
>
>







201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227
228
229

	protected function export(array $list = null)
	{
		$db = DB::getInstance();

		$champs = Config::getInstance()->get('champs_membres')->getKeys();
		$champs = array_map([$db, 'quoteIdentifier'], $champs);
		$fields = 'm.' . implode(', m.', $champs);


		if ($list) {
			$list = array_map('intval', $list);
			$where = sprintf('WHERE m.%s', $db->where('id', $list));
		}
		else {
			$where = '';
		}

		$sql = sprintf('SELECT %s, c.nom AS "Cat├ęgorie membre" FROM membres AS m
			INNER JOIN membres_categories AS c ON m.id_categorie = c.id

			%s ORDER BY c.id;', $fields, $where);

		$res = $db->iterate($sql);

		return [
			array_keys((array) $res->current()),
			$res,
			sprintf('Export membres - %s - %s', Config::getInstance()->get('nom_asso'), date('Y-m-d')),
		];
	}