Commit d536b629 authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

setting step after operator validation to deal3

parent 5561fb29
......@@ -417,8 +417,11 @@ class Form {
public static function canSeeAnswer($userId, $answer, $form, $parentForm){
if(self::canEditAnswer($userId, $answer, $form, $parentForm))
return true;
else if(Costum::isSameFunction("canSeeAnswer", array("answer"=>$answer)))
return Costum::sameFunction("canSeeAnswer", array("answer"=>$answer));
// else if(Costum::sameFunction("canSeeAnswer", array("answer"=>$answer))){
// return true;
// }
else if(Costum::isSameFunction("canEditAnswer", array("answer"=>$answer)))
return Costum::sameFunction("canEditAnswer", array("answer"=>$answer));
return false;
}
public static function canEditAnswer($userId, $answer, $form, $parentForm){
......@@ -646,7 +649,6 @@ class Form {
}
public static function getFormData($params){
$costum = CacheHelper::getCostum();
//Rest::json($costum ); exit;
//WARNING la c'est bien data que l'on veut
if(isset($costum["form"]["rules"])){
foreach ($params["formList"] as $k => $value) {
......@@ -661,29 +663,27 @@ class Form {
$budgetInputList = [];
$allforms = [];
$stockBudgetInputs = false;
if( !empty($params["formList"]) ){
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;
}
}
}
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))
CacheHelper::set("budgetInputList", $budgetInputList);
Yii::app()->session["budgetInputList"] = $budgetInputList;
//use the cache
CacheHelper::set("forms", $allforms);
Yii::app()->session["forms"] = $allforms;
return $params;
}
......@@ -727,7 +727,6 @@ class Form {
$params["formList"] = $costum["form"]["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
//Rest::json($params); exit;
$params=self::getFormData($params);
} else {
if(isset($_GET["form"]))
......@@ -744,96 +743,91 @@ class Form {
$showForm = true;
if( !empty($params["formId"]) )
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if( !empty($myAnswers) ) {
if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 )
$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"]) ] );
// }
// 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 = self::getListAnswersBy($params["formId"], $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>";
}
}
if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 )
$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"]) ] );
// }
// 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 = self::getListAnswersBy($params["formId"], $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>";
}
}
return $params;
}
......
......@@ -111,8 +111,18 @@ $(document).ready(function() {
}
};
$(this).fadeOut();
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal3" //pourrait etre un parametre element.costum.form.stepOperateur : deal3
};
mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
} );
});
......
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