Beispiel #1
0
 /**
  * @param $data
  */
 public function saveMedals($data)
 {
     //        $aModels = $this->persons;
     $aNeedDel = [];
     Docmedal::updateAll(['mdl_doc_id' => 0, 'mdl_competition' => '', 'mdl_title' => ''], ['mdl_doc_id' => $this->doc_id]);
     foreach ($data as $ob) {
         $ob['mdl_doc_id'] = $this->doc_id;
         Yii::info('medal = ' . print_r($ob, true));
         $s = 'Update ' . Docmedal::tableName() . ' Set ';
         $param = [];
         $sDelim = '';
         foreach ($ob as $k => $v) {
             $s .= $sDelim . $k . ' = ' . ':' . $k;
             $param[':' . $k] = $v;
             $sDelim = ', ';
         }
         $s .= ' Where mdl_doc_id = 0 Limit 1';
         //            Yii::info($s);
         $n = Yii::$app->db->createCommand($s, $param)->execute();
         if ($n == 0) {
             $oNew = new Docmedal();
             $oNew->attributes = $ob;
             if (!$oNew->save()) {
                 Yii::info('Error save Docmedal: ' . print_r($oNew->getErrors(), true));
             }
         }
     }
 }