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

detaching coforms from costums

parent 743dc207
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
'new' => 'survey.controllers.answer.NewAction', 'new' => 'survey.controllers.answer.NewAction',
'index' => 'survey.controllers.answer.IndexAction', 'index' => 'survey.controllers.answer.IndexAction',
'all'=>'survey.controllers.answer.AllAction', 'all'=>'survey.controllers.answer.AllAction',
'admindirectory'=>'survey.controllers.answer.admin.DirectoryAction' 'admindirectory'=>'survey.controllers.answer.admin.DirectoryAction',
'forms' => 'survey.controllers.answer.OformsAction',
'all' => 'survey.controllers.answer.AllAction',
); );
} }
} }
...@@ -24,7 +24,6 @@ class CoController extends CommunecterController { ...@@ -24,7 +24,6 @@ class CoController extends CommunecterController {
'form' => 'survey.controllers.actions.FormAction', 'form' => 'survey.controllers.actions.FormAction',
'forms' => 'survey.controllers.actions.FormsAction', 'forms' => 'survey.controllers.actions.FormsAction',
'oforms' => 'survey.controllers.actions.OformsAction',
'edit' => 'survey.controllers.actions.EditAction', 'edit' => 'survey.controllers.actions.EditAction',
'new' => 'survey.controllers.actions.NewAction', 'new' => 'survey.controllers.actions.NewAction',
'save' => 'survey.controllers.actions.SaveAction', 'save' => 'survey.controllers.actions.SaveAction',
......
<?php
class OformsAction extends CTKAction
{
public function run($slug)
{
$this->getController()->layout = "//layouts/empty";
$el = Slug::getElementBySlug($slug);
$params = [];
if(isset( $el["el"]["costum"]["form"]))
{
$params["forms"] = [ $el["el"]["costum"]["form"] ];
$params["forms"][0]["name"] = "todo COForms name";
//$params["forms"][0]["name"] = "todo COForms name";
//var_dump($el["el"]["costum"]["form"]); exit;
foreach ( $params["forms"] as $fix => $f )
{
$formId = "";
foreach ($f['ids'] as $ix => $fid)
{
if($formId != "")
$formId .= "|";
$formId .= $fid;
$params["forms"][$fix][$fid] = PHDB::findOne( Form::COLLECTION, [ "id"=>$fid ] );
}
$params["forms"][$fix]["answers"] = PHDB::count( Form::ANSWER_COLLECTION, ["formId"=>$formId] );
}
}
//$forms = PHDB::find(Form::COLLECTION,["costum.form"=>[]])
echo $this->getController()->renderPartial('survey.views.tpls.forms.oforms', $params, true);
}
}
\ No newline at end of file
<?php
class AllAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//if $id : opens the forms
public function run($form)
{
$controller=$this->getController();
$controller->layout = "//layouts/empty";
$tpl=(!empty($params["parentForm"]["answersTpl"])) ? $params["parentForm"]["answersTpl"] : 'survey.views.tpls.forms.cplx.answers';
$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]);
$params["forms"][$formId] = $f;
}
$params["what"] = "propositions";
$el = Slug::getElementBySlug( $params["form"]["parentSlug"] );
$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['canEdit'] = ( isset(Yii::app()->session["userId"]) && isset($el["type"]) && isset($el["id"]) ) ?
Authorisation::canEditItem(Yii::app()->session["userId"],$el["type"], $el["id"])
: false ;
$params["wizid"] = $form;
if(Yii::app()->request->isAjaxRequest)
echo $controller->renderPartial( $tpl , $params, true);
else
echo $controller->render( $tpl , $params, true);
}
}
\ No newline at end of file
<?php
class OformsAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//if $id : opens the forms
public function run($slug = null,$form=null)
{
$controller=$this->getController();
if(!empty($slug)){
$controller->layout = "//layouts/empty";
$tpl = 'survey.views.tpls.forms.oforms';
$el = Slug::getElementBySlug($slug);
$params = [ "el"=>$el["el"] ];
$params["forms"] = PHDB::find( Form::COLLECTION, [ "parentSlug"=>$slug ] );
//$params["forms"][0]["name"] = "todo COForms name";
//var_dump($el["el"]["costum"]["form"]); exit;
if(isset($params["forms"]))
{
foreach ( $params["forms"] as $fix => $f )
{
$params["forms"][$fix]["name"] = "todo COForms name";
$formId = "";
if(isset($f['ids'])){
foreach ($f['ids'] as $ix => $fid)
{
if($formId != "")
$formId .= "|";
$formId .= $fid;
$params["forms"][$fix][$fid] = PHDB::findOne( Form::COLLECTION, [ "id"=>$fid ] );
}
}
$params["forms"][$fix]["answers"] = PHDB::count( Form::ANSWER_COLLECTION, ["formId"=>$formId , "parentSlug" => $slug] );
}
}
}
// IS IT IMPORTANT TO OPEN A FORM WITHOUT AN ANSWER
// else if(!empty($form))
// {
// $controller->layout = "//layouts/mainSearch";
// $canEdit = false;
// if( isset(Yii::app()->session["userId"]) && isset($controller->costum["contextType"]) && isset($controller->costum["contextId"]) )
// $canEdit = Authorisation::canEditItem(Yii::app()->session["userId"],@$controller->costum["contextType"], @$controller->costum["contextId"]);
// //TODO if no canEdit et test exist then
// //redirect unTpl
// $params = ["canEdit" => $canEdit];
// if( isset($test) ){
// $params["tpl"]=$id;
// $params["test"]=$test;
// }
// if(isset($_GET["form"]))
// $params = Form::getDataForAnswer($params);
// $params['el'] = Slug::getElementBySlug( $params["parentForm"]["parentSlug"] )["el"];
// $tpl=(!empty($params["parentForm"]["tpl"])) ? $params["parentForm"]["tpl"] : "survey.views.tpls.forms.formWizard";
// }
//var_dump($params);exit;
if(Yii::app()->request->isAjaxRequest)
echo $controller->renderPartial( $tpl , $params, true);
else
echo $controller->render( $tpl , $params, true);
}
}
\ No newline at end of file
...@@ -646,12 +646,12 @@ class Form { ...@@ -646,12 +646,12 @@ class Form {
return false; return false;
} }
public static function getFormData($params){ public static function getFormData($params){
$costum = CacheHelper::getCostum();
//WARNING la c'est bien data que l'on veut //WARNING la c'est bien data que l'on veut
if(isset($costum["form"]["rules"])){ if(isset($params["parentForm"]["rules"])){
foreach ($params["formList"] as $k => $value) { foreach ($params["formList"] as $k => $value) {
if(isset($costum["form"]["rules"][$value])){ if(isset($params["parentForm"]["rules"][$value])){
if(!self::canFormAccess($costum["form"]["rules"][$value])){ if(!self::canFormAccess($params["parentForm"]["rules"][$value])){
array_splice($params["formList"], $k, -1); array_splice($params["formList"], $k, -1);
} }
} }
...@@ -684,7 +684,7 @@ class Form { ...@@ -684,7 +684,7 @@ class Form {
Yii::app()->session["budgetInputList"] = $budgetInputList; Yii::app()->session["budgetInputList"] = $budgetInputList;
//var_dump($budgetInputList); //var_dump($budgetInputList);
//use the cache //use the cache
Yii::app()->session["forms"] = $allforms; $params["forms"] = $allforms;
return $params; return $params;
} }
...@@ -706,11 +706,15 @@ class Form { ...@@ -706,11 +706,15 @@ class Form {
$params["el"] = Element::getByTypeAndId($costum["contextType"], $costum["contextId"] ); $params["el"] = Element::getByTypeAndId($costum["contextType"], $costum["contextId"] );
$params["el"]["id"] = $costum["contextId"]; $params["el"]["id"] = $costum["contextId"];
} }
//if(isset($_GET["form"]))
$form = (isset($costum['form'])) ? $costum['form'] : PHDB::findOne( Form::COLLECTION, [ "_id" => new MongoId($_GET["form"]) ] );
if(isset($costum["hasOpenForm"])){ $params["parentForm"] = $form;
if(isset($costum["isMultiForms"])){
if(isset($costum["hasOpenForm"]))
{
if(isset($costum["isMultiForms"]))
{
$answerId=null; $answerId=null;
$answer=null; $answer=null;
$generateAnswer = false; $generateAnswer = false;
...@@ -727,8 +731,8 @@ class Form { ...@@ -727,8 +731,8 @@ class Form {
$params["formList"] = explode("|", $answer["formId"]); $params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"]; $params["formId"] = $answer["formId"];
}else if(isset($costum["form"])){ }else if(isset($form)){
$params["formList"] = $costum["form"]["ids"]; $params["formList"] = $form["ids"];
$params["formId"] = implode("|", $params["formList"]); $params["formId"] = implode("|", $params["formList"]);
} }
$params=self::getFormData($params); $params=self::getFormData($params);
...@@ -736,7 +740,7 @@ class Form { ...@@ -736,7 +740,7 @@ class Form {
if(isset($_GET["form"])) if(isset($_GET["form"]))
$params["formId"] = $_GET["form"]; $params["formId"] = $_GET["form"];
else else
$params["formId"] = (isset($costum["form"]["id"])) ? $costum["form"]["id"] : Form::generateOpenForm( $el["slug"] ); $params["formId"] = (isset($form["id"])) ? $form["id"] : Form::generateOpenForm( $el["slug"] );
} }
...@@ -753,7 +757,7 @@ class Form { ...@@ -753,7 +757,7 @@ class Form {
if(!isset($costum["form"]["oneAnswerPerPerson"]) || count($myAnswers) == 0){ if(!isset($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] ];
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
<a href="#dashboard" class='lbh btn btn-default'><i class="fa fa-area-chart"></i> Observatoire Global</a> <a href="#dashboard" class='lbh btn btn-default'><i class="fa fa-area-chart"></i> Observatoire Global</a>
<a href="javascript:;" id="globalCommunityBtn" class=' btn btn-default'><i class="fa fa-group"></i> Communauté</a> <a href="javascript:;" id="globalCommunityBtn" class=' btn btn-default'><i class="fa fa-group"></i> Communauté</a>
</div> </div>
<?php
<div id="allAnswersContainer" class="hide col-xs-12 col-lg-offset-2 col-lg-8 margin-top-20"> $showClass = ($this->module->id == "survey" && Yii::app()->controller->id == "answer" && Yii::app()->controller->action->id == "all" ) ? "" : "hide";
?>
<div id="allAnswersContainer" class="<?php $showClass ?> col-xs-12 col-lg-offset-2 col-lg-8 margin-top-20">
<ul id="allAnswersList"> <ul id="allAnswersList">
<?php <?php
$lbl = $what." "; $lbl = $what." ";
...@@ -43,7 +45,8 @@ ...@@ -43,7 +45,8 @@
$totalInputs = 0; $totalInputs = 0;
$answeredInputs = 0; $answeredInputs = 0;
//var_dump(Yii::app()->session["forms"]); //var_dump(Yii::app()->session["forms"]);
foreach (Yii::app()->session["forms"] as $fid => $f)
foreach ($forms as $fid => $f)
{ {
$totalInputs += count($f["inputs"]); $totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]); //echo "|".$f['id']."-fi=".count($f["inputs"]);
......
<div class="col-md-12 col-sm-12 col-xs-12 labelTitleDir margin-bottom-15"> <div class="col-md-12 col-sm-12 col-xs-12 labelTitleDir margin-bottom-15">
<i class="fa fa-file-text-o fa-2x margin-right-10"></i> <i class="fa fa-angle-down"></i> <?php echo count($forms) ?> <b>Open Forms</b> créé par <span class="Montserrat" id="name-lbl-title">SOMMOM</span> <i class="fa fa-file-text-o fa-2x margin-right-10"></i> <i class="fa fa-angle-down"></i> <?php echo count($forms) ?> <b>Open Forms</b> créé par <span class="Montserrat" id="name-lbl-title"><?php echo $el["name"] ?></span>
<button class="btn btn-sm btn-link bg-green-k pull-right btn-open-form" data-form-type="classifieds" data-dismiss="modal"><i class="fa fa-plus"></i> Nouveau Formulaire</button> <a href='javascript:dyFObj.openForm(oform);' class="btn btn-sm btn-link bg-green-k pull-right "><i class="fa fa-plus"></i> Nouveau Formulaire</a>
<div class="col-xs-12 text-right no-padding margin-top-5">
<button class="btn switchDirectoryView margin-right-5" data-value="list"><i class="fa fa-bars"></i></button>
<button class="btn switchDirectoryView active " data-value="block"><i class="fa fa-th-large"></i></button>
</div>
</div> </div>
<?php foreach ($forms as $fix => $f) { <?php
$ct = 0;
foreach ($forms as $fix => $f) {
if($ct == 0)
echo '<div class="row ">';
?> ?>
<div class="col-md-4 col-sm-3 col-xs-12 " style="padding:10px;border:1px solid grey"> <div class="col-md-4 col-sm-3 col-xs-12 " style="padding:5px;">
steps : <br/> <div class="col-xs-12 " style="padding:10px;border:1px solid grey">
<?php foreach ( $f["ids"] as $ix => $i ) { steps : <br/>
echo '<i class="fa fa-file-text-o"></i> '.$f[$i]['name']."<br/>"; <?php
}?> if(isset($f['ids'])){
<a href='' style="width:40%;border:1px solid grey"> foreach ( $f["ids"] as $ix => $i ) {
<i class='fa fa-comments'></i>(<?php echo $f["answers"]; ?>) réponses echo '<i class="fa fa-file-text-o"></i> '.$f[$i]['name']."<br/>";
</a> }
<a href='' style="width:40%;border:1px solid grey"> }?>
<i class='fa fa-file-text-o'></i> Questionnaire <a href='javascript:;' data-id='<?php echo $fix ?>' class="showAnswersBtn btn btn-xs btn-default col-sm-4 col-sm-12 bold">
</a> <i class='fa fa-comments'></i>(<?php echo $f["answers"]; ?>) RÉPONSES
</a>
<a href='javascript:;' data-id='<?php echo $fix ?>' class="configBtn btn btn-xs btn-danger col-sm-4 col-sm-12 bold">
<i class='fa fa-cogs'></i> CONFIG
</a>
<a href='costum/co/index/slug/<?php echo $el["slug"] ?>/form/<?php echo $fix ?>' class="btn btn-xs btn-primary col-sm-4 col-xs-12 bold">
<i class='fa fa-file-text-o'></i> RÉPONDRE
</a>
</div>
</div> </div>
<?php } ?> <?php
$ct++;
if($ct == 3){
echo "</div>";
$ct = 0;
}
} ?>
<script type="text/javascript">
var tplCtx = {};
jQuery(document).ready(function() {
mylog.log("render","/modules/costum/views/tpls/forms/cplx/answers.php");
$('.showAnswersBtn').off().on("click",function() {
getAjax("#central-container",baseUrl+"/survey/answer/all/form/"+$(this).data("id"),function(){
},"html");
});
$('.configBtn').off().on("click",function() {
tplCtx.id = $(this).data("id");
dyFObj.openForm(oformParams)
});
});
var oform = {
jsonSchema : {
title : "Créer un Questionnaire",
description : "Tout est possible, faut juste poser les bonnes questions",
icon : "fa-question",
properties : {
name : { label : "Nom du formulaire"},
// sections : {
// inputType : "array",
// label : "Nommé chaque étape de votre questionnaire",
// subLabel : "Vous remplirez les question de chaques étapes par la suite",
// values : []
// },
image : dyFInputs.image(),
id : { inputType : "hidden",value:"<?php echo $el["slug"].count($forms) ?>"},
parentSlug : { inputType : "hidden",value:"<?php echo $el["slug"] ?>"},
tpl : { inputType : "hidden",value:"survey.views.tpls.forms.formWizard"},
answersTpl : { inputType : "hidden",value:"survey.views.tpls.forms.answers"}
},
beforeBuild : function(){
dyFObj.setMongoId('forms',function(){
uploadObj.gotoUrl = '#page.type.forms.id.'+uploadObj.id;
});
},
afterSave : function(){
dyFObj.commonAfterSave();
},
save : function () {
tplCtx = {
collection : "forms",
value : {}
};
$.each( oform.jsonSchema.properties , function(k,val) {
if(val.inputType == "properties")
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array")
tplCtx.value[k] = getArray('.'+k+val.inputType);
else
tplCtx.value[k] = $("#"+k).val();
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
});
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
urlCtrl.loadByHash(location.hash);
} );
}
}
}
};
var oformParams = {
jsonSchema : {
title : "Configurer le Questionnaire",
description : "lisez bien les options",
icon : "fa-question",
properties : {
private : { inputType : "checkboxSimple",
label : "Privé",
subLabel : "Seul la communauté peut éditer ce questionnaire",
params : { onText : "Oui", offText : "Non", onLabel : "Oui", offLabel : "Non",
labelText : "Privé"
},
checked : false },
canReadOtherAnswers: { inputType : "checkboxSimple",
label : "Réponses Ouvertes à la lecture",
subLabel : "Les réponses sont elles ouverte à la lecture public",
params : { onText : "Oui",offText : "Non",onLabel : "Oui",offLabel : "Non",
labelText : "Réponses Ouvertes"
},
checked : false },
startDate: {
inputType : "date",
label : "Date de début",
},
endDate: {
inputType : "date",
label : "Date de fin"
},
oneAnswerPerPers: {inputType : "checkboxSimple",
label : "Bloquer à une réponse par personne",
subLabel : "Une personne ne pourra répondre qu'une seule fois",
params : { onText : "Oui",offText : "Non",onLabel : "Oui",offLabel : "Non",
labelText : "Réponse unique"
},
checked : false },
canModify : { inputType : "checkboxSimple",
label : "Réponse Modifiable",
subLabel : "une fois soumise les réponses sont elles modifiables",
params : { onText : "Oui",offText : "Non",onLabel : "Oui",offLabel : "Non",
labelText : "Réponse Modifiable"
},
checked : false },
showAnswers: {inputType : "checkboxSimple",
label : "Réponse Affichés",
subLabel : "Les réponses sont elles affichés publiquement",
params : { onText : "Oui",offText : "Non",onLabel : "Oui",offLabel : "Non",
labelText : "Réponse Affichés"
},
checked : false },
},
save : function () {
tplCtx.collection = "forms";
tplCtx.value = {};
$.each( oform.jsonSchema.properties , function(k,val) {
if(val.inputType == "properties")
tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
else if(val.inputType == "array")
tplCtx.value[k] = getArray('.'+k+val.inputType);
else
tplCtx.value[k] = $("#"+k).val();
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
});
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == "undefined")
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
urlCtrl.loadByHash(location.hash);
} );
}
}
}
};
</script>
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