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

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

parents 649e14b2 94331ee9
......@@ -27,7 +27,8 @@ 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"]["ids"]) , "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"])
: false ;
......
......@@ -65,12 +65,14 @@ class IndexAction extends CAction
}
// var_dump($canEditAnswer);
// var_dump($canSeeAnswer);
if($canEditAnswer === true || $canSeeAnswer === true){
$params["canEditForm"] = $canEditForm;
$params["canEdit"] = $canEditAnswer;
$params["canSee"] = $canSeeAnswer;
$params["mode"] = (!empty($mode) ? $mode : "r");
//$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
//Rest::json($params); exit;
$tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
} else {
......
<?php
class NewAction extends CAction
{
public function run($id=null, $tpl=null)
public function run($id=null, $type=null , $tpl=null)
{
$this->getController()->layout = "//layouts/empty";
$params = array();
if(!empty($id))
$params["idForm"] = $id;
else{
if(!empty($this->getController()->costum) && !empty($this->getController()->costum["slug"])){
$form = PHDB::findOne(Form::COLLECTION, array("parentSlug" => $this->getController()->costum["slug"] ) ) ;
$params["idForm"] = (String) $form["_id"];
}
//var_dump($this->getController()->costum["slug"]); exit;
if(empty($params["idForm"]) && !empty($this->getController()->costum) && !empty($this->getController()->costum["contextId"])){
$form = PHDB::findOne(Form::COLLECTION, array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1)) ) ;
$params["idForm"] = (String) $form["_id"];
}
}
if(!empty($id) && !empty($type)){
$params["forms"] = PHDB::find(Form::COLLECTION,
array("parent.".$id ),
array("name") ) ;
} else if( !empty($this->getController()->costum) ){
$params["forms"] = PHDB::find(Form::COLLECTION,
array('$and' => array(
array("active" => true),
array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1))
// array('$or' => array(
// array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1) ),
// array("source.keys" => array('$in' => array($this->getController()->costum["slug"]) ) )
// ) )
)),
array("name") ) ;
}
//var_dump($this->getController()->costum); exit;
$tpl= "survey.views.tpls.views.new";
echo $this->getController()->renderPartial($tpl,$params );
......
......@@ -25,7 +25,15 @@ class DirectoryAction extends CAction
"slug" => $_POST["slug"] );
$searchRegExp = Search::accentToRegex($search);
$query=array("parentSlug"=>$slug);
//$query=array("parentSlug"=>$slug);
$forms = PHDB::find(Form::COLLECTION, array("parent.".$_POST["id"] => array('$exists' => 1 ) ) , array("name") );
$idFs = array();
foreach ($forms as $keyF => $valF) {
$idFs[] = $keyF;
}
$query=array( "form"=>array('$in' => $idFs) );
//Rest::json($query); exit;
$querySearch = array();
if(!empty($querySearch))
$query = array('$and' => array( $query , $querySearch ) ) ;
......@@ -34,16 +42,16 @@ class DirectoryAction extends CAction
$query = Search::searchFilters($panelAdmin['filters'], $query);
}
$params["typeDirectory"]=[ Form::ANSWER_COLLECTION ];
$params["typeDirectory"]=[ Answer::COLLECTION ];
$params["results"] = array();
$answers = PHDB::findAndLimitAndIndex ( Form::ANSWER_COLLECTION , $query, $stepLim, $limitMin);
$answers = PHDB::findAndLimitAndIndex ( Answer::COLLECTION , $query, $stepLim, $limitMin);
$answerList = Form::listForAdmin($answers) ;
foreach ($answerList as $key => $value) {
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION));
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Answer::COLLECTION));
}
$params["results"]["count"][Form::ANSWER_COLLECTION] = PHDB::count( Form::ANSWER_COLLECTION , $query);
$params["results"]["count"][Answer::COLLECTION] = PHDB::count( Answer::COLLECTION , $query);
$params["results"][Form::ANSWER_COLLECTION] = $answerList ;
$params["results"][Answer::COLLECTION] = $answerList ;
$params["panelAdmin"] = $panelAdmin;
$page = "groupAdmin";
if($tpl=="json")
......
......@@ -12,9 +12,12 @@ class DeleteAction extends CAction
{
// if( Authorisation::isElementAdmin($id, Form::ANSWER_COLLECTION, Yii::app()->session["userId"], false)) {
if(isset($form["ids"])){
$formId = implode("|", $form["ids"]);
PHDB::remove( Form::ANSWER_COLLECTION, ["formId" => $formId]);
if(isset($form["ids"]))
{
PHDB::remove( Form::ANSWER_COLLECTION, ["formId" => implode("|", $form["ids"]) ]);
foreach ($form["ids"] as $ix => $fid) {
PHDB::remove( Form::COLLECTION, ["id" => $fid]);
}
}
PHDB::remove( Form::COLLECTION, ["_id" => new MongoId($id)] );
echo Rest::json(['result' => true ]);
......
<?php
class EditAction extends CAction
{
public function run($id=null, $answer=null, $tpl=null)
public function run($id=null, $answer=null)
{
$this->getController()->layout = "//layouts/empty";
$params = array("canEdit" => true, "showAnswerActions"=>false);
$params = Form::getDataForAnswer($params);
$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.views.index";
$params["mode"]="w";
echo $this->getController()->renderPartial($tpl,$params );
// $this->getController()->layout = "//layouts/empty";
// $params = array("canEdit" => true, "showAnswerActions"=>false);
// $params = Form::getDataForAnswer($params);
// $tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.views.index";
// $params["mode"]="w";
// echo $this->getController()->renderPartial($tpl,$params );
$this->getController()->layout = "//layouts/empty";
$params = array();
if(!empty($id) && !empty(Yii::app()->session["userId"]) ){
$form = PHDB::findOneById( Form::COLLECTION , $id);
$canEditForm = Form::canAdmin(Yii::app()->session['userId'], $form);
if($canEditForm === true){
if(!empty($answer)){
$params["answerId"]=$answer;
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($answer)));
} else {
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("form"=>$id, "draft" => true));
if(empty($answer))
$answer = Answer::generateAnswer($form, true);
$params["answerId"] = (String) $answer["_id"];
}
$params["form"] = $form ;
//Rest::json($params); exit;
$params = Form::getDataForAnswer($params);
$params["answer"] = $answer;
$params["canEditForm"] = $canEditForm;
$params["canEdit"] = true;
$params["canSee"] = true;
$params["showForm"] = true;
$params["mode"] = "fa";
$tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
} else {
if(Yii::app()->request->isAjaxRequest)
echo $this->getController()->renderPartial("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
else
$this->getController()->render("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
}
} else {
if(Yii::app()->request->isAjaxRequest)
echo $this->getController()->renderPartial("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
else
$this->getController()->render("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
}
}
}
......
......@@ -15,8 +15,8 @@ class GetAction extends CTKAction
$tpl = 'survey.views.tpls.forms.oforms';
$el = Slug::getElementBySlug($slug);
$params = [ "el"=>$el["el"] ];
$params["forms"] = PHDB::find( Form::COLLECTION, [ "parentSlug"=>$slug ] );
//$params["forms"] = PHDB::find( Form::COLLECTION, [ "parentSlug"=>$slug ] );
$params["forms"] = PHDB::find( Form::COLLECTION, [ "parent.".$el["id"] => array('$exists' => 1) ] );
//$params["forms"][0]["name"] = "todo COForms name";
//var_dump($el["el"]["costum"]["form"]); exit;
if(isset($params["forms"]))
......@@ -34,7 +34,9 @@ class GetAction extends CTKAction
$params["forms"][$fix][$fid] = PHDB::findOne( Form::COLLECTION, [ "id"=>$fid ] );
}
}
$params["forms"][$fix]["answers"] = PHDB::count( Form::ANSWER_COLLECTION, ["formId"=>$formId , "parentSlug" => $slug] );
// $params["forms"][$fix]["answers"] = PHDB::count( Form::ANSWER_COLLECTION, ["formId"=>$formId , "parentSlug" => $slug] );
$params["forms"][$fix]["answers"] = PHDB::count( Answer::COLLECTION, ["form"=>$fix] );
}
}
......
......@@ -10,7 +10,7 @@ class Answer{
}
public static function generateAnswer($form){
public static function generateAnswer($form, $draft = false){
$costum = CacheHelper::getCostum();
//Rest::json($costum); exit;
$ans = [
......@@ -22,19 +22,24 @@ class Answer{
],
"created" => time()
];
if(isset($costum["contextType"]) && isset($costum["contextId"])){
$ans["parentSlug"] = Slug::getSlugByIdAndCol($costum["contextId"], $costum["contextType"]);
}
if($draft === true)
$ans["draft"] = true;
$formList = null ;
if( !empty($form) ){
$formList = $form["ids"];
$ans["form"] = (String)$form["_id"];
$ans["formId"] = implode("|", $formList);
$ans["formList"] = count($formList);
if(!empty($form["ids"])){
$formList = $form["ids"];
$ans["formId"] = implode("|", $formList);
$ans["formList"] = count($formList);
}
//$ans["step"] = $formList[0];
}
//var_dump($form); exit;
//Rest::json($costum); exit;
if(!empty($costum) && !empty($costum["slug"]) ) {
$ans["source"] = Costum::getSource($costum["slug"]);
}
//Rest::json($ans); exit;
if(Costum::isSameFunction("generateAnswerBeforeSave")){
$paramBeforeSave=Costum::sameFunction("generateAnswerBeforeSave",
array("answer" => $ans, "formList"=>$formList) );
......
......@@ -439,11 +439,13 @@ class Form {
return false;
}
public static function canEditAnswer($userId, $answer, $form, $parentForm){
public static function canEditAnswer($userId, $answer, $form, $parentForm = null){
if(self::canAdmin((string)$form["_id"], $form))
return true;
else if($answer["user"] == $userId)
return true;
else if ( self::canAdmin((string)$form["_id"], $form) )
return true;
// else if(Authorisation::canEditItem(Yii::app()->session["userId"], $parentForm["type"], $answer["_id"] ))
// return true;
// else if(Costum::sameFunction("canEditAnswer", array("answer"=>$answer)))
......@@ -684,17 +686,19 @@ class Form {
{
$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(isset($f["inputs"])){
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;
}
}
}
}
......@@ -706,14 +710,31 @@ class Form {
return $params;
}
public static function getListAnswersBy($formId, $parent, $userId=null, $cond=null){
$where=array("formId"=> $formId, "parentSlug" => $parent);
if(!empty($userId)){
// public static function getListAnswersBy($formId, $parent, $userId=null, $cond=null){
// $where=array("formId"=> $formId, "parentSlug" => $parent);
// if(!empty($userId)){
// $where["user"]=$userId;
// }
// if(!empty($cond))
// $where=array('$and'=> array($where, $cond));
// $lists=PHDB::find( Form::ANSWER_COLLECTION, $where);
// return $lists;
// }
public static function getListAnswersBy($form=null, $costum=null, $userId=null, $cond=null){
$where = array();
$lists = array();
if(!empty($form))
$where["form"]=$form;
if(!empty($costum))
$where["source.keys"]=array('$in' => array($costum) );
if(!empty($userId))
$where["user"]=$userId;
}
if(!empty($cond))
if(!empty($cond)){
$where=array('$and'=> array($where, $cond));
$lists=PHDB::find( Form::ANSWER_COLLECTION, $where);
}
if(!empty($where))
$lists=PHDB::find( Answer::COLLECTION, $where);
return $lists;
}
public static function getDataForAnswer($params){
......@@ -748,11 +769,11 @@ class Form {
if(!empty($answerId) && $answerId !="new")
$answer = self::getAnswerById($answerId);
//var_dump($answer);exit;
if(!empty($answer)){
if(!empty($answer) && !empty($answer["formId"] )){
$params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"];
}else if(isset($form)){
}else if(isset($form) && !empty($form["ids"]) ){
$params["formList"] = $form["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
......@@ -763,22 +784,23 @@ class Form {
else
$params["formId"] = (isset($form["id"])) ? $form["id"] : Form::generateOpenForm( $el["slug"] );
}
// $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"]))
if(!isset($params["el"]) && !empty($answer) && isset($answer["parentSlug"]))
$params["el"]=Slug::getElementBySlug($answer["parentSlug"])["el"];
$showForm = true;
if(!empty($params["formId"])){
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if( !isset($params["el"]) && !empty($answer) && isset($answer["parent"]) ){
foreach ($answer["parent"] as $keyP => $valP) {
$params["el"]=Element::getElementById($keyP, $valP["type"], null, array() );
}
}
$showForm = true;
if(!isset($form["oneAnswerPerPerson"]) || count($myAnswers) == 0){
//Rest::json($params); exit;
//if(!empty($params["formId"])){
// $myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
$myAnswers = self::getListAnswersBy((String)$form["_id"], null, Yii::app()->session["userId"]);
if(!isset($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] ];
......@@ -796,18 +818,17 @@ class Form {
$showForm = false;
$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;
$params["answer"] = $answer;
$params["showForm"] = $showForm;
$params["showAnswerActions"]=(isset($params["showAnswerActions"])) ? $params["showAnswerActions"] : true;
// $allAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"] ) ;
$allAnswers = self::getListAnswersBy($form) ;
$params["allAnswers"] = (isset($allAnswers)) ? $allAnswers : [] ;
} 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>";
}
}
//}
}
}
......
<?php
if($canEditForm === true){
$subFormIds = [];
if(isset($form["ids"]))
$subFormIds = array_merge( $subFormIds, $form["ids"] );
?>
<div class="col-xs-12 padding-10 text-center bg-info">
<h4>Admin Form</h4>
<a href='javascript:;' data-id='<?php echo (String)$form["_id"]; ?>' class="configBtn btn btn-danger bold">
<i class='fa fa-cogs'></i> CONFIG
</a>
</div>
<?php
}
?>
<script type="text/javascript">
var tplCtx = {};
var form = <?php echo (!empty($form)) ? json_encode( $form ) : "null"; ?>;
var subForms = <?php echo json_encode($subFormIds)?>;
jQuery(document).ready(function() {
mylog.log("render","/modules/costum/views/tpls/forms/cplx/answers.php");
$('.configBtn').off().on("click",function() {
tplCtx.id = $(this).data("id");
mylog.log( "configBtn", tplCtx.id );
dyFObj.openForm( oformParams, null, form )
});
});
var oformParams = {
jsonSchema : {
title : "Configurer le Questionnaire",
description : "lisez bien les options",
icon : "fa-question",
properties : {
active : {
inputType : "checkboxSimple",
label : "Activé (Ouvert aux Réponses)",
subLabel : "Activer pour partagé et ouvrir le questionnaire aux réponses.",
params : { onText : "Oui", offText : "Non", onLabel : "Oui", offLabel : "Non",
labelText : "Activé"},
checked : false },
ids : {
inputType : "array",
label : "Nommé chaque étape de votre questionnaire",
//subLabel : "Vous remplirez les question de chaques étapes par la suite",
value : []
},
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 : true },
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 : true },
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 : true },
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 : true },
},
beforeBuild : function(){
dyFObj.setMongoId('forms',function(){
uploadObj.gotoUrl = '#page.type.forms.id.'+uploadObj.id;
});
},
save : function (formData) {
//mylog.log('save tplCtx formData', formData)
tplCtx.collection = "forms";
tplCtx.path = "allToRoot";
tplCtx.value = {};
$.each( oformParams.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);
if(k=="ids"){
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 ={
collection : "forms",
value : {
id : newFormId,
name : fName,
type : "openForm",
inputs : {}
}
};
dataHelper.path2Value( newForm, function() {
mylog.log("created new sub Form",newFormId);
} );
cx++;
}
})
}
}
else
tplCtx.value[k] = $("#"+k).val();
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
});
mylog.log("oformParams 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>
\ No newline at end of file
......@@ -13,7 +13,7 @@ if($saveOneByOne)
}
?>
<div class="form-check">
<label class="form-check-label" for="<?php echo $key ?>"><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?></h4></label>