Skip to content

Instantly share code, notes, and snippets.

@rickharris
Created October 26, 2011 21:00
Show Gist options
  • Save rickharris/1317829 to your computer and use it in GitHub Desktop.
Save rickharris/1317829 to your computer and use it in GitHub Desktop.
<?php
abstract class Controller_Parts extends Controller_Template {
/**
* @var Array Ordered list of steps in the form <step name> => <function to execute>
*/
protected $steps = array(
'make' => 'vcdb',
'year' => 'vcdb',
'model' => 'vcdb',
'submodel' => 'vcdb',
);
/**
* The main vehicle selector action. This should generall be the same for all
* implementing controllers. The particular steps can be overridden via
* $this->steps.
*/
public function action_index()
{
$params = Input::get('vehicle');
$completed_steps = array_keys($params);
$options = array();
$count = 0;
foreach ($this->steps as $step => $function)
{
// Even if the user has already selected this, we still need the
// option data to populate the select
$options[$step] = $this->{"step_{$function}"}($step, array_slice($params, 0, $count, true));
$count++;
// But stop at the first unknown
if ( ! in_array($step, $completed_steps))
{
break;
}
}
$data = compact('params', 'options');
$this->template->content = View::factory('parts/vehicle_selector.jade', $data);
}
/**
* Implementation for the 'make' step.
*/
protected function step_vcdb($step, $params)
{
return Model_Vehicle::distinct($step, $params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment