Commit 544ed60f authored by Clément Damiens's avatar Clément Damiens
Browse files

Merge remote-tracking branch 'origin/development' into development

parents 114be7c5 ee45e6cd
...@@ -660,22 +660,25 @@ class Form { ...@@ -660,22 +660,25 @@ class Form {
$budgetInputList = []; $budgetInputList = [];
$allforms = []; $allforms = [];
$stockBudgetInputs = false; $stockBudgetInputs = false;
foreach ($params["formList"] as $i => $formId) if(!empty($params["formList"])){
{ foreach ($params["formList"] as $i => $formId)
$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]); {
$allforms[$formId] = $f; $f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
foreach ($f["inputs"] as $key => $inp) $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.budget"] ) )
if( in_array($inp["type"], [ $budgetInputList[$formId.".".$key] = $formId.".".$key;
"tpls.forms.cplx.tpls.forms.cplx.financementFromBudget", if( in_array($inp["type"], [
"tpls.forms.cplx.tpls.forms.cplx.suiviFromBudget", "tpls.forms.cplx.tpls.forms.cplx.financementFromBudget",
"tpls.forms.cplx.tpls.forms.cplx.decideFromBudget"] ) ) "tpls.forms.cplx.tpls.forms.cplx.suiviFromBudget",
$stockBudgetInputs = true; "tpls.forms.cplx.tpls.forms.cplx.decideFromBudget"] ) )
$stockBudgetInputs = true;
}
} }
}
}
if(count($budgetInputList)) if(count($budgetInputList))
Yii::app()->session["budgetInputList"] = $budgetInputList; Yii::app()->session["budgetInputList"] = $budgetInputList;
//var_dump($budgetInputList); //var_dump($budgetInputList);
...@@ -743,91 +746,95 @@ class Form { ...@@ -743,91 +746,95 @@ class Form {
$showForm = true; $showForm = true;
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if(!empty($params["formId"])){
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){ if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//si ya qu'une réponse et on la charge directe //si ya qu'une réponse et on la charge directe
if(count($myAnswers) == 1 ) if(count($myAnswers) == 1 )
$answer = $myAnswers[ array_keys($myAnswers)[0] ]; $answer = $myAnswers[ array_keys($myAnswers)[0] ];
else { else {
//sinon on cherche la reponse incomplete //sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans) foreach ($myAnswers as $id => $ans)
{ {
//chercher les reponse incomplete //chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null ) if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans; $answer = $ans;
} }
} }
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] ) if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$showForm = false; $showForm = false;
//si aucune reponse existe //si aucune reponse existe
//et qu'on a des input complexe alors on génere une answer //et qu'on a des input complexe alors on génere une answer
// if( !isset($_GET['answer']) && $answer == null ){ // if( !isset($_GET['answer']) && $answer == null ){
// if(isset($params["formList"])){ // if(isset($params["formList"])){
// $generateAnswer = true; // $generateAnswer = true;
// } // }
// else if(isset($form["inputs"])){ // else if(isset($form["inputs"])){
// foreach ($form["inputs"] as $key => $inp) // foreach ($form["inputs"] as $key => $inp)
// { // {
// if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false ) // if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
// $generateAnswer = true; // $generateAnswer = true;
// } // }
// } // }
// } // }
// if( isset($answerId) && $answerId == "new" ) // if( isset($answerId) && $answerId == "new" )
// $generateAnswer = true; // $generateAnswer = true;
//on pré genere un anwser que quand il n'y en pas //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 //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 //il ne peut y avoir qu'un seul answer en cours simultanement
//on pré genere un anwser que quand il n'y en pas //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 //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 //il ne peut y avoir qu'un seul answer en cours simultanement
///TODO purger ANSwers via CRON ///TODO purger ANSwers via CRON
// if( $generateAnswer ) // if( $generateAnswer )
// { // {
// //var_dump("create new" ); // //var_dump("create new" );
// $ans = [ // $ans = [
// "formId" => $params["formId"], // "formId" => $params["formId"],
// "user" => Yii::app()->session["userId"], // "user" => Yii::app()->session["userId"],
// "parentSlug" => $params["el"]["slug"], // "parentSlug" => $params["el"]["slug"],
// "links"=>[ // "links"=>[
// "answered" => [ Yii::app()->session["userId"] ] , // "answered" => [ Yii::app()->session["userId"] ] ,
// //proposed ,particpated,decision,financed,financed,referenced,commented,worked,payed,tested,validated // //proposed ,particpated,decision,financed,financed,referenced,commented,worked,payed,tested,validated
// //each actor is connectable to his activitystream // //each actor is connectable to his activitystream
// ], // ],
// "created" => time() // "created" => time()
// ]; // ];
// if(isset($params["formList"])) // if(isset($params["formList"]))
// $ans["formList"] = count($params["formList"]); // $ans["formList"] = count($params["formList"]);
// PHDB::insert(Form::ANSWER_COLLECTION, $ans); // PHDB::insert(Form::ANSWER_COLLECTION, $ans);
// $answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] ); // $answer = PHDB::findOne( Form::ANSWER_COLLECTION, [ "_id" => new MongoId($ans["_id"]) ] );
// } // }
// var_dump($params["el"]["slug"] ); // var_dump($params["el"]["slug"] );
// var_dump($params["formId"] ); // var_dump($params["formId"] );
// var_dump($answer ); // var_dump($answer );
// var_dump(Yii::app()->getRequest()->getQuery('answer')); // var_dump(Yii::app()->getRequest()->getQuery('answer'));
// exit; // exit;
$params["answer"] = $answer; $params["answer"] = $answer;
$params["showForm"] = $showForm; $params["showForm"] = $showForm;
$params["showAnswerActions"]=(isset($params["showAnswerActions"])) ? $params["showAnswerActions"] : true; $params["showAnswerActions"]=(isset($params["showAnswerActions"])) ? $params["showAnswerActions"] : true;
$allAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"] ) ; $allAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"] ) ;
$params["allAnswers"] = (isset($allAnswers)) ? $allAnswers : [] ; $params["allAnswers"] = (isset($allAnswers)) ? $allAnswers : [] ;
//var_dump($params["el"]["slug"]);exit; //var_dump($params["el"]["slug"]);exit;
//var_dump($params["allAnswers"]);exit; //var_dump($params["allAnswers"]);exit;
} else { } else {
echo "<h4 class='text-center text-red'><i class='fa fa-warning'></i> Une seul réponse n'est possible.</h4>"; 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>"; echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/answer/".$myAnswers[0]."'>Votre réponse</a>";
}
} }
} }
return $params; return $params;
} }
......
...@@ -6,32 +6,37 @@ else if(!empty($answer) && isset($answer["answers"][$kunik]) && $answer["answers ...@@ -6,32 +6,37 @@ else if(!empty($answer) && isset($answer["answers"][$kunik]) && $answer["answers
$value = "checked"; $value = "checked";
$inpClass = "";
if($saveOneByOne) if($saveOneByOne)
$inpClass = " saveOneByOne"; $inpClass = " saveOneByOne";
if($mode == "r"){ ?> if($mode == "r" || $mode == "pdf"){ ?>
<div class="col-xs-12" id="<?php echo $kunik ?>"> <div class="col-xs-12" id="<?php echo $kunik ?>">
<label for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label ?></h4></label> <label for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label ?></h4></label><br/>
<?php <?php echo @$form["inputs"][$key]["placeholder"]." : ".(!empty($value) ? "Yes" : "No"); ?>
echo @$form["inputs"][$key]["placeholder"]." : ".(!empty($value) ? "Yes" : "No");
?>
</div> </div>
<?php <?php
}else{ }else{
?> ?>
<div class="form-check"> <div class="form-check">
<label class="form-check-label" for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label> <label class="form-check-label" for="<?php echo $kunik ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label>
<br/>
<input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?php echo $kunik ?>" data-form='<?php echo $form["id"] ?>' <?php echo $value ?> > <?php echo @$form["inputs"][$key]["placeholder"]?> <input type="checkbox" class="form-check-input <?php echo $inpClass ?>" id="<?php echo $kunik ?>" data-form='<?php echo $form["id"] ?>' <?php echo $value ?> > <?php echo @$form["inputs"][$key]["placeholder"]?>
<?php if(!empty($info)){ ?> <?php if(!empty($info)){ ?>
<small id="<?php echo $key ?>Help" class="form-text text-muted"><?php echo $info ?></small> <small id="<?php echo $key ?>Help" class="form-text text-muted"><?php echo $info ?></small>
<?php } ?> <?php } ?>
</div> </div>
<script type="text/javascript">
<?php } ?>
<?php if($mode != "pdf"){ ?>
<script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
mylog.log("render form input","/modules/costum/views/tpls/forms/checkbox.php"); mylog.log("render form input","/modules/costum/views/tpls/forms/checkbox.php");
}); });
</script> </script>
<?php } ?> <?php } ?>
\ No newline at end of file
<?php <?php
//check show btn use cases //check show btn use cases
// role is financer or operater // role is financer or operater
if( $mode != "pdf" ){
if(Form::canFormAccess( ['roles'=>["Financeur","Opérateur"] ]))
{
if( isset($form['id']) )
{ ?>
if( Form::canFormAccess( ['roles'=>["Financeur","Opérateur"] ]))
{
if( isset($form['id']) )
{ ?>
<table class="table table-bordered table-hover directoryTable" >
<tbody class="directoryLines">
<tr>
<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Intention Opérateur</h4></td>
</tr>
<?php
$str = "";
$selectedOperator = false;
if(isset($answer["links"]["operators"]))
{
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$persons = Link::groupFindByType( Person::COLLECTION,$communityLinks,["name","links"] );
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$financers = array_merge( $persons, $organizations );
$orgs = []; <table class="table table-bordered table-hover directoryTable" >
if( !empty($or["links"]["memberOf"][$this->costum["contextId"]]["roles"]) ) { <tbody class="directoryLines">
foreach ($financers as $id => $or) {
$roles = $or["links"]["memberOf"][$this->costum["contextId"]]["roles"]; <tr>
if( isset($this->costum["form"]["params"]["financement"]["limitRoles"]) && !empty($roles)) <td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Intention Opérateur</h4></td>
{ </tr>
foreach ($roles as $i => $r) { <?php
if( in_array($r, $this->costum["form"]["params"]["financement"]["limitRoles"]) ) $str = "";
$orgs[$id] = $or["name"]; $selectedOperator = false;
} if(isset($answer["links"]["operators"]))
{
$communityLinks = Element::getCommunityByTypeAndId($this->costum["contextType"],$this->costum["contextId"]);
$persons = Link::groupFindByType( Person::COLLECTION,$communityLinks,["name","links"] );
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$financers = array_merge( $persons, $organizations );
$orgs = [];
if( !empty($or["links"]["memberOf"][$this->costum["contextId"]]["roles"]) ) {
foreach ($financers as $id => $or) {
$roles = $or["links"]["memberOf"][$this->costum["contextId"]]["roles"];
if( isset($this->costum["form"]["params"]["financement"]["limitRoles"]) && !empty($roles))
{
foreach ($roles as $i => $r) {
if( in_array($r, $this->costum["form"]["params"]["financement"]["limitRoles"]) )
$orgs[$id] = $or["name"];
}
}
} }
} }
} // var_dump($orgs);exit;
// var_dump($orgs);exit;
foreach ($answer["links"]["operators"] as $oid => $state) { foreach ($answer["links"]["operators"] as $oid => $state) {
if($state != "0") if($state != "0")
{ {
$selectedOperator = true; $selectedOperator = true;
$str = '<tr>'. $str = '<tr>'.
'<td>Opérateur</td>'. '<td>Opérateur</td>'.
'<td>'.$oid.'</td>'. '<td>'.$oid.'</td>'.
'<td><span class="label label-success">Validé</span></td>'. '<td><span class="label label-success">Validé</span></td>'.
'</tr>'; '</tr>';
} }
else if( !$selectedOperator ) else if( !$selectedOperator )
{ {
//if role financeurs //if role financeurs
$str .= '<tr>'. $str .= '<tr>'.
'<td>Opérateur Candidat</td>'. '<td>Opérateur Candidat</td>'.
'<td>'.$oid.'</td>'. '<td>'.$oid.'</td>'.
'<td><span class="label label-success"><a href="javascript:;" class="validateOperator" data-id="'.$oid.'">à Valider</a></span></td>'. '<td><span class="label label-success"><a href="javascript:;" class="validateOperator" data-id="'.$oid.'">à Valider</a></span></td>'.
'</tr>'; '</tr>';
}
} }
}
echo $str;
//if role operateurs
if(!$selectedOperator){
?>
<tr>
<td colspan='2' class="text-center" >
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="intentOperator btn btn-primary">Opérateur : Demander de prendre en charge</a>
</td>
</tr>
<?php
} }
} //if role financeur
echo $str; if(!$selectedOperator){
?>
<tr>
//if role operateurs <td colspan='2' class="text-center" >
if(!$selectedOperator){ <a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="validateOperator btn btn-danger">Financeur : Veuillez étudier ce dossier</a>
?> </td>
<tr> </tr>
<td colspan='2' class="text-center" > <?php }?>
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="intentOperator btn btn-primary">Opérateur : Demander de prendre en charge</a> </tbody>
</td> </table>
</tr> <?php
<?php }
} } else { ?>
//if role financeur <div class="col-xs-12 text-center margin-top-50 well">
if(!$selectedOperator){ <?php if(@$answer["step"] && $answer["step"]=="deal1"){ ?>
?> <span style="font-size: 22px;font-weight: 800;">Vous avez soumis votre dossier pour qu'un opérateur se positionne dessus.<br/>Il est en cours de validation.
<tr> Cette étape sera validé par un opérateur et les financeurs.</span>
<td colspan='2' class="text-center" > <?php }else{ ?>
<a href="javascript:;" data-oid="<?php echo Yii::app()->session["userId"] ?>" class="validateOperator btn btn-danger">Financeur : Veuillez étudier ce dossier</a> <span class="text-center" style="font-size: 22px;font-weight: 800;">
</td> Une fois votre dossier estimé rempli, vous pouvez le valider afin qu'il soit mis sous étude des opérateurs et des financeurs<br/><br/>
</tr> <a href="javascript:;" class="validateForSubmit btn btn-success">
<?php }?> Soumettre votre dossier
</tbody> </a>
</table> </span>
<?php <?php } ?>
}} else { ?> </div>
<div class="col-xs-12 text-center margin-top-50 well"> <?php
<?php if(@$answer["step"] && $answer["step"]=="deal1"){ ?> } ?>
<span style="font-size: 22px;font-weight: 800;">Vous avez soumis votre dossier pour qu'un opérateur se positionne dessus.<br/>Il est en cours de validation. <script type="text/javascript">
Cette étape sera validé par un opérateur et les financeurs.</span>
<?php }else{ ?>
<span class="text-center" style="font-size: 22px;font-weight: 800;">
Une fois votre dossier estimé rempli, vous pouvez le valider afin qu'il soit mis sous étude des opérateurs et des financeurs<br/><br/>
<a href="javascript:;" class="validateForSubmit btn btn-success">
Soumettre votre dossier
</a>
</span>
<?php } ?>
</div>
<?php } ?>
<script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
mylog.log("render","modules/survey/views/tpls/forms/costum/deal/stepOperateur.php"); mylog.log("render","modules/survey/views/tpls/forms/costum/deal/stepOperateur.php");
var today = new Date(); var today = new Date();
today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear(); today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
$('.validateOperator').off().on("click", function() { $('.validateOperator').off().on("click", function() {
var oid = $(this).data("id"); var oid = $(this).data("id");
ctxTpl = { ctxTpl = {
id : "<?php echo $answer['_id'] ?>", id : "<?php echo $answer['_id'] ?>",
collection : "answers", collection : "answers",
path : "links.operators."+oid, path : "links.operators."+oid,
value : { value : {
date : today, date : today,
user : userId user : userId
} }
}; };
$(this).fadeOut(); $(this).fadeOut();
mylog.log("save step save",ctxTpl); mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) { dataHelper.path2Value( ctxTpl, function(params) {
ctxTpl = { ctxTpl = {
id : "<?php echo $answer['_id'] ?>", id : "<?php echo $answer['_id'] ?>",
collection : "answers", collection : "answers",
path : "step", path : "step",
value : "deal3" //pourrait etre un parametre element.costum.form.stepOperateur : deal3 value : "deal3" //pourrait etre un parametre element.costum.form.stepOperateur : deal3
}; };
mylog.log("save step save",ctxTpl); mylog.log("save step save",ctxTpl);
dataHelper.path2Value( ctxTpl, function(params) { dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
} );
});
$('.validateForSubmit').off().on("click", function() {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal1"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
});
} );
$('.intentOperator').off().on("click", function() {
var oid = $(this).data("oid");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : "0"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash); urlCtrl.loadByHash(location.hash);
} ); } );
} );
});
$('.validateForSubmit').off().on("click", function() {
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "step",
value : "deal1"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
}); });
} );
$('.intentOperator').off().on("click", function() {
var oid = $(this).data("oid");
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
collection : "answers",
path : "links.operators."+oid,
value : "0"
};
dataHelper.path2Value( ctxTpl, function(params) {
urlCtrl.loadByHash(location.hash);
} );
}); });
</script>
<?php } ?>