Skip to content

Instantly share code, notes, and snippets.

@muskie9
Last active July 11, 2016 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muskie9/2ff6e80a8c8f5569d65d806491f90e04 to your computer and use it in GitHub Desktop.
Save muskie9/2ff6e80a8c8f5569d65d806491f90e04 to your computer and use it in GitHub Desktop.
<?php
public function getCMSFields() {
$fields = Parent::getCMSFields();
$fields->addFieldToTab('Root.Compare Vehicles', new TextField('Title'));
$fields->addFieldToTab('Root.Compare Vehicles', LabelField::create('Model 1'));
//ArrayList::create(Car::get()->toArray())->RemoveDuplicates('MakesName');
$map = Car::get()->map('ID', 'MakesNiceName')->toArray();
$makes = new DropdownField('MakesName', 'MakesName', $map);
$makes->setEmptyString('(Select Makes Name)');
$fields->addFieldToTab('Root.Compare Vehicles', $makes);
$datesSource = function($val) {
$v = Car::get()->filter(array('MakesNiceName'=>$val))->column('ModelName');
// return appropriate options array if the value is one.\
$map = array();
//$test = array();
foreach ($v as $name=>$val)
{
if(!in_array($val, $map)){
$map[] = $val->ModelName;
}
}
//$test = array_unique($map);
return $map;
};
$model = DependentDropdownField::create('FieldThree', 'ModelName', $datesSource)->setDepends($makes);
$fields->addFieldToTab('Root.Compare Vehicles', $model);
$yearSource = function($val) {
$va = Car::get()->filter(array('id'=>$val));
$modelname = array();
foreach ($va as $name=>$val)
{
$modelname[] = $val->ModelName;
}
$new = current($modelname);
$va = Car::get()->filter(array('ModelName'=>$new));
foreach ($va as $name=>$val)
{
$map[] = $val->Year;
}
//$test = array_unique($map);
return array_unique($map);
};
$year = DependentDropdownField::create('FieldTwo', 'Year', $yearSource)->setDepends($model);
$fields->addFieldToTab('Root.Compare Vehicles', $year);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment