예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $ppk = new Ppk(Input::All());
     if ($ppk->save()) {
         return Response::json(array('success' => TRUE));
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Ppk();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Ppk'])) {
         $model->attributes = $_POST['Ppk'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id_ppk));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function importExcelToMysql($filePath, $fields = array(), $model = null, $startingRow = 2)
 {
     $objPHPExcel = PHPExcel_IOFactory::load($filePath);
     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
         //field validation
         $fieldValidate = array();
         $validated = FALSE;
         for ($col = 0; $col < count($fields); ++$col) {
             $val = $worksheet->getCellByColumnAndRow($fields[$col]['col'], 1)->getValue();
             $fieldValidate[$fields[$col]['name']] = $val;
         }
         if ($fieldValidate['code'] == 'Kode PPK' and $fieldValidate['ppk_name'] == 'Nama Kegiatan PPK' and $fieldValidate['official_name'] == 'Nama Pejabat PPK' and $fieldValidate['official_nip'] == 'NIP Pejabat PPK') {
             $validated = TRUE;
         }
         //end of validation
         $isSuccess = FALSE;
         if ($validated == TRUE) {
             $highestRow = $worksheet->getHighestRow();
             // e.g. 10
             for ($row = $startingRow; $row <= $highestRow; ++$row) {
                 $attributes = array();
                 for ($col = 0; $col < count($fields); ++$col) {
                     $val = $worksheet->getCellByColumnAndRow($fields[$col]['col'], $row)->getValue();
                     $attributes[$fields[$col]['name']] = $val;
                 }
                 if ($attributes['code'] != NULL && $attributes['ppk_name'] != NULL && $attributes['official_name'] != NULL && $attributes['official_nip'] != NULL) {
                     $code = $attributes['code'];
                     $recorded = Ppk::model()->find(array('condition' => "code='{$code}'"));
                     if ($recorded) {
                         $recorded->attributes = $attributes;
                         if ($recorded->update()) {
                             $isSuccess = TRUE;
                         }
                     } else {
                         $model = new Ppk();
                         $model->attributes = $attributes;
                         if ($model->save()) {
                             $isSuccess = TRUE;
                         }
                     }
                 }
             }
             if ($isSuccess) {
                 unlink($filePath);
                 Yii::app()->user->setFlash('success', "Data berhasil diimport.");
                 $this->redirect(array('index'));
             } else {
                 unlink($filePath);
                 Yii::app()->user->setFlash('error', "Mohon isikan data secara lengkap.");
             }
         } else {
             unlink($filePath);
             Yii::app()->user->setFlash('error', "Pastikan file yang Anda upload sudah benar!");
             $this->redirect(array('import'));
         }
     }
 }
예제 #4
0
 public function daftarPpkPost()
 {
     if (Request::ajax()) {
         $data = Input::all();
         $ppk = new Ppk();
         $ppk->nama = strtoupper($data['nama']);
         $ppk->noTel = $data['noTel'];
         $ppk->speedDial = $data['speedDial'];
         $ppk->noFaks = $data['noFaks'];
         $ppk->alamat = strtoupper($data['alamat']);
         if ($ppk->save()) {
             return 1;
         } else {
             return 0;
         }
     }
 }