function getProductsThatFit($vehicle_object)
 {
     $select = new VF_Select($this->getReadAdapter());
     $select->from($this->getSchema()->mappingsTable())->whereLevelIdsEqual($vehicle_object->toValueArray());
     $result = $select->query()->fetchAll();
     $products = array();
     foreach ($result as $row) {
         $product = new Elite_Vaf_Model_Catalog_Product();
         $product->setId($row['entity_id']);
         array_push($products, $product);
     }
     return $products;
 }
Example #2
0
 function doGetFits($productId)
 {
     $select = new VF_Select($this->getReadAdapter());
     $select->from($this->getSchema()->mappingsTable())->joinAndSelectLevels()->where('entity_id=?', $productId);
     $result = $this->query($select);
     $fits = array();
     while ($row = $result->fetchObject()) {
         if ($row->universal) {
             continue;
         }
         $fits[] = $row;
     }
     return $fits;
 }
    /**
     * @param array conjunction of critera Ex: array('make'=>1'year'=>1)
     * @return array of Vehicle that meet the critera
     */
    function findByLevelIds($levelIds, $mode = false)
    {
        $levelsToSelect = array();
        foreach ($this->schema->getLevels() as $level) {
            if (self::EXACT_ONLY == $mode) {
                $value = 0;
            } else {
                $value = false;
            }
            $value = isset($levelIds[$level]) ? $levelIds[$level] : $value;
            $value = isset($levelIds[$level . '_id']) ? $levelIds[$level . '_id'] : $value;
            unset($levelIds[$level . '_id']);

            $levelIds[$level] = $value;
            if(self::INCLUDE_PARTIALS == $mode && !$levelIds[$level])
            {
                continue;
            }
            if (self::EXACT_ONLY == $mode && !$levelIds[$level]) {
                continue;
            }
            array_push($levelsToSelect, $level);
        }

        $select = new VF_Select($this->getReadAdapter());
        $select
            ->from('elite_' . $this->schema->id() . '_definition')
            ->addLevelTitles('elite_' . $this->schema->id() . '_definition', $levelsToSelect);

        foreach ($this->schema->getLevels() as $level) {
            $value = false;
            $value = isset($levelIds[$level]) ? $levelIds[$level] : $value;
            $value = isset($levelIds[$level . '_id']) ? $levelIds[$level . '_id'] : $value;
            if ($value != false) {
                $level = str_replace(' ', '_', $level);
                $select->where('`elite_' . $this->schema->id() . '_definition`.`' . $level . '_id` = ?', $value);
            }
        }

        if (self::INCLUDE_PARTIALS != $mode) {
            foreach ($this->schema->getLevels() as $level) {
                if (self::EXACT_ONLY != $mode || (isset($levelIds[$level]) && $levelIds[$level])) {
                    $level = str_replace(' ', '_', $level);
                    $select->where('elite_' . $this->schema->id() . '_definition.' . $level . '_id != 0');
                }
            }
        }
        $result = $this->query($select)->fetchAll(Zend_Db::FETCH_OBJ);

        $return = array();
        foreach ($result as $row) {
            foreach ($this->schema->getLevels() as $level) {
                if (self::EXACT_ONLY == $mode && (!in_array($level, $levelsToSelect)) && $row->{$level . '_id'}) {
                    foreach ($this->schema->getNextLevelsIncluding($level) as $level) {
                        $row->{$level . '_id'} = 0;
                        $row->{$level} = '';
                    }
                    $vehicle = new VF_Vehicle($this->schema, $row->id, $row);
                    return array($vehicle);
                }

                if ((!isset($levelIds[$level]) || !$levelIds[$level]) && $mode) {
                    $row->{$level . '_id'} = 0;
                    $row->{$level} = '';
                }
                if (isset($levelIds[$level]) && !$levelIds[$level] && $row->{$level . '_id'}) {
                    continue;
                }

                if ((!$mode || self::EXACT_ONLY == $mode) && (!isset($levelIds[$level]) || !$levelIds[$level]) && !$row->{$level . '_id'}) {
                    continue;
                }
            }

            $vehicle = new VF_Vehicle($this->schema, $row->id, $row);
            array_push($return, $vehicle);
        }
        return $return;
    }