This is a very simplified/childish version of my data structure and code so I can better explain the problem.
Let's assume a a Dataobject
class Customers extends DataObject {
static $db = array(
'Name' => 'Text',
'Country' => 'Text'
);
In a template reports.ss , I would like to have a dropdown field (<select>) populated with all the "Country" existing
in the "Customers" dataObject. The trick is that I would like to ignore/delete the duplicates and ,if possible, to have
the list sorted.
My idea was to create a function (get_unique_country() )which returns a ObjectDataSet which I can use in a control block :
<% control get_unique_country %>
<option value=$Country>$country</option>
<% end_control %>
The problem is that I can't find a way to create a DataObject with no duplicate . However I found in the book (page 205-206) a
way to create an array containing unique values of countries :
I would have a function
function get_unique_country(){
$myentries = DataObject::get('Customers');
if(!$myentries) return array();
$countryList = array_unique($myentries->column('country'));
sort($countryList);
return $countryList;
}
The problem is that it returns an array not a DataObject . How can I use an array into a <% control %> block?
What is the best SS-way to achieve what I want?
Any hints would be very appreciated.
Thanks!
Lise