Beispiel #1
0
 /**
  * Creates a new Docmedal model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Docmedal();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->mdl_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
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));
             }
         }
     }
 }