protected function rowResult()
 {
     $this->getReadAdapter()->getConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
     $select = $this->getReadAdapter()->select()->from('elite_mapping', array('id', 'universal'));
     foreach ($this->schema->getLevels() as $level) {
         $table = 'elite_level_' . $level;
         $condition = sprintf('%s.id = elite_mapping.%s_id', $table, $level);
         $select->joinLeft($table, $condition, array($level => 'title'));
     }
     $select->joinLeft(array('p' => $this->getProductTable()), 'p.entity_id = elite_mapping.entity_id', array('sku'));
     return $this->query($select);
 }
 function run()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_mapping` ADD INDEX ( `entity_id` ) ;');
     }
 }
 function run()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $db->query('ALTER TABLE `elite_level_' . str_replace(' ', '_', $level) . '` ADD INDEX ( `title` )   ');
     }
 }
 function setSortingLevels()
 {
     $schema = new Elite_Vaf_Model_Schema();
     foreach ($schema->getLevels() as $level) {
         if (isset($_GET[$level . 'Sorting'])) {
             $this->generator()->setSorting($level, $_GET[$level . 'Sorting']);
         }
     }
 }
 function run()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     foreach ($schema->getLevels() as $level) {
         $old = 'elite_' . $level;
         $new = 'elite_level_' . $level;
         $db->query(sprintf("RENAME TABLE %s TO %s", $old, $new));
     }
 }
 function levels()
 {
     $params = $this->getRequest()->getParam('vehicle');
     $params = explode("-", $params);
     $schema = new Elite_Vaf_Model_Schema();
     $levels = array();
     foreach ($schema->getLevels() as $level) {
         $levels[$level] = current($params);
         next($params);
     }
     return $levels;
 }
 function addUniqueOnMappings()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
     $levels = array();
     foreach ($schema->getLevels() as $level) {
         $levels[] = sprintf('`%s_id`', $level);
     }
     $levels[] = 'universal';
     $levels[] = 'entity_id';
     $levels = implode(',', $levels);
     $query = "ALTER TABLE `elite_mapping` ADD UNIQUE ( %s );";
     $db->query(sprintf($query, $levels));
 }
 protected function saveLeafLevels()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $select = $this->getReadAdapter()->select()->from('elite_' . $schema->getLeafLevel());
     $result = $select->query();
     $vehicleFinder = new Elite_Vaf_Model_Vehicle_Finder($schema);
     foreach ($result->fetchAll(Zend_Db::FETCH_OBJ) as $row) {
         $vehicle = $vehicleFinder->findByLeaf($row->id);
         $bind = array();
         foreach ($schema->getLevels() as $level) {
             $bind[$level . '_id'] = $vehicle->getLevel($level)->getId();
         }
         try {
             $this->getReadAdapter()->insert('elite_definition', $bind);
         } catch (Exception $e) {
         }
     }
 }
 function selectionPart()
 {
     $vehicle = Elite_Vaf_Helper_Data::getInstance()->getFit();
     if (!$vehicle) {
         return false;
     }
     if ($this->getConfig()->logo->level) {
         $level = $this->getConfig()->logo->level;
         return $vehicle->getLevel($level)->__toString();
     }
     $schema = new Elite_Vaf_Model_Schema();
     if (in_array('make', $schema->getLevels())) {
         $make = $vehicle->getLevel('make');
         if (!$make) {
             return false;
         }
         return $make->__toString();
     }
     $rootLevel = $schema->getRootLevel();
     return $vehicle->getLevel($rootLevel)->__toString();
 }
 function save()
 {
     if (!(int) $this->product_id) {
         throw new Exception('Trying to insert a mapping with no product ID');
     }
     $schema = new Elite_Vaf_Model_Schema();
     $schema->setConfig($this->getConfig());
     $levels = $schema->getLevels();
     $select = $this->getReadAdapter()->select()->from('elite_mapping', array('id'));
     foreach ($this->vehicle->toValueArray() as $level => $id) {
         $select->where($this->inflect($level) . '_id = ?', $id);
     }
     $select->where('entity_id = ?', $this->product_id);
     $id = (int) $select->query()->fetchColumn();
     if (0 !== $id) {
         return $id;
     }
     $columns = '';
     $values = '';
     foreach ($levels as $level) {
         $columns .= '`' . $this->inflect($level) . '_id`,';
         $values .= $this->inflect($this->vehicle->getLevel($level)->getId());
         $values .= ',';
     }
     $query = sprintf('
         INSERT INTO
             `elite_mapping`
         (
             ' . $columns . '
             `entity_id`
         )
         VALUES
         (
             ' . $values . '
             %d
         )
         ', (int) $this->product_id);
     $r = $this->query($query);
     return $this->getReadAdapter()->lastInsertId();
 }
 public static function getJoins()
 {
     $joins = '';
     $schema = new Elite_Vaf_Model_Schema();
     $levels = $schema->getLevels();
     $c = count($levels);
     for ($i = 0; $i <= $c - 1; $i++) {
         $joins .= sprintf('
             LEFT JOIN
                 `elite_%1$s`
             ON
                 `elite_%1$s`.`id` = `elite_mapping`.`%1$s_id`
             ', $levels[$i]);
     }
     return $joins;
 }
 /** @param Elite_Vaf_Model_Vehicle */
 private static function getValues($vehicle, Elite_Vaf_Model_Schema $schema)
 {
     $values = '';
     $levels = $schema->getLevels();
     $values = '';
     $c = count($levels);
     $i = 0;
     foreach ($levels as $level) {
         $i++;
         $values .= $vehicle->getLevel($level)->getId();
         if ($i < $c) {
             $values .= ',';
         }
     }
     return $values;
 }
 protected function getLevels()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $schema->setConfig($this->getConfig());
     return $schema->getLevels();
 }
<?php

$db = Elite_Vaf_Helper_Data::getInstance()->getReadAdapter();
$query = "CREATE TABLE `elite_schema` (\n`key` VARCHAR( 25 ) NOT NULL ,\n`value` VARCHAR( 255 ) NOT NULL\n) ENGINE = InnoDB;";
$db->query($query);
$schema = new Elite_Vaf_Model_Schema();
$levels = $schema->getLevels();
if (!count($levels)) {
    $levels = array('make', 'model', 'year');
}
foreach ($levels as $level) {
    if (!trim($level)) {
        $levels = array('make', 'model', 'year');
    }
}
$db->insert('elite_schema', array('key' => 'levels', 'value' => implode(',', $levels)));
Exemple #15
0
    function renderAvailable()
    {
        ob_start();
        ?>
        <?php 
        $schema = new Elite_Vaf_Model_Schema();
        $levels = $schema->getLevels();
        foreach ($levels as $level) {
            ?>
            <div class="multiTree-selectContainer" >
                <?php 
            echo ucfirst($this->htmlEscape($level));
            ?>
:<br />
                <?php 
            $metadata = "{level:'{$level}', parent:'" . $schema->getPrevLevel($level) . "', parents:'" . implode(',', $schema->getPrevLevels($level)) . "',  parents_including:'" . implode(',', $schema->getPrevLevelsIncluding($level)) . "' }";
            ?>
                <select class="multiTree-select <?php 
            echo $level;
            ?>
Select <?php 
            echo $metadata;
            ?>
" multiple="multiple">
                    <?php 
            if ($schema->getRootLevel() == $level) {
                foreach ($this->listEntities($schema->getRootLevel()) as $entity) {
                    ?>
                            <option value="<?php 
                    echo $entity->getId();
                    ?>
"><?php 
                    echo $entity->getTitle();
                    ?>
</option>
                            <?php 
                }
            }
            ?>
                </select>
                <br />
                Quick Add:
                <br />
                <input type="text" class="vafQuickAdd vafQuickAdd_<?php 
            echo $level;
            ?>
 {level:'<?php 
            echo $level;
            ?>
'}" name="vafQuickAdd_<?php 
            echo $level;
            ?>
" />
                <input type="button" class="vafQuickAddSubmit vafQuickAddSubmit_<?php 
            echo $level;
            ?>
 {level:'<?php 
            echo $level;
            ?>
'}" name="vafQuickAddSubmit_<?php 
            echo $level;
            ?>
" value="+" />
                <br />
                <span class="multiTree-levelName" style="display:none;"><?php 
            echo $level;
            ?>
</span>
            </div>
            <?php 
        }
        ?>
        <input class="multiTree-Add" type="button" value="Add +" />
        <?php 
        return ob_get_clean();
    }
 protected function getLevels()
 {
     return $this->schema->getLevels();
 }
 /** @todo move to importer model */
 protected function formatMessages()
 {
     $schema = new Elite_Vaf_Model_Schema();
     $this->formatMessage('<strong>Vehicles List Import Results</strong>');
     $this->formatMessage(number_format($this->importer->getCountAddedVehicles()) . ' Vehicles Added');
     foreach ($schema->getLevels() as $level) {
         $this->formatMessage(number_format($this->importer->getCountAddedByLevel($level)) . ' ' . $level . 's Added');
     }
     //        if( $this->importer->getCountSkippedDefinitions() > 0 )
     //        {
     //            $this->formatMessage( number_format( $this->importer->getCountSkippedDefinitions() ) . ' vehicles skipped because they already existed, your csv contained overlapping ranges or duplicate vehicles.' );
     //        }
     $this->doFormatMessages();
 }