Exemplo n.º 1
0
 public function testReadWrite()
 {
     $filename = tempnam(sys_get_temp_dir(), 'UT');
     $rows = array(array('Column A', 'Column B'), array('value a', 'value b'));
     $csv = new Csv();
     $csv->write($filename, $rows);
     $csv->setColumnMapping(array('A', 'B', 'C'));
     $csv->read($filename, array($this, 'readRow'));
     unlink($filename);
     $this->expectOutputString('"Column A","Column B"' . "\n" . '"value a","value b"' . "\n", $csv->output($rows));
 }
Exemplo n.º 2
0
 /**
  * Process file
  *
  * @param array $values
  * @param       $filename
  */
 private function importFile(array $values, $filename)
 {
     $csv = new Csv($values['delimiter'], $values['enclosure']);
     $csv->setColumnMapping($this->userImport->getColumnMapping());
     $csv->read($filename, array($this->userImport, 'import'));
     if ($this->userImport->counter > 0) {
         $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
     } else {
         $this->flash->failure(t('Nothing have been imported!'));
     }
 }
Exemplo n.º 3
0
 /**
  * Process CSV file
  *
  */
 public function step2()
 {
     $values = $this->request->getValues();
     $filename = $this->request->getFilePath('file');
     if (!file_exists($filename)) {
         $this->step1($values, array('file' => array(t('Unable to read your file'))));
     }
     $csv = new Csv($values['delimiter'], $values['enclosure']);
     $csv->setColumnMapping($this->userImport->getColumnMapping());
     $csv->read($filename, array($this->userImport, 'import'));
     if ($this->userImport->counter > 0) {
         $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
     } else {
         $this->flash->failure(t('Nothing have been imported!'));
     }
     $this->response->redirect($this->helper->url->to('userImport', 'step1'));
 }
Exemplo n.º 4
0
 /**
  * Process CSV file
  *
  */
 public function step2()
 {
     $project = $this->getProject();
     $values = $this->request->getValues();
     $filename = $this->request->getFilePath('file');
     if (!file_exists($filename)) {
         $this->step1($values, array('file' => array(t('Unable to read your file'))));
     }
     $this->taskImport->projectId = $project['id'];
     $csv = new Csv($values['delimiter'], $values['enclosure']);
     $csv->setColumnMapping($this->taskImport->getColumnMapping());
     $csv->read($filename, array($this->taskImport, 'import'));
     if ($this->taskImport->counter > 0) {
         $this->session->flash(t('%d task(s) have been imported successfully.', $this->taskImport->counter));
     } else {
         $this->session->flashError(t('Nothing have been imported!'));
     }
     $this->response->redirect($this->helper->url->to('taskImport', 'step1', array('project_id' => $project['id'])));
 }