survos/grid-group-bundle

Handle groups of CSV as a spreadsheet

Fund package maintenance!
kbond

Installs: 1 763

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.5.378 2024-07-06 14:55 UTC

This package is auto-updated.

Last update: 2024-11-04 17:03:17 UTC


README

Under development! And will probably be replaced by Pixy/Pixie/KeyValue bundle, which uses Sqlite instead of csv. But some tools here could be helpful.

A bundle to manipulate a set of CSV files as a database. The idea is to avoid having to create temporary entities or models during the data import.

CsvParser

The CSV Reader class is an excellent way to read records from csv.

$csv = Reader::createFromPath('/path/to/file.csv', 'r');
$csv->setHeaderOffset(0);
$header_offset = $csv->getHeaderOffset(); //returns 0
$header = $csv->getHeader(); //returns ['First Name', 'Last Name', 'E-mail']

Example: create a simple related table.

Given a movie CSV table, create a CsvDatabase (GridGroup?)

id,title,poster,overview,release_date,genres
287947,Shazam!,https://image.tmdb.org/t/p/w500/xnopI5Xtky18MPhK40cZAGAOVeV.jpg,"A boy is given the ability to become an adult superhero in times of need with a single magic word.",1553299200,"Action, Comedy, Fantasy"
299537,"Captain Marvel",https://image.tmdb.org/t/p/w500/AtsgWhDnHTq68L0lLsUrCnM7TjG.jpg,"The story follows Carol Danvers as she becomes one of the universe’s most powerful heroes when Earth is caught in the middle of a galactic war between two alien races. Set in the 1990s, Captain Marvel is an all-new adventure from a previously unseen period in the history of the Marvel Cinematic Universe.",1551830400,"Action, Adventure, Science Fiction"

Create a movie.csv and genre.csv, with genre counts as an extra field

We need a schema to define the output csv database, which we can create by naming the fields.

$gridGroup = new GridGroup('movie_and_genre');
$grid = (new \Survos\GridGroupBundle\Model\Grid('movie'));
$grid->addRow()

Defining the schema