Ejemplo n.º 1
0
 public function actionFindByAgent($agent = null, $id = null)
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $out = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($agent)) {
         $data = Player::find()->byAgent($agent)->all();
         $out['results'] = array_map(function ($item) {
             /**
              * @var $item Player
              */
             return ['id' => $item->id, 'text' => $item->agentId];
         }, $data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Player::findOne($id)->agentId];
     }
     return $out;
 }