Commit 0e7ea975 authored by Tibor Katelbach's avatar Tibor Katelbach

refactor ids to subForms

parent 5e1cbf65
......@@ -16,7 +16,6 @@ class GetAction extends CTKAction
$params = [];
$params["form"] = PHDB::findOne( Form::COLLECTION, [ "_id"=>new MongoId($form) ] );
//var_dump($params["form"]);exit;
$params["formList"] = $params["form"]["ids"];
$params["forms"] = [];
foreach ($params["formList"] as $ix => $formId) {
$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
......@@ -27,7 +26,7 @@ class GetAction extends CTKAction
$params['el'] = $el["el"];
//ce code ne marchera pas pour deux formulaire identaique , d'un meme slug
//TODO utiliser le parntForm Id en plus
// $params["allAnswers"] = PHDB::find( Form::ANSWER_COLLECTION, ["formId"=>implode('|', $params["form"]["ids"]) , "parentSlug" => $params["form"]["parentSlug"]] );
// $params["allAnswers"] = PHDB::find( Form::ANSWER_COLLECTION, ["formId"=>implode('|', $params["form"]["subForms"]) , "parentSlug" => $params["form"]["parentSlug"]] );
$params["allAnswers"] = PHDB::find( Answer::COLLECTION, ["form"=> $form] );
$params['canEdit'] = ( isset(Yii::app()->session["userId"]) && isset($el["type"]) && isset($el["id"]) ) ?
Authorisation::canEditItem(Yii::app()->session["userId"],$el["type"], $el["id"])
......
......@@ -12,10 +12,10 @@ class DeleteAction extends CAction
{
// if( Authorisation::isElementAdmin($id, Form::ANSWER_COLLECTION, Yii::app()->session["userId"], false)) {
if(isset($form["ids"]))
if(isset($form["subForms"]))
{
PHDB::remove( Form::ANSWER_COLLECTION, ["formId" => implode("|", $form["ids"]) ]);
foreach ($form["ids"] as $ix => $fid) {
PHDB::remove( Form::ANSWER_COLLECTION, ["formId" => implode("|", $form["subForms"]) ]);
foreach ($form["subForms"] as $ix => $fid) {
PHDB::remove( Form::COLLECTION, ["id" => $fid]);
}
}
......
......@@ -25,8 +25,8 @@ class GetAction extends CTKAction
{
$formId = "";
if(isset($f['ids'])){
foreach ($f['ids'] as $ix => $fid)
if(isset($f['subForms'])){
foreach ($f['subForms'] as $ix => $fid)
{
if($formId != "")
$formId .= "|";
......
......@@ -28,8 +28,8 @@ class Answer{
$formList = null ;
if( !empty($form) ){
$ans["form"] = (String)$form["_id"];
if(!empty($form["ids"])){
$formList = $form["ids"];
if(!empty($form["subForms"])){
$formList = $form["subForms"];
$ans["formId"] = implode("|", $formList);
$ans["formList"] = count($formList);
}
......
......@@ -167,9 +167,8 @@ class Form {
$queryForm=array("_id"=>new MongoId($form));
}
$res["form"]=PHDB::findOne( Form::COLLECTION, $queryForm );
$res["formList"] = $res["form"]["ids"];
$res["forms"] = [];
foreach ($res["formList"] as $ix => $formId) {
foreach ($res["form"]["subForms"] as $ix => $formId) {
$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
$res["forms"][$formId] = $f;
}
......@@ -773,8 +772,8 @@ class Form {
$params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"];
}else if(isset($form) && !empty($form["ids"]) ){
$params["formList"] = $form["ids"];
}else if(isset($form) && !empty($form["subForms"]) ){
$params["formList"] = $form["subForms"];
$params["formId"] = implode("|", $params["formList"]);
}
$params=self::getFormData($params);
......
......@@ -311,7 +311,8 @@ var answerObj = <?php echo (!empty($answer)) ? json_encode( $answer ) : "null";
if($showForm){
$params = [
"formList"=>$formList,
"parentForm"=>$parentForm,
"form"=>$form,
"el" => $el,
"active" => "all",
"color1" => $color1,
......
<?php
if($canEditForm === true){
$subFormIds = [];
if(isset($form["ids"]))
$subFormIds = array_merge( $subFormIds, $form["ids"] );
if(isset($form["subForms"]))
$subFormIds = array_merge( $subFormIds, $form["subForms"] );
?>
<div class="col-xs-12 padding-10 text-center bg-info">
<h4>Admin Form</h4>
......@@ -42,7 +42,7 @@ var oformParams = {
params : { onText : "Oui", offText : "Non", onLabel : "Oui", offLabel : "Non",
labelText : "Activé"},
checked : false },
ids : {
subForms : {
inputType : "array",
label : "Nommé chaque étape de votre questionnaire",
//subLabel : "Vous remplirez les question de chaques étapes par la suite",
......@@ -107,14 +107,16 @@ var oformParams = {
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array"){
tplCtx.value[k] = getArray('.'+k+val.inputType);
if(k=="ids"){
if(k=="subForms"){
var cx = subForms.length;
$.each(tplCtx.value[k],function(ix,fName) {
mylog.log("check sub Form",fName, "<?php echo $el["slug"] ?>"+cx);
if($.inArray(fName, subForms) < 0 ){
var newFormId = "<?php echo $el["slug"] ?>"+cx;
tplCtx.value[k][ix] = newFormId;
var newForm ={
var newForm = {
collection : "forms",
value : {
id : newFormId,
......
......@@ -182,7 +182,7 @@ if( $mode != "pdf" ){
user : userId
}
};
if(costum.form.ids.length == $.inArray( "<?php echo $form['id'] ?>", costum.form.ids )+1 && formData.valid == "valid")
if(costum.form.subForms.length == $.inArray( "<?php echo $form['id'] ?>", costum.form.subForms )+1 && formData.valid == "valid")
ctxTpl.value.finished = true;
mylog.log("validation save",ctxTpl);
......@@ -192,10 +192,10 @@ if( $mode != "pdf" ){
//only increment step form to next step if step valid
if( ctxTpl.value.valid == "valid" || ctxTpl.value.valid == "validReserve" ){
step = 0;
if(costum.form.ids.length == $.inArray( "<?php echo $form['id'] ?>", costum.form.ids )+1)
if(costum.form.subForms.length == $.inArray( "<?php echo $form['id'] ?>", costum.form.subForms )+1)
step = "all";
else
step = costum.form.ids[$.inArray( "<?php echo $form['id'] ?>", costum.form.ids )+1];
step = costum.form.subForms[$.inArray( "<?php echo $form['id'] ?>", costum.form.subForms )+1];
ctxTpl = {
id : "<?php echo $answer['_id'] ?>",
......
......@@ -288,7 +288,8 @@ var answerObj = <?php echo (!empty($answer)) ? json_encode( $answer ) : "null";
}
if(!empty($showForm)) {
$params = [
"formList"=>$formList,
"parentForm"=>$parentForm,
"form"=>$form,
"el" => $el,
"active" => "all",
"color1" => $color1,
......
......@@ -8,8 +8,8 @@
$ct = 0;
$subFormIds = [];
foreach ($forms as $fix => $f) {
if(isset($f["ids"])){
foreach ($f["ids"] as $ix => $sfid) {
if(isset($f["subForms"])){
foreach ($f["subForms"] as $ix => $sfid) {
if(!in_array($sfid , $subFormIds))
$subFormIds[] = $sfid;
}
......@@ -36,8 +36,8 @@ foreach ($forms as $fix => $f) {
steps : <br/>
<?php
if(isset($f['ids'])){
foreach ( $f["ids"] as $ix => $i ) {
if(isset($f['subForms'])){
foreach ( $f["subForms"] as $ix => $i ) {
$countQ = ( isset($f[$i]["inputs"]) ) ? count($f[$i]["inputs"]) : 0;
echo '<i class="fa fa-file-text-o"></i> '.$f[$i]['name']." (".$countQ." inputs)<br/>";
}
......@@ -193,7 +193,7 @@ var oform = {
// params : { onText : "Oui", offText : "Non", onLabel : "Oui", offLabel : "Non",
// labelText : "Activé"},
// checked : false },
// ids : {
// subForms : {
// inputType : "array",
// label : "Nommé chaque étape de votre questionnaire",
// //subLabel : "Vous remplirez les question de chaques étapes par la suite",
......
......@@ -19,6 +19,7 @@ if( isset($this->costum["tpls"][$keyTpl]) ) {
}
}
if( isset($form["subForms"]) && count($form["subForms"]) > 1 ) {
?>
<div class="col-xs-12 margin-top-20">
<div id="<?php echo $wizid ?>" class="swMain">
......@@ -44,15 +45,12 @@ if( isset($this->costum["tpls"][$keyTpl]) ) {
// var_dump($listSteps); exit;
$activeStep = 0;
$nextStepValid =true;
foreach ($formList as $k => $v) {
foreach ($form["subForms"] as $k => $v) {
$n = "todo";
$p = null;
$form = PHDB::findOne( Form::COLLECTION,[ "id"=>$v ] );
if( !empty($form) )
$n = $form["name"];
if( !empty($forms[$v]) )
$n = $forms[$v]["name"];
echo "<li>";
......@@ -65,7 +63,7 @@ if( isset($this->costum["tpls"][$keyTpl]) ) {
$k == 0 ||
(isset($answer["step"]) && $answer["step"] == "all" ) ||
(isset($parentForm["hasStepValidations"]) && isset($answer["step"]) && $k <= array_search($answer["step"], $formList) ) ||
(isset($parentForm["hasStepValidations"]) && isset($answer["step"]) && $k <= array_search($answer["step"], $form["subForms"]) ) ||
( isset($parentForm["hasStepValidations"]) && !isset($answer["step"]) && $k <= $parentForm["hasStepValidations"] ) )
{
$d = 'class="done"';
......@@ -85,18 +83,14 @@ if( isset($this->costum["tpls"][$keyTpl]) ) {
<?php
foreach ($formList as $k => $v) {
foreach ($form["subForms"] as $k => $v) {
$hide = ($k==$activeStep) ? "" : "hide";
?>
<div id='<?php echo $v ; ?>' class='col-sm-offset-1 col-sm-10 sectionStep <?php echo $hide ;?>' style="padding-bottom:40px">
<?php
$form = PHDB::findOne( Form::COLLECTION,[ "id"=>$v ] );
?>
<script type="text/javascript">
formInputs["<?php echo $v ?>"] = <?php echo ( !empty($form['inputs']) ? json_encode( $form['inputs'] ) : json_encode([]) ) ?>;
formInputs["<?php echo $v ?>"] = <?php echo ( !empty($forms[$v]['inputs']) ? json_encode( $forms[$v]['inputs'] ) : json_encode([]) ) ?>;
var formInputsHere = formInputs;
jQuery(document).ready(function() {
mylog.log("render","survey.views.tpls.forms.wizard");
......@@ -119,23 +113,23 @@ if( isset($this->costum["tpls"][$keyTpl]) ) {
</script>
<?php
if( !empty($form) )
if( !empty($forms[$v]) )
{
echo '<h1 class="text-center" style="color:'.$color1.'" >'.@$form["name"].'</h1>';
echo '<h1 class="text-center" style="color:'.$color1.'" >'.@$forms[$v]["name"].'</h1>';
echo "<div class='text-center'>";
if(isset($this->costum["cms"][$form["id"]."desc"]))
echo htmlentities($this->costum["cms"][$form["id"]."desc"]);
if(isset($this->costum["cms"][$forms[$v]["id"]."desc"]))
echo htmlentities($this->costum["cms"][$forms[$v]["id"]."desc"]);
else
echo "<span style='color:#aaa'>* section description</span>";
if(@$canEditForm)
echo "<a class='btn btn-xs btn-danger editBtn' href='javascript:;' data-key='".@$form["id"]."desc' data-type='textarea' data-markdown='1' data-path='costum.cms.".@$form["id"]."desc' data-label='Expliquez les objectifs de cette étape ? '> <i class='fa fa-pencil'></i></a>";
echo "<a class='btn btn-xs btn-danger editBtn' href='javascript:;' data-key='".@$forms[$v]["id"]."desc' data-type='textarea' data-markdown='1' data-path='costum.cms.".@$forms[$v]["id"]."desc' data-label='Expliquez les objectifs de cette étape ? '> <i class='fa fa-pencil'></i></a>";
echo "</div>";
//echo "<div class='markdown'>";
echo "<div class=''>";
echo $this->renderPartial("survey.views.tpls.forms.formSection",
[ "formId" => $v,
"form" => $form,
"form" => $forms[$v],
"wizard" => true,
"answer"=>$answer,
"mode" => @$mode,
......@@ -157,13 +151,37 @@ if( isset($this->costum["tpls"][$keyTpl]) ) {
?>
<script type="text/javascript">
</script>
</div>
<?php } else if( isset($form["subForms"]) && count($form["subForms"]) == 1 ) {
echo "<div class='col-xs-12'>";
echo '<h1 class="text-center" style="color:'.$color1.'" >'.@$forms[$v]["name"].'</h1>';
echo "<div class='text-center'>";
if(isset($this->costum["cms"][$forms[$v]["id"]."desc"]))
echo htmlentities($this->costum["cms"][$forms[$v]["id"]."desc"]);
else
echo "<span style='color:#aaa'>* section description</span>";
if(@$canEditForm)
echo "<a class='btn btn-xs btn-danger editBtn' href='javascript:;' data-key='".@$forms[$v]["id"]."desc' data-type='textarea' data-markdown='1' data-path='costum.cms.".@$forms[$v]["id"]."desc' data-label='Expliquez les objectifs de cette étape ? '> <i class='fa fa-pencil'></i></a>";
echo "</div>";
//echo "<div class='markdown'>";
echo "<div class=''>";
echo $this->renderPartial("survey.views.tpls.forms.formSection",
[ "formId" => $form["subForms"][0],
"form" => $forms[$form["subForms"][0]],
"wizard" => true,
"answer"=>$answer,
"mode" => @$mode,
"showForm" => $showForm,
"canEdit" => $canEdit,
"canEditForm" => @$canEditForm,
"el" => $el ] ,true );
echo "</div>";
echo "</div>";
} else {
echo "<div class='col-xs-12 text-center'>";
echo '<br/><h4 class="text-red text-center">ce formulaire est encore vide</h4>';
echo "<a href='javascript:;' data-id='".(String)$form["_id"]."' class='configBtn btn btn-danger bold'> <i class='fa fa-cogs'></i> CONFIGUREZ LE ICI </a>";
echo "</div>";
} ?>
</div>
\ No newline at end of file
......@@ -157,7 +157,8 @@ if(isset($this->costum["cms"]["color1"]))
if($showForm){
$params = [
"formList"=>$formList,
"parentForm"=>$parentForm,
"form"=>$form,
"el" => $el,
"active" => "all",
"color1" => $color1,
......
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