function buildDistinctQueryForVehicleEntityIdMappings(Zend_Db_Select $select, VF_Vehicle $vehicle) { $subSelect = $this->getReadAdapter()->select(); foreach ($this->schema()->getLevels() as $current_level) { $level = $vehicle->getLevel($current_level); if (!$level->getId()) { continue; } $subSelect->where(sprintf("%s = ?", $current_level), $level->getTitle()); } $select = $this->combineSubSelectIfWhereIsNotEmpty($select, $subSelect); return $select; }