/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MatapelajaranGuru::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id_matapelajaran_guru' => $this->id_matapelajaran_guru, 'id_matapelajaran' => $this->id_matapelajaran, 'id_kelas' => $this->id_kelas]); $query->andFilterWhere(['like', 'nip', $this->nip])->andFilterWhere(['like', 'sub_kls1', $this->sub_kls1])->andFilterWhere(['like', 'sub_kls2', $this->sub_kls2])->andFilterWhere(['like', 'sub_kls3', $this->sub_kls3])->andFilterWhere(['like', 'sub_kls4', $this->sub_kls4])->andFilterWhere(['like', 'sub_kls5', $this->sub_kls5])->andFilterWhere(['like', 'sub_kls6', $this->sub_kls6]); return $dataProvider; }
/** * Creates a new Siswa model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Siswa(); $nilai = new Nilai(); $post = Yii::$app->request->post(); if ($model->load($post)) { $tgllahir = strtotime($post['Siswa']['thn'] . '-' . $post['Siswa']['bln'] . '-' . $post['Siswa']['tgl']); $model->tgl_lahir = date('Y-m-d', $tgllahir); $foto = UploadedFile::getInstance($model, 'foto'); if ($foto) { $ext = end(explode(".", $foto->name)); $extt = $foto->extension; $model->foto = Yii::$app->security->generateRandomString() . "." . $extt; } if ($model->save()) { if ($foto) { mkdir('uploads/foto_siswa', 0777, true); $foto->saveAs('uploads/foto_siswa/' . $model->foto); } $signUp = new \frontend\models\SignupForm(); $signUp->username = $model->email; $signUp->email = $model->email; $signUp->password = $model->password; $signUp->level = 'Siswa'; $mapel = MatapelajaranGuru::find()->all(); foreach ($mapel as $key => $value) { $nilai->nis = $model->nis; $nilai->id_matapelajaran = $value->id_matapelajaran_guru; $nilai->tahun_ajaran = $_POST['Nilai']['tahun_ajaran']; if ($nilai->save()) { $nilai = new Nilai(); } } if ($signUp->signup()) { Yii::$app->session->setFlash('success', 'Simpan Berhasil'); } else { Yii::$app->session->setFlash('warning', 'Simpan Gagal'); } return $this->redirect(['index']); } else { Yii::$app->session->setFlash('warning', 'Failed'); } } else { return $this->render('create', ['model' => $model, 'nilai' => $nilai]); } }
/** * @return \yii\db\ActiveQuery */ public function getMataPelajaran() { return $this->hasOne(MatapelajaranGuru::className(), ['id_matapelajaran_guru' => 'id_matapelajaran']); }
/** * @return \yii\db\ActiveQuery */ public function getMatapelajaranGurus() { return $this->hasMany(MatapelajaranGuru::className(), ['id_matapelajaran' => 'id_matapelajaran']); }
/** * Finds the MatapelajaranGuru model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MatapelajaranGuru the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MatapelajaranGuru::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }