예제 #1
0
 public function actionImport($path)
 {
     Yii::import('ext.phpexcelreader.JPhpExcelReader');
     $data = new JPhpExcelReader($path);
     for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
         $model = new InOutData();
         for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
             if ($j == 1) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->department = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->department = '';
                 }
             }
             if ($j == 2) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->nama = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->nama = '';
                 }
             }
             if ($j == 3) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->no = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->no = '';
                 }
             }
             if ($j == 4) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->date_time = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->date_time = '';
                 }
             }
             if ($j == 5) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->status = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->status = '';
                 }
             }
             if ($j == 6) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->location_id = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->location_id = '';
                 }
             }
             if ($j == 7) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->id_number = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->id_number = '';
                 }
             }
             if ($j == 8) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->verify_code = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->verify_code = '';
                 }
             }
             if ($j == 9) {
                 if (isset($data->sheets[0]['cells'][$i][$j])) {
                     $model->no_kartu = $data->sheets[0]['cells'][$i][$j];
                 } else {
                     $model->no_kartu = '';
                 }
             }
         }
         $model->save();
     }
     $this->redirect(array('inoutdata/admin'));
 }
예제 #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 = InOutData::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }