/**
  * Updates an existing Stats model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     // @todo: user specific
     $deck_options_tmp = Deck::find()->all();
     foreach ($deck_options_tmp as $deck) {
         $deck_options[$deck['id']] = $deck['name'];
     }
     $deck_type_options_tmp = DeckTypes::find()->all();
     foreach ($deck_type_options_tmp as $deck_type) {
         $deck_type_options[$deck_type['id']] = $deck_type['name'];
     }
     $classes_options_tmp = Classes::find()->all();
     foreach ($classes_options_tmp as $class) {
         $classes_options[$class['id']] = $class['name'];
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'deck_options' => $deck_options, 'deck_type_options' => $deck_type_options, 'classes_options' => $classes_options]);
     }
 }
 protected function getParentDeckOptions($id = null)
 {
     // we need the current id because the child cannot be its parent
     if ($id) {
         $deck_options_tmp = Deck::find()->where(['!=', 'id', $id])->all();
     } else {
         $deck_options_tmp = Deck::find()->all();
     }
     $deck_options[] = 'No parent deck';
     foreach ($deck_options_tmp as $deck) {
         $deck_options[$deck['id']] = $deck['name'];
     }
     return $deck_options;
 }
 public function actionIndex()
 {
     $decks = Deck::find()->all();
     foreach ($decks as $deck) {
         foreach ($deck->cards as $card) {
             var_dump($card->name);
         }
     }
     exit;
     $endpoint = "https://omgvamp-hearthstone-v1.p.mashape.com/cards";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Mashape-Key: aIpC7Lq0bvmshWtxepdzWC7ywu85p13p5YcjsnMJjyZDCBCv03'));
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $endpoint);
     $result = curl_exec($ch);
     curl_close($ch);
     $arr = json_decode($result, true);
     //var_dump(count($arr)); exit();
     foreach ($arr as $set) {
         //echo $set.PHP_EOL;
         foreach ($set as $card) {
             if ($card['type'] == "Minion" || $card['type'] == "Spell" || $card['type'] == "Weapon") {
                 //var_dump($card); exit();
                 $mod_card = new Card();
                 $mod_card->name = $card['name'];
                 $mod_card->orig_id = $card['cardId'];
                 $mod_card->cardSet = $card['cardSet'];
                 $mod_card->type = $card['type'];
                 if (isset($card['faction'])) {
                     $mod_card->faction = $card['faction'];
                 }
                 if (isset($card['rarity'])) {
                     $mod_card->rarity = $card['rarity'];
                 }
                 if (isset($card['cost'])) {
                     $mod_card->cost = $card['cost'];
                 }
                 if (isset($card['attack'])) {
                     $mod_card->attack = $card['attack'];
                 }
                 if (isset($card['health'])) {
                     $mod_card->health = $card['health'];
                 }
                 if (isset($card['text'])) {
                     $mod_card->text = $card['text'];
                 }
                 if (isset($card['flavor'])) {
                     $mod_card->flavor = $card['flavor'];
                 }
                 if (isset($card['artist'])) {
                     $mod_card->artist = $card['artist'];
                 }
                 if (isset($card['collectible'])) {
                     $mod_card->collectible = $card['collectible'];
                 }
                 if (isset($card['elite'])) {
                     $mod_card->elite = $card['elite'];
                 }
                 $mod_card->img = $card['img'];
                 $mod_card->imgGold = $card['imgGold'];
                 $mod_card->locale = $card['locale'];
                 if ($mod_card->save()) {
                     echo "save successful" . PHP_EOL;
                 } else {
                     echo "Save failed" . PHP_EOL;
                     var_dump($mod_card->getErrors());
                 }
                 echo "Done: " . $card['name'] . PHP_EOL;
             }
         }
     }
 }