R
R
Roman2015-05-20 18:12:55
Yii
Roman, 2015-05-20 18:12:55

How to execute Mysql Function in ActiveDataProvider (Rest API)?

How can I use the Active Date provider to execute a custom function (MYSQL FUNCTION) that is in the database.
The function determines the nearest place by coordinators. And somehow I need to pull the data out of the database and substitute it into that function.
The function itself dist( lat,lon,latitude,longitude)<100
lat,lon - this will get the get parameter
latitude,longitude - this should be taken from the database
And I need to somehow implement it into my code.
So far, I don't even know how to approach this task.
Thank you.

class ClientsController extends ActiveController
{
    public $modelClass = 'api\modules\v1\models\Clients';

    public function actions()
    {
        $actions = parent::actions();
        // disable the "delete" and "create" actions
        unset($actions['create'],$actions['view'],$actions['delete'], $actions['update']);

        return array_merge(
            $actions,
            [
                'index' => [
                    'class' => 'yii\rest\IndexAction',
                    'modelClass' => $this->modelClass,
                    'checkAccess' => [$this, 'checkAccess'],
                    'prepareDataProvider' => function ($action) {
                        //---------------------------------
                        /* @var $model ClientsController */
                        $model = $action->modelClass;
                        $query = $model::find();
                        $dataProvider = new ActiveDataProvider(['query' => $query]);
                        $query->andFIlterWhere([
                            'country_id' => @$_GET['country_id'],
                            'state_id' => @$_GET['state_id'],
                            'city_id' => @$_GET['city_id'],
                        ]);
                        return $dataProvider;
                        //---------------------------------

                    }
                ]
            ]
        );
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
restyler, 2015-05-20
@restyler

$query->andWhere("dist(:lat,:lon, latitude,longitude)>100", [':lat' => $_GET['lan'], ':lon' => $_GET['lon']])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question