/**
  * @param int $characterID
  *
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionCreate($characterID)
 {
     Url::remember(Url::current(), self::REMEMBER_NAME);
     $character = $this->loadCharacter($characterID);
     $this->getView()->addBread(['label' => 'Demands', 'url' => ['demand/index', 'characterID' => $characterID]])->addBread(['label' => 'Create'])->setCharacter($character);
     $marketDemand = new MarketDemand();
     $marketDemand->characterID = $characterID;
     $marketDemand->userID = \Yii::$app->user->id;
     if ($this->isAjax()) {
         $type = $this->get('sType');
         if ($type == 'station') {
             $sql = '(SELECT sStation.stationID, sStation.stationName, sStation.stationTypeID FROM staStations as sStation WHERE sStation.stationName LIKE "%' . $_GET['q'] . '%")
                     UNION
                     (SELECT cStation.stationID, cStation.stationName, cStation.stationTypeID FROM api_eve_conquerableStation as cStation WHERE cStation.stationName LIKE "%' . $_GET['q'] . '%")';
         } elseif ($type == 'item') {
             $sql = 'SELECT typeID, typeName FROM invTypes WHERE typeName LIKE "%' . $_GET['q'] . '%" AND published ="1" ORDER BY typeName';
         }
         $return = \Yii::$app->db->createCommand($sql)->queryAll();
         echo Json::encode($return);
         // @todo change response type
         \Yii::$app->end();
     } elseif ($this->isPost() && $marketDemand->load($this->post())) {
         if ($marketDemand->save()) {
             UpdaterEveCentral::addType($marketDemand->typeID);
             return $this->redirect(['demand/list', 'characterID' => $characterID]);
         }
     }
     return $this->render('create', ['marketDemand' => $marketDemand]);
 }
 /**
  *
  */
 public function ruleUnique()
 {
     $model = MarketDemand::findOne(['typeID' => $this->typeID, 'stationID' => $this->stationID, 'userID' => $this->userID]);
     if ($model) {
         $this->addError('typeID', $this->invTypes->typeName . ' already added to list.');
     }
 }
 /**
  * @param int $demandID
  *
  * @return MarketDemand
  * @throws NotFoundHttpException
  */
 public function loadMarketDemand($demandID)
 {
     $model = MarketDemand::findOne(['id' => $demandID, 'userID' => \Yii::$app->user->id]);
     if (!$model) {
         throw new NotFoundHttpException('Such market demand does not exist.');
     }
     return $model;
 }