/** * Generate a spreadsheet by transforming 3D data into 2D data. * * @param array $filters (optional) * @return League\Csv\Writer */ public function generate(array $filters = []) { // Query the repository for filtered set of objects to export $objects = $this->query($filters); // Insert headers $this->data->insertOne($this->getHeaders()); // Add objects as rows if ($objects) { // Transform a 3D object into a 2D row $objects->transform([$this, 'transform']); // Insert all the objects as rows $this->data->insertAll($objects->toArray()); } return $this->data; }
echo 'Error: ' . $e->getMessage(); exit; } echo PHP_EOL; echo sprintf('%s open and %s closed issues pulled…', (string) count($issues['open']), (string) count($issues['closed'])); // Set up the header rows for the CSV $toWrite = [['url', 'number', 'title', 'status', 'assignee', 'milestone', 'created_at', 'updated_at', 'body']]; $prCount = 0; // Set up the data rows for the CSV foreach ($issues as $states) { foreach ($states as $issue) { // Strip out pull requests if (strpos($issue['html_url'], '/pull/')) { ++$prCount; continue; } $assignee = $issue['assignee'] == null ? '' : $issue['assignee']['login']; $milestone = $issue['milestone'] == null ? '' : $issue['milestone']['number'] . ': ' . $issue['milestone']['title']; $toWrite[] = [$issue['html_url'], $issue['number'], $issue['title'], $issue['state'], $assignee, $milestone, $issue['created_at'], $issue['updated_at'], $issue['body']]; } } echo PHP_EOL; echo sprintf('Stripping out %s pull requests…', (string) $prCount); echo PHP_EOL; echo 'Writing to CSV…'; // Write the array to the CSV file $writer = new Writer(sprintf('%s.csv', $repo->owner . '_' . $repo->name), 'ab+'); $writer->setNullHandlingMode(Writer::NULL_AS_EMPTY); $writer->insertAll($toWrite); echo PHP_EOL; echo sprintf('Done! CSV file is %s.csv', $repo->name);