backend\controllers\StoreController::actionNameFilter PHP Method

actionNameFilter() public method

public actionNameFilter ( $q = null, $id = null )
    public function actionNameFilter($q = null, $id = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $output = ['results' => ['id' => '', 'text' => '']];
        if (!is_null($q)) {
            $sql = 'SELECT t0.id, CONCAT(t1.name, \'-\', t0.name) AS text FROM ' . Store::tableName() . ' AS t0 LEFT JOIN ' . School::tableName() . ' AS t1 ON t0.school_id = t1.id WHERE t0.name LIKE :like ORDER BY t0.school_id ASC LIMIT 25';
            $output['results'] = Yii::$app->db->createCommand($sql, [':like' => "%{$q}%"])->queryAll();
        } elseif ($id > 0 && ($store = Store::findOne($id))) {
            $output['results'] = ['id' => $id, 'text' => $store->school->name . '-' . $store->name];
        }
        return $output;
    }