Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Questions::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' => $this->id, 'yes' => $this->yes, 'no' => $this->no, 'sort' => $this->sort]);
     $query->andFilterWhere(['like', 'questions', $this->questions])->andFilterWhere(['like', 'vote', $this->vote]);
     return $dataProvider;
 }
 /**
  * Finds the Questions model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Questions the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Questions::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionAnswer($labelid = 1, $questionid = 1)
 {
     $session = Yii::$app->session;
     //获取问题及相关答案
     $question = Questions::find()->where(['labelid' => $labelid, 'questionid' => $questionid])->one();
     $answers = $question->answers;
     $answerform = new AnswerForm();
     if ($answerform->load(Yii::$app->request->post()) && $answerform->validate() && !empty($session['user'])) {
         //插入回答
         $answer = new Answers();
         $answer->labelid = $labelid;
         $answer->questionid = $questionid;
         $maxanswerid = Answers::find()->where(['labelid' => $labelid, 'questionid' => $questionid])->orderBy('answerid desc')->one();
         $maxanswerid = $maxanswerid['answerid'];
         if (empty($maxanswerid)) {
             $maxanswerid = 0;
         }
         $answer->answerid = $maxanswerid + 1;
         $answer->answerer = $session['username'];
         $answer->answer = $answerform->answer;
         $answer->save();
         return $this->redirect(Yii::$app->request->getUrl());
     }
     return $this->render('answer', ['answerform' => $answerform, 'question' => $question, 'answers' => $answers]);
 }
Beispiel #4
0
 public function getQuestion()
 {
     return $this->hasOne(Questions::classname(), ['questionid' => 'questionid']);
 }
Beispiel #5
0
 public function getQuestions()
 {
     $questions = $this->hasMany(Questions::classname(), ['labelid' => 'labelid'])->asArray();
     return $questions;
 }
Beispiel #6
0
 public function actionResult()
 {
     if (!Yii::$app->user->identity) {
         return $this->goHome();
     }
     \Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => '']);
     $this->getMetaTagsDefault();
     $questionsYes = Questions::find()->andWhere(['yes' => 1])->all();
     $questionsNo = Questions::find()->andWhere(['no' => 1])->all();
     $customYes = new Questions();
     $customYes->id = 1000001;
     $customYes->questions = 'Iншi';
     $customYes->yes = 1;
     $questionsYes[] = $customYes;
     $customNo = new Questions();
     $customNo->id = 1000002;
     $customNo->questions = 'Iншi';
     $customNo->no = 1;
     $questionsNo[] = $customNo;
     $result = Vote::getResult();
     return $this->render('result', ['questionsYes' => $questionsYes, 'questionsNo' => $questionsNo, 'result' => $result]);
 }
Beispiel #7
0
 public static function getResult()
 {
     $result = [];
     //get from db
     $votes = self::find()->all();
     $questions = Questions::find()->all();
     //add custom questions
     $customYes = new Questions();
     $customYes->id = 1000001;
     $customYes->questions = 'Iншi';
     $customYes->yes = 1;
     $customYes->no = 0;
     $questions[] = $customYes;
     $customNo = new Questions();
     $customNo->id = 1000002;
     $customNo->questions = 'Iншi';
     $customNo->no = 1;
     $customNo->yes = 0;
     $questions[] = $customNo;
     //total
     $result['yes']['count'] = Vote::find()->yesOnly()->count();
     $result['no']['count'] = Vote::find()->noOnly()->count();
     $result['yes']['count'] += Vote::find()->where(['questions_id' => 1000001])->count();
     $result['no']['count'] += Vote::find()->where(['questions_id' => 1000002])->count();
     // echo '<pre>';
     // var_dump($result);
     // echo '</pre>';
     // echo '<pre>';
     // var_dump($customYes);
     // echo '</pre>';
     //get total count
     foreach ($questions as $key => $value) {
         if (!empty($value->yes)) {
             $result['yes']['count'] += $value->vote;
         }
         if (!empty($value->no)) {
             $result['no']['count'] += $value->vote;
         }
     }
     //set total values
     $totalCount = $result['yes']['count'] + $result['no']['count'];
     $result['yes']['percent'] = round($result['yes']['count'] / $totalCount * 100);
     $result['no']['percent'] = round($result['no']['count'] / $totalCount * 100);
     //set percent
     //   \yii\helpers\VarDumper::dump($questions, 11, 1);
     foreach ($questions as $key => $value) {
         $result['questions'][$value->id] = ['count' => $value->vote, 'vote' => $value->vote];
         if (!empty($value->yes)) {
             // \yii\helpers\VarDumper::dump($result['questions'], 11, 1);
             $result['questions'][$value->id]['group'] = 'yes';
             $result['questions'][$value->id]['percent'] = round($result['questions'][$value->id]['count'] / $result['yes']['count'] * 100);
         }
         if (!empty($value->no)) {
             $result['questions'][$value->id]['group'] = 'no';
             $result['questions'][$value->id]['percent'] = round($result['questions'][$value->id]['count'] / $result['no']['count'] * 100);
         }
     }
     //         \yii\helpers\VarDumper::dump($result, 11, 1);
     // die();
     //add each vote to array
     foreach ($votes as $key => $vote) {
         if ('yes' == $result['questions'][$vote->questions_id]['group']) {
             $result['questions'][$vote->questions_id]['count'] = $result['questions'][$vote->questions_id]['count'] + 1;
             $result['questions'][$vote->questions_id]['percent'] = round($result['questions'][$vote->questions_id]['count'] / $result['yes']['count'] * 100);
         }
         if ('no' == $result['questions'][$vote->questions_id]['group']) {
             $result['questions'][$vote->questions_id]['count'] = $result['questions'][$vote->questions_id]['count'] + 1;
             $result['questions'][$vote->questions_id]['percent'] = round($result['questions'][$vote->questions_id]['count'] / $result['no']['count'] * 100);
         }
     }
     //set smile
     foreach ($questions as $key => $value) {
         $result['questions'][$value->id]['smile'] = 10 - round($result['questions'][$value->id]['percent'] / 10);
         if ($result['questions'][$value->id]['smile'] < 1) {
             $result['questions'][$value->id]['smile'] = 1;
         }
     }
     /*echo '<pre>';
             print_r($result);
     
             die();*/
     //  echo '<pre>';
     // var_dump($result);
     // echo '</pre>';
     // die();
     return $result;
 }
