From fff33c76c887a6b3a310c2f997024e117c486bd8 Mon Sep 17 00:00:00 2001 From: Rap RIV Date: Fri, 26 Jun 2020 10:32:59 +0400 Subject: [PATCH] =?UTF-8?q?Form=20:=20am=C3=A9lioration=20validation=20for?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/answer/IndexAction.php | 5 +- controllers/answer/ValidateAction.php | 39 ++-------- models/Answer.php | 90 ++++++++++++++++-------- views/tpls/forms/cplx/validationForm.php | 7 +- views/tpls/forms/finish.php | 5 ++ views/tpls/forms/formWizard.php | 2 +- 6 files changed, 79 insertions(+), 69 deletions(-) create mode 100644 views/tpls/forms/finish.php diff --git a/controllers/answer/IndexAction.php b/controllers/answer/IndexAction.php index 982a0d7..16f85e3 100644 --- a/controllers/answer/IndexAction.php +++ b/controllers/answer/IndexAction.php @@ -40,7 +40,10 @@ class IndexAction extends CAction $canEditAnswer = false; $canSeeAnswer = false; - if(empty($mode) || ( $mode != "w" && $mode != "r" ) ) + + + if( empty($mode) || ( $mode != "w" && $mode != "r" ) || + ( !empty($answer["validated"]) && $answer["validated"] == true) ) $mode = "r"; if(!empty(Yii::app()->session['userId'])){ diff --git a/controllers/answer/ValidateAction.php b/controllers/answer/ValidateAction.php index 5c6c4e1..5e63719 100644 --- a/controllers/answer/ValidateAction.php +++ b/controllers/answer/ValidateAction.php @@ -1,39 +1,12 @@ getController(); + $params = $_POST; + $params["controller"] = $this->getController(); + $res = Answer::validate($params); + Rest::json($res); } } - - "organizations" : [ - { - "from" : "aressForm1.multitextvalidationaressForm110", - "to" : "name" - }, - { - "from" : "aressForm1.multitextvalidationaressForm111", - "to" : "sigle" - }, - { - "from" : "aressForm1.multitextvalidationaressForm112", - "to" : "siren" - }, - { - "from" : "aressForm1.multitextvalidationaressForm19", - "to" : "email" - }, - { - "from" : "aressForm1.multitextvalidationaressForm113", - "to" : "WALDEC_RNA -" - }, - { - "from" : "aressForm1.multitextvalidationaressForm113", - "to" : "siren" - } -] \ No newline at end of file diff --git a/models/Answer.php b/models/Answer.php index fae74ae..601d6d6 100644 --- a/models/Answer.php +++ b/models/Answer.php @@ -368,45 +368,73 @@ class Answer{ public static function validate($params){ $costum = CacheHelper::getCostum(); $set = array(); - - if(!empty($params["validated"]) && $params["validated"] === true) - $set["validated"] = true; + $res = array('result' => false, "msg" => "Erreur"); + if(!empty($params["answerId"])) + $answer = PHDB::findOneById(Answer::COLLECTION, $params["answerId"]); - if(!empty($params["input"]["generateElement"])){ - $mapping = array(); - $import = array( - 'file' => array(json_encode(array($params["answer"]))), - 'nameFile' => "test", - 'typeFile' => 'json', - "warnings" => "false" - ); - - foreach ($params["input"]["generateElement"] as $type => $map) { + if(!empty($answer)){ + if(!empty($params["input"]["validated"]) && ( $params["input"]["validated"] === true || $params["input"]["validated"] === "true" ) ) + $set["validated"] = true; + + if(!empty($params["input"]["generateElement"])){ $mapping = array(); - foreach ($map as $k => $v) { - $mapping[] =array( - 'idHeadCSV' => $v["from"], - 'valueAttributeElt' => $v["to"] - ); + $import = array( + 'file' => array(json_encode(array($params["answer"]))), + 'nameFile' => "test", + 'typeFile' => 'json', + "warnings" => "false" + ); + + foreach ($params["input"]["generateElement"] as $type => $map) { + $mapping = array(); + foreach ($map as $k => $v) { + $mapping[] =array( + 'idHeadCSV' => $v["from"], + 'valueAttributeElt' => $v["to"] + ); + } + $import['infoCreateData'] = $mapping; + $import['typeElement'] = $type; + //Rest::json($import); exit; + $resImport = Import::previewData($import, true, true, true); + //Rest::json($resImport); exit; + foreach ($resImport["elementsObj"] as $keyElt => $elt) { + $elt = Import::checkElement($elt, $type); + if(!empty($elt["msgError"])) + unset($elt["msgError"]); + $elt["collection"] = $type; + $elt["key"] = $type; + if(Costum::isSameFunction("generateElementBeforeSave")){ + $elt = Costum::sameFunction("generateElementBeforeSave", $elt); + } + $save = Element::save($elt); + //Rest::json($save); exit; + Link::connect($save["id"], $type, $params["answerId"], Answer::COLLECTION, Yii::app()->session["userId"], "answers",false,false,false,false); + Link::connect($params["answerId"], Answer::COLLECTION, $save["id"], $type, Yii::app()->session["userId"], $type,false,false,false,false); + + } + $res = array('result' => true, "msg" => "Valider"); + //Rest::json($resImport); exit; } - $import['infoCreateData'] = $mapping; - $import['typeElement'] = $type; - $resImport = Import::previewData($import, true, true, true); - Rest::json($resImport); exit; } - } - if(Costum::isSameFunction("answerValidate")){ - $paramBeforeValidate = Costum::sameFunction("answerValidate", $params); - } + if(Costum::isSameFunction("answerValidate")){ + $paramBeforeValidate = Costum::sameFunction("answerValidate", $params); + } + + if(!empty($set)){ + PHDB::update(Answer::COLLECTION, + array( "_id" => new MongoId((string)$params["answerId"])), + array( '$set' => $set ) ); - if(!empty($set)){ - PHDB::update(Answer::COLLECTION, - array( "_id" => new MongoId((string)$params["answerId"])), - array( '$set' => $set ) ); + $res = array('result' => true, "msg" => "Valider"); + } + - $res = array('result' => true, "msg" => "Valider"); + if($res["result"] === true){ + $res["html"] = $params["controller"]->renderPartial('survey.views.tpls.forms.finish', $res, true); + } } return $res; diff --git a/views/tpls/forms/cplx/validationForm.php b/views/tpls/forms/cplx/validationForm.php index dc42161..d17801d 100644 --- a/views/tpls/forms/cplx/validationForm.php +++ b/views/tpls/forms/cplx/validationForm.php @@ -1,7 +1,7 @@
@@ -17,7 +17,6 @@ if($mode != "pdf"){ $("#question #validation").off().click(function(){ var paramsValidate = { answerId : answerId, - answer : answerObj.answers, input : paramsInput }; @@ -26,7 +25,9 @@ if($mode != "pdf"){ baseUrl+"/survey/answer/validate", paramsValidate, function(data){ - toastr.success("Le formulaire à été soumis"); + toastr.success("Le formulaire à été soumis"); + if(typeof data.html != "undefined") + $("#customHeader").html(data.html); }, function(data){ toastr.error("Un soucis est apparue. Contacter l'administrateur"); diff --git a/views/tpls/forms/finish.php b/views/tpls/forms/finish.php new file mode 100644 index 0000000..1f6bb49 --- /dev/null +++ b/views/tpls/forms/finish.php @@ -0,0 +1,5 @@ +
+

Félicitation!!! Vous avez terminé le formulaire.

+
+

Celui-ci sera traité dans les plus bref délai.

+
\ No newline at end of file diff --git a/views/tpls/forms/formWizard.php b/views/tpls/forms/formWizard.php index fd35a89..27606ab 100644 --- a/views/tpls/forms/formWizard.php +++ b/views/tpls/forms/formWizard.php @@ -145,7 +145,7 @@ if(isset($this->costum["cms"]["color1"]))