private function typesAutocomplete($q) { $result = array(); $model = new shopTypeModel(); $value = $model->escape($q, 'like'); $table = $model->getTableName(); $sql = <<<SQL SELECT `icon`,`id`,`name`,`count` FROM {$table} WHERE `name` LIKE '%{$value}%' ORDER BY `count` DESC LIMIT 20 SQL; foreach ($model->query($sql)->fetchAll('id', true) as $id => $t) { $icon = shopHelper::getIcon($t['icon']); unset($t['icon']); $t['count'] = _w('%d product', '%d products', $t['count']); $result[] = array('id' => $id, 'value' => $id, 'name' => $t['name'], 'label' => $icon . implode('; ', array_filter($t))); } return $result; }