Example #1
0
 /**
  * Manages all models.
  */
 public function actionAdmin()
 {
     $this->layout = '//layouts/column1';
     $model = new Penempatan('search');
     //Asli admin
     $model2 = new ThAjar();
     $model->unsetAttributes();
     // clear any default values Asli admin
     if (isset($_GET['Penempatan'])) {
         //Asli admin
         $model->attributes = $_GET['Penempatan'];
     }
     //Asli admin
     //Set validasi create th_ajar otomatis
     $tanggal1 = Yii::app()->db->createCommand("select th_ajar from th_ajar where th_ajar='" . date('Y') . '/' . (date('Y') + 1) . "';")->queryScalar();
     $tanggal2 = date('Y') . '/' . (date('Y') + 1);
     //$vari=array();
     //Penempatan oleh wali kelas
     if (isset($_POST['naik'])) {
         //Validasi dari set validasi (Create th_ajar otomatis)
         if ($tanggal1 != $tanggal2) {
             $model2 = new ThAjar();
             $model2->th_ajar = date('Y') . '/' . (date('Y') + 1);
             $model2->save();
         }
         $valid = true;
         foreach ($_POST['naik'] as $a => $val) {
             $simpan = $this->loadModel($val);
             $model = new Penempatan();
             //Tinggal kelas
             if (isset($_POST['tomboltidaknaik'])) {
                 $model->nis = $simpan->nis;
                 $model->kelas = $simpan->kelas;
                 $model->lokal = $simpan->lokal;
                 $model->th_ajar = date('Y') . '/' . (date('Y') + 1);
                 $status = 0;
             } elseif (isset($_POST['tombolnaik'])) {
                 //Naik kelas
                 $model->nis = $simpan->nis;
                 $model->kelas = $simpan->kelas + 1;
                 $model->lokal = $simpan->lokal;
                 $model->th_ajar = date('Y') . '/' . (date('Y') + 1);
                 $status = 1;
             }
             $valid = $model->validate() && $valid;
             $model->save();
         }
         if ($valid || $model->save()) {
             if ($status == 1) {
                 Yii::app()->user->setFlash('success', 'Proses kenaikan kelas <strong>berhasil!</strong>. Terima kasih');
             } else {
                 Yii::app()->user->setFlash('info', 'Proses tinggal kelas <strong>berhasil!</strong>. Terima kasih');
             }
             $this->refresh();
             //$this->redirect(array('admin'));
         }
     } elseif (isset($_POST['kelas1']) && isset($_POST['tombol1']) || isset($_POST['kelas2']) && isset($_POST['tombol2']) || isset($_POST['kelas3']) && isset($_POST['tombol3']) || isset($_POST['kelas4']) && isset($_POST['tombol4']) || isset($_POST['kelas5']) && isset($_POST['tombol5']) || isset($_POST['kelas6']) && isset($_POST['tombol6'])) {
         //Validasi dari set validasi (Create th_ajar otomatis)
         if ($tanggal1 != $tanggal2) {
             $model2 = new ThAjar();
             $model2->th_ajar = date('Y') . '/' . (date('Y') + 1);
             $model2->save();
         }
         $valid = true;
         $input = array("A", "B", "C");
         if (isset($_POST['tombol1'])) {
             $kelas = $_POST['kelas1'];
             $notif = 1;
         } elseif (isset($_POST['tombol2'])) {
             $kelas = $_POST['kelas2'];
             $notif = 2;
         } elseif (isset($_POST['tombol3'])) {
             $kelas = $_POST['kelas3'];
             $notif = 3;
         } elseif (isset($_POST['tombol4'])) {
             $kelas = $_POST['kelas4'];
             $notif = 4;
         } elseif (isset($_POST['tombol5'])) {
             $kelas = $_POST['kelas5'];
             $notif = 5;
         } elseif (isset($_POST['tombol6'])) {
             $kelas = $_POST['kelas6'];
             $notif = 6;
         }
         foreach ($kelas as $a => $val) {
             $simpan = $this->loadModel($val);
             $model = $this->loadModel($val);
             $model->nis = $simpan->nis;
             $model->kelas = $simpan->kelas;
             $random = shuffle($input);
             $model->lokal = $input[0];
             $model->th_ajar = date('Y') . '/' . (date('Y') + 1);
             $valid = $model->validate() && $valid;
             $model->save();
         }
         if ($valid || $model->save()) {
             Yii::app()->user->setFlash('success', 'Proses random kelas ' . $notif . ' <strong>berhasil!</strong>. Terima kasih');
             $this->refresh();
             //$this->redirect(array('admin'));
         }
         /*$i=0;
         		 $j=0;
         		
         		$number=array('A','B','C');
         		shuffle($number);
         		$kurang=count($_POST['kelas1']);
         		while($i<=$kurang)
         		{
         			
         		$model->lokal=$number[$j];
         			
         		if (($j+1) % 3 == 0) {
         		shuffle($number);
         		$j=-1;
         		}
         			
         		$i++;
         		$j++;
         		}*/
         //var_dump($model->lokal);
         //die();
     }
     $this->render('admin', array('model' => $model, 'model2' => $model2));
 }
Example #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ThAjar::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }