I have a list of Retailers and Distributors I want to output in the template sorted by continent, country and category
Below is the Data Object
class ProductSeller extends DataObject
{
static $db = array (
'SellerName' => 'Text',
'SellerDescription' => 'Text',
'SellerCategory' => "Enum('Retail, Distributor, Web')",
'SellerLocation' => 'Text',
'SellerContinent' => "Enum('NorthAmerica, SouthAmerica, Europe, Asia, Australia')",
'SellerURL' => 'Text',
'SellerPhone' => 'Text'
);
static $has_one = array (
'WhereToBuyPage' => 'WhereToBuyPage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('SellerName'),
new TextareaField('SellerDescription'),
new DropdownField('SellerCategory','SellerCategory', singleton('ProductSeller')->dbObject('SellerCategory')->enumValues()),
new CountryDropdownField('SellerLocation'),
new DropdownField('SellerContinent','Continent', singleton('ProductSeller')->dbObject('SellerContinent')->enumValues()),
new TextField('SellerURL'),
new TextField('SellerPhone')
);
}
}
In the template I can group the SellerContinent and SellerCategory by if statements, however is there an easy way to group the countries without manually making an if statements for every country.
I wrote a function thats sorts the Data by country so worse comes to worse I can use the country as a class and jQuery the whole thing and just give the JavaScript-less people a sorted list.
function sortByCountry(){
$countrys = DataObject::get("ProductSeller","", "SellerLocation");
return $countrys;
}
Thanks