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)); }
/** * 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!')); } }
/** * Format row before validation * * @access public * @param array $row * @return array */ public function prepare(array $row) { $values = array(); $values['project_id'] = $this->projectId; $values['reference'] = $row['reference']; $values['title'] = $row['title']; $values['description'] = $row['description']; $values['is_active'] = Csv::getBooleanValue($row['is_active']) == 1 ? 0 : 1; $values['score'] = (int) $row['score']; $values['time_estimated'] = (double) $row['time_estimated']; $values['time_spent'] = (double) $row['time_spent']; if (!empty($row['assignee'])) { $values['owner_id'] = $this->user->getIdByUsername($row['assignee']); } if (!empty($row['creator'])) { $values['creator_id'] = $this->user->getIdByUsername($row['creator']); } if (!empty($row['color'])) { $values['color_id'] = $this->color->find($row['color']); } if (!empty($row['column'])) { $values['column_id'] = $this->board->getColumnIdByTitle($this->projectId, $row['column']); } if (!empty($row['category'])) { $values['category_id'] = $this->category->getIdByName($this->projectId, $row['category']); } if (!empty($row['swimlane'])) { $values['swimlane_id'] = $this->swimlane->getIdByName($this->projectId, $row['swimlane']); } if (!empty($row['date_due'])) { $values['date_due'] = $this->dateParser->getTimestampFromIsoFormat($row['date_due']); } $this->removeEmptyFields($values, array('owner_id', 'creator_id', 'color_id', 'column_id', 'category_id', 'swimlane_id', 'date_due')); return $values; }
protected function execute(InputInterface $input, OutputInterface $output) { $data = $this->subtaskExport->export($input->getArgument('project_id'), $input->getArgument('start_date'), $input->getArgument('end_date')); if (is_array($data)) { Csv::output($data); } }
protected function execute(InputInterface $input, OutputInterface $output) { $data = $this->projectDailyColumnStatsModel->getAggregatedMetrics($input->getArgument('project_id'), $input->getArgument('start_date'), $input->getArgument('end_date')); if (is_array($data)) { Csv::output($data); } }
/** * Send a CSV response * * @access public * @param array $data Data to serialize in csv * @param integer $status_code HTTP status code */ public function csv(array $data, $status_code = 200) { $this->status($status_code); $this->nocache(); header('Content-Type: text/csv'); Csv::output($data); exit; }
/** * 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')); }
/** * Format row before validation * * @access public * @param array $row * @return array */ public function prepare(array $row) { $row['username'] = strtolower($row['username']); foreach (array('is_admin', 'is_project_admin', 'is_ldap_user') as $field) { $row[$field] = Csv::getBooleanValue($row[$field]); } $this->removeEmptyFields($row, array('password', 'email', 'name')); return $row; }
/** * 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']))); }
public function testGetBooleanValue() { $this->assertEquals(1, Csv::getBooleanValue('1')); $this->assertEquals(1, Csv::getBooleanValue('True')); $this->assertEquals(1, Csv::getBooleanValue('t')); $this->assertEquals(1, Csv::getBooleanValue('TRUE')); $this->assertEquals(1, Csv::getBooleanValue('true')); $this->assertEquals(1, Csv::getBooleanValue('T')); $this->assertEquals(0, Csv::getBooleanValue('0')); $this->assertEquals(0, Csv::getBooleanValue('123')); $this->assertEquals(0, Csv::getBooleanValue('anything')); }
/** * Format row before validation * * @access public * @param array $row * @return array */ public function prepare(array $row) { $row['username'] = strtolower($row['username']); foreach (array('is_admin', 'is_manager', 'is_ldap_user') as $field) { $row[$field] = Csv::getBooleanValue($row[$field]); } if ($row['is_admin'] == 1) { $row['role'] = Role::APP_ADMIN; } elseif ($row['is_manager'] == 1) { $row['role'] = Role::APP_MANAGER; } else { $row['role'] = Role::APP_USER; } unset($row['is_admin']); unset($row['is_manager']); $this->removeEmptyFields($row, array('password', 'email', 'name')); return $row; }
/** * Send a CSV response * * @access public * @param array $data Data to serialize in csv */ public function csv(array $data) { $this->withoutCache(); $this->withContentType('text/csv; charset=utf-8'); $this->send(); Csv::output($data); }