3372 Posts in 998 Topics by 712 members
|Go to End|
22 February 2010 at 1:24am Last edited: 22 February 2010 1:37am
Is there a way to automatically load up a data store (a datamodel table) with information when it is created? I require a country-selection field and figured it would be good idea to put it into a separate module for reuse. The countries would be stored in the database, and so it would be ideal for the table to be pre-populated as soon as the module is installed.
The country data will be in XML files initially, to make it easier to handle international characters.
Unless, of course, such a module already exists?
Edit: of course, an ideal module would contain an arbitrary number of nested and linked regions of any arbitrary type, for use in different ways. For example, to be able to define the UK, its countries, then its regions, then its counties (of which there are several sets, depending on how you define "county"), and its postal code areas (overlapping and not fully enclosed within counties) etc. would be tremendously useful. That would also link to GIS outline shapes, yet another level of usefulness. That is probably a step further than I need to go now, especially being a newbie to SS.
22 February 2010 at 8:36am
If you add the method requireDefaultRecords() to your model class, it will be called when the database is built, after the tables have been created.
I.e. you could write a script that loads data from an XML file when your database is created. Note that Sapphire comes with Spyc for reading YAML documents - this could be a good way to load up a simple dataset like regions.
Incidentally, I've already done something similar to your arbitrary linked regions system for a project. Using the http://doc.silverstripe.org/doku.php?id=hierarchy extension it's quite easy to implement. We haven't gone quite as far as added a GIS layer over the top (partly because the regions were not always strictly geographic), but it's quite achievable.
22 February 2010 at 8:58am
The GIS layer I was thinking of probably doesn't involve much more than a large text field to hold CSV polygon data for the outlines (more likely multiple polygons, so broken areas and holes in areas can be drawn). I've done something similar in another project, with the polygon data being pulled out and converted into Google Maps polygon layers with roll-overs. There was no need to split the individual points out into separate data items, so storing it is very easy.
I'll have a look at YAML. It's a term I've seen a lot, but never really explored it.
|Go to Top|