Design Guide - Find/List Vehicles

Preface

A 'level' is a part of a vehicle. 'Honda' is a "level" whereas 'Honda Civic 2002' is a complete vehicle. You may list all values for a level using the below snippet.

The 'level' class

The level class is Elite_Vaf_Model_Level. This class encapsulates data & behavior for a vehicle part. When you have a level, you can query for it's ID, title, or call it's __toString() magic method. See example 1.

The 'vehicle' class

The level class is Elite_Vaf_Model_Vehicle. This class encapsulates data & behavior for a complete vehicle, including it's level parts. When you have a vehicle, you can query for an associative array of level IDs, associative array of titles (keyed by level name), or query for a particular level object. See examples 3-7.

Example 1 - Listing all models

$model = new Elite_Vaf_Model_Level('model');
$actual = $model->listAll();

foreach($actual as $eachModel)
{
    echo $eachModel->getId() . '-' . $eachModel->getTitle();
}
    
Example 2 - Listing all models that are in use.*'In use' refers to the model being utilized in a fitment for at least one product

$model = new Elite_Vaf_Model_Level('model');
$actual = $model->listInUse();

foreach($actual as $eachModel)
{
    echo $eachModel->getId() . '-' . $eachModel->getTitle();
}
    

Using the 'vehicle finder' you may list vehicles. You may find them by ID, or by title. Simply instantiate the vehicle finder, then you can search for vehicles by the ID(s) of it's component 'levels' or by the titles of them. Pass an associative array where the keys are the level names, and the values are the IDs/Titles. When searching by ID "make_id" may optionally be used instead of "make" for the array keys.

Example 3 - Listing all vehicles for make ID #5

$schema = new Elite_Vaf_Model_Schema;
$finder = new Elite_Vaf_Model_Vehicle_Finder( $schema );
$vehicles = $finder->findByLevelIds(array('make_id'=>5));

foreach($vehicles as $vehicle)
{
    echo $vehicle;
    print_r($vehicle->toValueArray());
    print_r($vehicle->toTitleArray());
    // echo 'make Id is ' . $vehicle->getLevel('make)->getId() . ' which corresponds to  ' . $vehicle->getLevel('make')->getTitle();
}
    
Example 4 - Listing all vehicles for make matching "Honda"

$schema = new Elite_Vaf_Model_Schema;
$finder = new Elite_Vaf_Model_Vehicle_Finder( $schema );
$vehicles = $finder->findByLevels(array('make'=>'Honda'));

foreach($vehicles as $vehicle)
{
    echo $vehicle;
    print_r($vehicle->toValueArray());
    print_r($vehicle->toTitleArray());
    // echo 'make Id is ' . $vehicle->getLevel('make)->getId() . ' which corresponds to  ' . $vehicle->getLevel('make')->getTitle();
}
    
Example 5 - Listing all vehicles for make matching "Honda" and manufactured in 2005

$schema = new Elite_Vaf_Model_Schema;
$finder = new Elite_Vaf_Model_Vehicle_Finder( $schema );
$vehicles = $finder->findByLevels(array('make'=>'Honda', 'year'=>2005 ));

foreach($vehicles as $vehicle)
{
    echo $vehicle;
    print_r($vehicle->toValueArray());
    print_r($vehicle->toTitleArray());
    // echo 'make Id is ' . $vehicle->getLevel('make)->getId() . ' which corresponds to  ' . $vehicle->getLevel('make')->getTitle();
}
    
Example 6 - Find an exact [one] vehicle by titles.

$schema = new Elite_Vaf_Model_Schema;
$finder = new Elite_Vaf_Model_Vehicle_Finder( $schema );
$vehicle = $finder->findOneByLevels(array('make'=>'Honda', 'model'=>'Civic', 'year'=>2005 ));

echo $vehicle;
print_r($vehicle->toValueArray());
print_r($vehicle->toTitleArray());
// echo 'make Id is ' . $vehicle->getLevel('make)->getId() . ' which corresponds to  ' . $vehicle->getLevel('make')->getTitle();

    
Example 7 - Find an exact [one] vehicle by ID.

$schema = new Elite_Vaf_Model_Schema;
$finder = new Elite_Vaf_Model_Vehicle_Finder( $schema );
$vehicle = $finder->findOneByLevelIds(array('make'=>5, 'model'=>3, 'year'=>8 ));

echo $vehicle;
print_r($vehicle->toValueArray());
print_r($vehicle->toTitleArray());
// echo 'make Id is ' . $vehicle->getLevel('make)->getId() . ' which corresponds to  ' . $vehicle->getLevel('make')->getTitle();

    
Example 8 - Find unique models that fit a particular make & year

$model = new Elite_Vaf_Model_Level('model');
$models = $model->listAll(array('year'=>1, 'make'=>5));