private function featuresAutocomplete($q) { $result = array(); $model = new shopFeatureModel(); $value = $model->escape($q, 'like'); $table = $model->getTableName(); $options = (array) waRequest::get('options', array()); $where = array('1'); if (!empty($options['single'])) { $where[] = '`multiple`=0'; } $where = ' AND ((' . implode(') AND (', $where) . '))'; $sql = <<<SQL SELECT `id`,`name`,`code`,`type`,`count` FROM {$table} WHERE (`parent_id` IS NULL AND ( (`name` LIKE '%{$value}%') OR (`code` LIKE '%{$value}%') )){$where} ORDER BY `count` DESC LIMIT 20 SQL; foreach ($model->query($sql)->fetchAll('code', true) as $code => $f) { $f['type'] = shopFeatureModel::getTypeName($f); $f['count'] = _w('%d value', '%d values', $f['count']); $id = $f['id']; unset($f['id']); $result[] = array('id' => $id, 'value' => $code, 'name' => $f['name'], 'label' => implode('; ', array_filter($f))); } return $result; }