Overview
Comment:Fix: export user dates as french format
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: 67a32db6a41547d7b3d1fc5f8b6096d34d8cf9ab88ee160ffbfa1c431e4d2177
User & Date: bohwaz on 2021-05-22 12:19:25
Other Links: manifest | tags
Context
2021-05-22
14:07
Fix case fold when null check-in: dcde3b82ea user: bohwaz tags: trunk, stable
12:19
Fix: export user dates as french format check-in: 67a32db6a4 user: bohwaz tags: trunk, stable
11:21
Fix hover on even rows in selectors check-in: 89013f983a user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/CSV.php from [abd4bedd11] to [1989ff97c6].

152
153
154
155
156
157
158


159
160

161




162
163
164
165
166
167
168
169
170
171
172
173

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

		if (!($iterator instanceof \Iterator) || $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));







>
>


>
|
>
>
>
>



<
<







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

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

		if (!($iterator instanceof \Iterator) || $iterator->valid()) {
			foreach ($iterator as $row) {
				$row = self::rowToArray($row, $row_map_callback);

				foreach ($row as $key => &$v) {
					if (is_object($v) && $v instanceof \DateTimeInterface) {
						if ($v->format('His') == '000000') {
							$v = $v->format('d/m/Y');
						}
						else {
							$v = $v->format('d/m/Y H:i:s');
						}
					}
				}



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

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

Modified src/include/lib/Garradin/Membres/Import.php from [33ecedf27d] to [9fc2a43ba6].

8
9
10
11
12
13
14


15
16
17
18
19
20
21
...
238
239
240
241
242
243
244
245
246
247








248
249

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
use Garradin\Utils;
use Garradin\CSV;
use Garradin\CSV_Custom;
use Garradin\UserException;

class Import
{


	/**
	 * Importer un CSV générique
	 * @return boolean                   TRUE en cas de succès
	 */
	public function fromCustomCSV(CSV_Custom $csv, int $current_user_id)
	{
		$db = DB::getInstance();
................................................................................
	public function toODS(array $list = null): void
	{
		list($champs, $result, $name) = $this->export($list);
		CSV::toODS($name, $result, $champs, [$this, 'exportRow']);
	}

	public function exportRow(\stdClass $row) {
		// Pas hyper efficace, il faudrait ne pas récupérer la liste pour chaque ligne... FIXME
		$champs_multiples = Config::getInstance()->get('champs_membres')->getMultiples();









		// convertir les champs à choix multiple de binaire vers liste séparée par des points virgules
		foreach ($champs_multiples as $id=>$config) {

			$out = [];

			foreach ($config->options as $b => $name)
			{
				if ($row->$id & (0x01 << $b)) {
					$out[] = $name;
				}
			}

			$row->$id = implode(';', $out);

		}

		return $row;
	}
}







>
>







 







|
|
|
>
>
>
>
>
>
>
>
|
<
>
|

|
|
|
|
|
|

|
|





8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
use Garradin\Utils;
use Garradin\CSV;
use Garradin\CSV_Custom;
use Garradin\UserException;

class Import
{
	protected $champs;

	/**
	 * Importer un CSV générique
	 * @return boolean                   TRUE en cas de succès
	 */
	public function fromCustomCSV(CSV_Custom $csv, int $current_user_id)
	{
		$db = DB::getInstance();
................................................................................
	public function toODS(array $list = null): void
	{
		list($champs, $result, $name) = $this->export($list);
		CSV::toODS($name, $result, $champs, [$this, 'exportRow']);
	}

	public function exportRow(\stdClass $row) {
		if (null === $this->champs) {
			$this->champs = Config::getInstance()->get('champs_membres')->getAll();
		}

		foreach ($this->champs as $id => $config) {
			if ($config->type == 'date') {
				$row->$id = \DateTime::createFromFormat('!Y-m-d', $row->$id);
			}
			elseif ($config->type == 'datetime') {
				$row->$id = \DateTime::createFromFormat('!Y-m-d H:i:s', $row->$id);
			}
			// convertir les champs à choix multiple de binaire vers liste séparée par des points virgules

			elseif ($config->type == 'multiple') {
				$out = [];

				foreach ($config->options as $b => $name)
				{
					if ($row->$id & (0x01 << $b)) {
						$out[] = $name;
					}
				}

				$row->$id = implode(';', $out);
			}
		}

		return $row;
	}
}