コード例 #1
0
 /**
  * API to access civil statistic data
  * @return
  */
 public function actionIndex()
 {
     $request = Yii::$app->request;
     $logger = new Logger();
     $user = new User();
     if ($request->isGet) {
         $accToken = !empty($_GET['access-token']) ? $_GET['access-token'] : '';
         $type = !empty($_GET['type']) ? $_GET['type'] : '';
         if (empty($accToken)) {
             throw new yii\web\UnauthorizedHttpException();
         }
         $accNIK = $user->findIdentityByAccessToken($accToken)->id;
         Logger::write($accNIK);
         if (empty($type)) {
             throw new yii\web\BadRequestHttpException();
         } else {
             switch ($type) {
                 case 'lokasi':
                     $data = $this->getStatbyLoc();
                     break;
                 case 'tahun':
                     $data = $this->getStatbyYear();
                     break;
                 default:
                     throw new yii\web\BadRequestHttpException();
                     break;
             }
             return ["name" => "success", 'status' => '200', 'message' => count($data) > 0 ? 'found' : 'not found', 'nik_responsible' => $accNIK, 'data' => $data];
         }
     } else {
         throw new yii\web\MethodNotAllowedHttpException();
     }
 }
コード例 #2
0
 /**
  * API to access data kartu keluarga
  * @return
  */
 public function actionIndex()
 {
     $request = Yii::$app->request;
     $logger = new Logger();
     $user = new User();
     if ($request->isPost) {
         $nik = !empty($_POST['nik']) ? $_POST['nik'] : '';
         $accToken = !empty($_POST['access-token']) ? $_POST['access-token'] : '';
     } elseif ($request->isGet) {
         $accToken = !empty($_GET['access-token']) ? $_GET['access-token'] : '';
         $noKK = !empty($_GET['no_kk']) ? $_GET['no_kk'] : '';
         $nik = !empty($_GET['nik']) ? $_GET['nik'] : '';
         if (empty($accToken)) {
             throw new yii\web\UnauthorizedHttpException();
             // throw new yii\web\BadRequestHttpException;
         } else {
             $accNIK = $user->findIdentityByAccessToken($accToken)->id;
             $data = null;
             Logger::write($accNIK);
             if (!empty($noKK) && empty($nik)) {
                 $data = $this->getKK($noKK);
             } elseif (empty($noKK) && !empty($nik)) {
                 $data = $this->getInfoKK($nik);
             } else {
                 throw new yii\web\BadRequestHttpException();
             }
             if (!empty($data)) {
                 return ["name" => "success", 'status' => '200', 'message' => 'found', 'nik_responsible' => $accNIK, 'data' => $data];
             } else {
                 throw new yii\web\NotAcceptableHttpException();
             }
         }
     } else {
         throw new yii\web\MethodNotAllowedHttpException();
     }
 }
コード例 #3
0
 /**
  * API to access civil data
  * @return
  */
 public function actionIndex()
 {
     $request = Yii::$app->request;
     $logger = new Logger();
     $user = new User();
     if ($request->isPost) {
         $nik = !empty($_POST['nik']) ? $_POST['nik'] : '';
         $accToken = !empty($_POST['access-token']) ? $_POST['access-token'] : '';
     } elseif ($request->isGet) {
         $nik = !empty($_GET['nik']) ? $_GET['nik'] : '';
         $field = isset($_GET['field']) ? $_GET['field'] : "nama-jenis_kelamin-tempat_lahir-tanggal_lahir";
         $search = !empty($_GET['search']) ? $_GET['search'] : '';
         $accToken = !empty($_GET['access-token']) ? $_GET['access-token'] : '';
         if (empty($accToken)) {
             throw new yii\web\UnauthorizedHttpException();
         }
         if (empty($nik)) {
             throw new yii\web\BadRequestHttpException();
         } else {
             $accNIK = User::findIdentityByAccessToken($accToken)->id;
             $data = $this->getPenduduk($nik, $field);
             Logger::write($accNIK);
             if (!empty($data)) {
                 return ["name" => "success", 'status' => '200', 'message' => 'found', 'nik_responsible' => $accNIK, 'data' => $data];
             } else {
                 throw new yii\web\NotAcceptableHttpException();
             }
         }
     } else {
         throw new yii\web\MethodNotAllowedHttpException();
     }
 }
コード例 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }