Last active
July 11, 2016 23:26
-
-
Save muskie9/2ff6e80a8c8f5569d65d806491f90e04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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