/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Nilai(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Nilai'])) { $valid = true; foreach ($_POST['Nilai'] as $i => $ii) { $model = new Nilai(); $model->attributes = $_POST['Nilai'][$i]; $model->kode_guru = $_POST['Nilai']['kode_guru']; $model->kode_mapel = $_POST['Nilai']['kode_mapel']; $valid = $model->validate() && $valid; $model->save(); } if ($valid || $model->save()) { $this->redirect(array('nilai/create')); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $bulan = date('m'); if ($bulan < 7) { $smt = 2; //jika th 2(1-6) maka tahun-1/tahun-2 2012/2013 $th_ajar = date('Y') - 1 . '/' . date('Y'); } elseif ($bulan < 13 && $bulan > 6) { $smt = 1; //jika th 1(7-12) maka tahun/tahun+1 2012/2013 $th_ajar = date('Y') . '/' . (date('Y') + 1); } //Action search dialog $model2 = new Penempatan('search'); $model2->unsetAttributes(); // clear any default values if (isset($_GET['Penempatan'])) { $model2->attributes = $_GET['Penempatan']; } //Action create $model = new Nilai(); if (isset($_POST['Nilai'])) { $kode_mapel = Yii::app()->db->createCommand("select kode_mapel from jadwal where kode_guru='" . Yii::app()->user->id . "';")->queryScalar(); $kurikulum = Yii::app()->db->createCommand("select kurikulum from jadwal where kode_guru='" . Yii::app()->user->id . "';")->queryScalar(); $kelas = Yii::app()->db->createCommand("select kelas from jadwal where kode_guru='" . Yii::app()->user->id . "';")->queryScalar(); $valid = true; try { if (isset($_GET['nis'])) { foreach ($_POST['Nilai'] as $i => $ii) { $model = new Nilai(); $model->attributes = $_POST['Nilai'][$i]; $model->nis = $_GET['nis']; $model->kode_mapel = $kode_mapel; $model->kode_guru = Yii::app()->user->id; $model->kurikulum = $kurikulum; $model->th_ajar = $th_ajar; $model->semester = $smt; if ($kelas != 6) { $model->un = 0; $model->uas = 0; } //$valid=$model->validate()&&$valid; $model->save(); } } else { foreach ($_POST['Nilai'] as $i => $ii) { $model = new Nilai(); $model->attributes = $_POST['Nilai'][$i]; $model->kode_mapel = $kode_mapel; $model->kode_guru = Yii::app()->user->id; $model->kurikulum = $kurikulum; $model->th_ajar = $th_ajar; $model->semester = $smt; if ($kelas != 6) { $model->un = 0; $model->uas = 0; } $valid = $model->validate() && $valid; $model->save(); } } if ($model->save() || $valid) { Yii::app()->user->setFlash('success', 'Nilai <strong>berhasil</strong> disimpan.'); //$this->redirect(array('admin')); $this->refresh(); } } catch (CDbException $e) { Yii::app()->user->setFlash('warning', '<strong>Beberapa nilai sudah tersimpan.</strong> Silahkan periksa kembali.'); $model->addError(null, "Beberapa nilai sudah tersimpan. Silahkan periksa kembali"); $this->refresh(); } } $this->render('create', array('model' => $model, 'model2' => $model2)); }