Beispiel #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getQuestions()
 {
     return $this->hasMany(Questions::className(), ['content_id' => 'id']);
 }
Beispiel #9
0
 public function verify($id = null)
 {
     $document = Documents::find('first', array('conditions' => array('hash' => $id)));
     if (count($document) == 0) {
         return $this->redirect('kyc::index');
         exit;
     }
     if ($document['verify']['verified'] == "Yes") {
         return $this->redirect('kyc::verified');
     }
     $image_passport_face = File::find('first', array('conditions' => array('details_passport_face_id' => (string) $document['_id'])));
     if ($image_passport_face['filename'] != "") {
         $imagename_passport_face = $image_passport_face['_id'] . '_' . $image_passport_face['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_passport_face;
         file_put_contents($path, $image_passport_face->file->getBytes());
     }
     $image_address = File::find('first', array('conditions' => array('details_address_id' => (string) $document['_id'])));
     if ($image_address['filename'] != "") {
         $imagename_address = $image_address['_id'] . '_' . $image_address['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_address;
         file_put_contents($path, $image_address->file->getBytes());
     }
     $image_passport = File::find('first', array('conditions' => array('details_passport_id' => (string) $document['_id'])));
     if ($image_passport['filename'] != "") {
         $imagename_passport = $image_passport['_id'] . '_' . $image_passport['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_passport;
         file_put_contents($path, $image_passport->file->getBytes());
     }
     $image_driving = File::find('first', array('conditions' => array('details_driving_id' => (string) $document['_id'])));
     if ($image_driving['filename'] != "") {
         $imagename_driving = $image_driving['_id'] . '_' . $image_driving['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_driving;
         file_put_contents($path, $image_driving->file->getBytes());
     }
     $image_tax = File::find('first', array('conditions' => array('details_tax_id' => (string) $document['_id'])));
     if ($image_tax['filename'] != "") {
         $imagename_tax = $image_tax['_id'] . '_' . $image_tax['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_tax;
         file_put_contents($path, $image_tax->file->getBytes());
     }
     $image_video = File::find('first', array('conditions' => array('details_video_id' => (string) $document['_id'])));
     if ($image_video['filename'] != "") {
         $imagename_video = $image_video['_id'] . '_' . $image_video['filename'];
         $path = LITHIUM_APP_PATH . '/webroot/documents/' . $imagename_video;
         file_put_contents($path, $image_video->file->getBytes());
     }
     $questions = Questions::find("first");
     if ($this->request->data) {
         $Score = 0;
         $groupPass = 0;
         $groupFace = 0;
         $Score = $Score + $this->request->data[Verify][Upload][Passport];
         $Score = $Score + $this->request->data[Verify][Upload][Driving];
         $Score = $Score + $this->request->data[Verify][Upload][Tax];
         $Score = $Score + $this->request->data[Verify][Upload][Address];
         $Score = $Score + $this->request->data[Verify][Upload][Face];
         $groupPass = $groupPass + $this->request->data[Verify][Name][Passport];
         $groupPass = $groupPass + $this->request->data[Verify][DOB][Passport];
         $groupPass = $groupPass + $this->request->data[Verify][DOB][Place];
         $groupPass = $groupPass + $this->request->data[Verify][Passport][Number];
         $groupPass = $groupPass + $this->request->data[Verify][Passport][Expiry];
         $groupPass = $groupPass + $this->request->data[Verify][Passport][Country];
         if ($groupPass == 30) {
             $Score = $Score + $groupPass;
         }
         //			$Score = $Score + $this->request->data[Verify][Name][Driving];
         $Score = $Score + $this->request->data[Verify][Name][Tax];
         $Score = $Score + $this->request->data[Verify][Name][Address];
         //			$Score = $Score + $this->request->data[Verify][Address][Driving];
         $Score = $Score + $this->request->data[Verify][Address][Tax];
         $Score = $Score + $this->request->data[Verify][Address][Address];
         //			$Score = $Score + $this->request->data[Verify][DOB][Driving];
         $Score = $Score + $this->request->data[Verify][DOB][Tax];
         //			$Score = $Score + $this->request->data[Verify][Driving][Number];
         //			$Score = $Score + $this->request->data[Verify][Driving][Country];
         $groupDriving = $groupDriving + $this->request->data[Verify][Name][Driving];
         //			print_r("Driving Name:". $groupDriving. "\n");
         $groupDriving = $groupDriving + $this->request->data[Verify][Address][Driving];
         //			print_r("Driving Address:". $groupDriving. "\n");
         $groupDriving = $groupDriving + $this->request->data[Verify][DOB][Driving];
         //			print_r("Driving DOB:". $groupDriving. "\n");
         $groupDriving = $groupDriving + $this->request->data[Verify][Driving][Number];
         //			print_r("Driving Number:". $groupDriving. "\n");
         $groupDriving = $groupDriving + $this->request->data[Verify][Driving][Country];
         //			print_r("Driving Country:". $groupDriving. "\n");
         //			print_r("GroupDriving:". $groupDriving. "\n");
         if ($groupDriving == 24) {
             $Score = $Score + $groupDriving + 5;
         }
         //print_r("Score:". $Score. "\n")			;
         $Score = $Score + $this->request->data[Verify][Tax][Number];
         $Score = $Score + $this->request->data[Verify][Tax][Country];
         $groupFace = $groupFace + $this->request->data[Verify][PassportFace][Passport];
         $groupFace = $groupFace + $this->request->data[Verify][PassportFace][Person];
         $groupFace = $groupFace + $this->request->data[Verify][PassportFace][PassportSame];
         $groupFace = $groupFace + $this->request->data[Verify][PassportFace][PersonSame];
         if ($groupFace == 30) {
             $Score = $Score + $groupFace;
         }
         //print_r("GroupFace:". $groupFace. "\n")			;
         //print_r("Score:". $Score. "\n")			;
         $data = array("Verify.Upload.Passport" => $this->request->data[Verify][Upload][Passport], "Verify.Upload.Driving" => $this->request->data[Verify][Upload][Driving], "Verify.Upload.Tax" => $this->request->data[Verify][Upload][Tax], "Verify.Upload.Address" => $this->request->data[Verify][Upload][Address], "Verify.Upload.Face" => $this->request->data[Verify][Upload][Face], "Verify.Name.Passport" => $this->request->data[Verify][Name][Passport], "Verify.Name.Driving" => $this->request->data[Verify][Name][Driving], "Verify.Name.Tax" => $this->request->data[Verify][Name][Tax], "Verify.Name.Address" => $this->request->data[Verify][Name][Address], "Verify.Address.Passport" => $this->request->data[Verify][Address][Passport], "Verify.Address.Driving" => $this->request->data[Verify][Address][Driving], "Verify.Address.Tax" => $this->request->data[Verify][Address][Tax], "Verify.Address.Address" => $this->request->data[Verify][Address][Address], "Verify.DOB.Passport" => $this->request->data[Verify][DOB][Passport], "Verify.DOB.Driving" => $this->request->data[Verify][DOB][Driving], "Verify.DOB.Tax" => $this->request->data[Verify][DOB][Tax], "Verify.DOB.Place" => $this->request->data[Verify][DOB][Place], "Verify.Passport.Number" => $this->request->data[Verify][Passport][Number], "Verify.Passport.Expiry" => $this->request->data[Verify][Passport][Expiry], "Verify.Passport.Country" => $this->request->data[Verify][Passport][Country], "Verify.Driving.Number" => $this->request->data[Verify][Driving][Number], "Verify.Driving.Country" => $this->request->data[Verify][Driving][Country], "Verify.Tax.Number" => $this->request->data[Verify][Tax][Number], "Verify.Tax.Country" => $this->request->data[Verify][Tax][Country], "Verify.PassportFace.Passport" => $this->request->data[Verify][PassportFace][Passport], "Verify.PassportFace.Person" => $this->request->data[Verify][PassportFace][Person], "Verify.PassportFace.PassportSame" => $this->request->data[Verify][PassportFace][PassportSame], "Verify.PassportFace.PersonSame" => $this->request->data[Verify][PassportFace][PersonSame], "Verify.DateTime" => new \MongoDate(), "Verify.Checked" => "Yes", "Verify.Score" => $Score, "Verify.Percent" => round($Score / 100 * 100, 0));
         $conditions = array('hash' => $id);
         $save = Documents::update($data, $conditions);
     }
     $document = Documents::find('first', array('conditions' => array('hash' => $id)));
     return compact('document', 'imagename_address', 'imagename_passport', 'imagename_driving', 'imagename_tax', 'imagename_passport_face', 'imagename_video', 'questions');
 }