Differences From Artifact [b0831a97ff]:

To Artifact [d27a94c923]:


1
2
3
4


5
6
7
8
9
10
11
<?php

namespace Garradin;



class CSV
{
	static public function readAsArray(string $path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);




>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

namespace Garradin;

use KD2\Office\Calc\Writer as ODSWriter;

class CSV
{
	static public function readAsArray(string $path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);
190
191
192
193
194
195
196
197
198
199
200
201
202





203
204
205
206
207
208
209
210

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

		$ods->output();
	}

	static public function import(array $file, array $expected_columns): \Generator
	{
		if (empty($file['size']) || empty($file['tmp_name'])) {
			throw new UserException('Fichier invalide');
		}






		$fp = fopen($file['tmp_name'], 'r');

		if (!$fp) {
			throw new UserException('Le fichier ne peut ĂȘtre ouvert');
		}

		// Find the delimiter
		$delim = self::findDelimiter($fp);







|





>
>
>
>
>
|







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

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

		$ods->output();
	}

	static public function importUpload(array $file, array $expected_columns): \Generator
	{
		if (empty($file['size']) || empty($file['tmp_name'])) {
			throw new UserException('Fichier invalide');
		}

		self::import($file['tmp_name']);
	}

	static public function import(string $file, array $expected_columns): \Generator
	{
		$fp = fopen($file, 'r');

		if (!$fp) {
			throw new UserException('Le fichier ne peut ĂȘtre ouvert');
		}

		// Find the delimiter
		$delim = self::findDelimiter($fp);