Commit 296b9805 authored by Raph El's avatar Raph El
Browse files

Hotfix survey after merge

parent 88460a79
......@@ -684,7 +684,6 @@ class Form {
$allforms = [];
if(isset($form) && !empty($form["subForms"]) ){
<<<<<<< HEAD
$params["formId"] = implode("|", $form["subForms"]);
//$params = self::getFormData($params);
......@@ -727,183 +726,6 @@ class Form {
$params["showForm"] = true;
}
}
=======
}
public static function getDataForAnswer($params){
//var_dump(Yii::app()->session['costum']);exit;
if(isset(Yii::app()->session["costum"]["contextType"]) && isset(Yii::app()->session["costum"]["contextId"]))
$params["el"] = Element::getByTypeAndId(Yii::app()->session["costum"]["contextType"], Yii::app()->session["costum"]["contextId"] );
if(isset(Yii::app()->session['costum']["hasOpenForm"])){
if(isset(Yii::app()->session['costum']["isMultiForms"])){
$answerId=null;
$answer=null;
$generateAnswer = false;
//var_dump($_GET['answer']); exit;
if(isset($_GET['answer']))
$answerId=$_GET['answer'];
else if(isset($params["answerId"]))
$answerId=$params["answerId"];
//var_dump($answerId);
if(!empty($answerId) && $answerId !="new")
$answer = self::getAnswerById($answerId);
//Rest::json($answer);exit;
if(!empty($answer)){
$params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"];
}else if(isset(Yii::app()->session["costum"]["form"])){
$params["formList"] = Yii::app()->session["costum"]["form"]["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
// <<<<<<< HEAD
// //when inputs are interdependant on other inputs
// $budgetInputList = [];
// $allforms = [];
// $stockBudgetInputs = false;
// //Rest::json(Yii::app()->session["costum"]["form"]); exit;
// foreach ($params["formList"] as $i => $formId)
// {
// $f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
// $allforms[$formId] = $f;
// foreach ($f["inputs"] as $key => $inp)
// {
// if( in_array($inp["type"], ["tpls.forms.cplx.budget"] ) )
// $budgetInputList[$formId.".".$key] = $formId.".".$key;
// if( in_array($inp["type"], [
// "tpls.forms.cplx.tpls.forms.cplx.financementFromBudget",
// "tpls.forms.cplx.tpls.forms.cplx.suiviFromBudget",
// "tpls.forms.cplx.tpls.forms.cplx.decideFromBudget"] ) )
// $stockBudgetInputs = true;
// }
// }
// if(count($budgetInputList))
// Yii::app()->session["budgetInputList"] = $budgetInputList;
// //use the cache
// Yii::app()->session["forms"] = $allforms;
// } else {
// =======
$params=self::getFormData($params);
} else {
//>>>>>>> qa
if(isset($_GET["form"]))
$params["formId"] = $_GET["form"];
else
$params["formId"] = (isset(Yii::app()->session["costum"]["form"]["id"])) ? Yii::app()->session["costum"]["form"]["id"] : Form::generateOpenForm( $el["slug"] );
}
$params["mode"] = "w";
if(isset($_GET["mode"]))
$params["mode"] = $_GET["mode"];
// else {
// if(isset($_GET["answer"]))
// }
//Rest::json($params);exit;
// $answer = ( isset(Yii::app()->session["costum"]["form"]["canModifyAnswer"]) && isset($_GET['answer'])) ? PHDB::findOne( Form::ANSWER_COLLECTION,[ "_id" => new MongoId($_GET['answer']) ] ) : null;
if(!isset($params["el"]) && !empty($answer) && isset($answer["parentSlug"]))
$params["el"]=Slug::getElementBySlug($answer["parentSlug"])["el"];
$showForm = true;
$myAnswers = PHDB::find( Form::ANSWER_COLLECTION,[
"formId" => $params["formId"],
"parentSlug" => $params["el"]["slug"],
"user" => Yii::app()->session["userId"] ] );
if(!isset(Yii::app()->session["costum"]["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 && empty($_GET['answer']))
$answer = $myAnswers[ array_keys($myAnswers)[0] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$showForm = false;
//si aucune reponse existe
//et qu'on a des input complexe alors on génere une answer
if( !isset($_GET['answer']) && $answer == null ){
if(isset($params["formList"])){
$generateAnswer = true;
}
else if(isset($form["inputs"])){
foreach ($form["inputs"] as $key => $inp)
{
if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
$generateAnswer = true;
}
}
}
if( isset($answerId) && $answerId == "new" )
$generateAnswer = true;
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
//on pré genere un anwser que quand il n'y en pas
//pour permettre le save onBlur , ou s'il y a des cplx forms
//il ne peut y avoir qu'un seul answer en cours simultanement
///TODO purger ANSwers via CRON
if( $generateAnswer )
{
//var_dump("create new" );
$ans = [
"formId" => $params["formId"],
"user" => Yii::app()->session["userId"],
"parentSlug" => $params["el"]["slug"],
"links"=>[
"answered" => [ Yii::app()->session["userId"] ] ,
//proposed ,particpated,decision,financed,financed,referenced,commented,worked,payed,tested,validated
//each actor is connectable to his activitystream
],
"created" => time()
];
if(isset($params["formList"]))
$ans["formList"] = count($params["formList"]);
PHDB::insert(Form::ANSWER_COLLECTION, $ans);
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] );
}
//Rest::json($answer); exit;
// var_dump($params["el"]["slug"] );
// var_dump($params["formId"] );
// var_dump($answer );
// var_dump(Yii::app()->getRequest()->getQuery('answer'));
// exit;
$params["answer"] = $answer;
$params["showForm"] = $showForm;
$params["showAnswerActions"]=(isset($params["showAnswerActions"])) ? $params["showAnswerActions"] : true;
$allAnswers = PHDB::find( Form::ANSWER_COLLECTION,[
"formId" => $params["formId"],
"parentSlug" => $params["el"]["slug"] ] ) ;
$params["allAnswers"] = (!isset($allAnswers)) ? [] : $allAnswers ;
//var_dump($params["el"]["slug"]);exit;
//var_dump($params["allAnswers"]);exit;
} else {
echo "<h4 class='text-center text-red'><i class='fa fa-warning'></i> Une seul réponse n'est possible.</h4>";
echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/answer/".$myAnswers[0]."'>Votre réponse</a>";
}
}
>>>>>>> qa
return $params;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment