Commit 3107435a authored by Raph El's avatar Raph El

Form : Remove "parentSlug"

parent ddc1bcf3
......@@ -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 ;
......
<?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('$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")
......
......@@ -14,8 +14,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"]))
......@@ -33,7 +33,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( Form::ANSWER_COLLECTION, ["form"=>$fix] );
}
}
......
......@@ -22,19 +22,22 @@ class Answer{
],
"created" => time()
];
if(isset($costum["contextType"]) && isset($costum["contextId"])){
$ans["parentSlug"] = Slug::getSlugByIdAndCol($costum["contextId"], $costum["contextType"]);
}
$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) );
......
......@@ -422,11 +422,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)))
......@@ -689,14 +691,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){
......@@ -731,11 +750,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($answer["formId"]) ){
$params["formList"] = $form["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
......@@ -746,22 +765,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"];
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(!empty($params["formId"])){
$myAnswers = self::getListAnswersBy($params["formId"], $params["el"]["slug"], Yii::app()->session["userId"]);
if(!isset($form["oneAnswerPerPerson"]) || count($myAnswers) == 0){
// $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] ];
......@@ -779,13 +799,12 @@ 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>";
......
......@@ -34,10 +34,13 @@ if( !isset($parentForm["startDate"]) ||
} else if( count($myAnswers) == 0 ) {
echo "<h4>Bienvenue vous n'avez pas encore participer.</h4>";
$countTotalAnswers = PHDB::count( Form::ANSWER_COLLECTION,[ "formId" => $formId,
"parentSlug" => $el["slug"] ] );
$countdistinctUsers = count(PHDB::distinct( Form::ANSWER_COLLECTION,"user",[ "formId" => $formId,
"parentSlug" => $el["slug"] ] ));
// $countTotalAnswers = PHDB::count( Form::ANSWER_COLLECTION,[ "formId" => $formId,
// "parentSlug" => $el["slug"] ] );
// $countdistinctUsers = count(PHDB::distinct( Form::ANSWER_COLLECTION,"user",[ "formId" => $formId,
// "parentSlug" => $el["slug"] ] ));
$countTotalAnswers = PHDB::count( Answer::COLLECTION,[ "form" => (String)$form['_id'] ] );
$countdistinctUsers = count(PHDB::distinct( Answer::COLLECTION,"user",[ "form" => (String)$form['_id'] ] ));
if($countTotalAnswers == 0)
echo "<br/>Soyez le premier à répondre!!!";
else
......@@ -45,9 +48,15 @@ if( !isset($parentForm["startDate"]) ||
echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/new/true'>Participer</a>";
} else {
echo "<h4>Vous avez deja participer, vous pouvez retoucher vos ".PHDB::count( Form::ANSWER_COLLECTION,[ "formId" => $formId,
"parentSlug" => $el["slug"],
"user" => Yii::app()->session["userId"] ] )." réponses dans la liste.</h4>";
// echo "<h4>Vous avez deja participer, vous pouvez retoucher vos ".PHDB::count( Form::ANSWER_COLLECTION,[ "formId" => $formId,
// "parentSlug" => $el["slug"],
// "user" => Yii::app()->session["userId"] ] )." réponses dans la liste.</h4>";
echo "<h4>Vous avez deja participer, vous pouvez retoucher vos ".
PHDB::count( Form::ANSWER_COLLECTION,
[ "form" => (String)$form['_id'],
"user" => Yii::app()->session["userId"] ] ).
" réponses dans la liste.</h4>";
echo "<a class='btn btn-primary' href='/costum/co/index/slug/".$el["slug"]."/new/true'>Ajouter une réponse</a>";
}
......
......@@ -286,7 +286,7 @@ var answerObj = <?php echo (!empty($answer)) ? json_encode( $answer ) : "null";
];
echo $this->renderPartial("survey.views.tpls.answers.allAnswers",$params);
}
//if($showForm){
if(!empty($showForm)) {
$params = [
"formList"=>$formList,
"el" => $el,
......@@ -299,10 +299,10 @@ var answerObj = <?php echo (!empty($answer)) ? json_encode( $answer ) : "null";
];
echo $this->renderPartial("survey.views.tpls.forms.wizard",$params);
// } else {
// echo "<h4 class='text-center' style='color:".$color1."'><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>";
// }
} else {
echo "<h4 class='text-center' style='color:".$color1."'><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>";
}
?>
</div>
......
<?php
//var_dump($answer);
//var_dump($saveOneByOne);
$saveOneByOne = (isset($saveOneByOne)) ? $saveOneByOne :false;
if( isset( $form["inputs"] ) ){ ?>
<form id="formQuest">
......@@ -148,38 +148,6 @@ jQuery(document).ready(function() {
mylog.log("render","/modules/survey/views/tpls/forms/formbuilder.php");
<?php if(!$saveOneByOne){
//if form contains just one cplx input then all saves are made oneByone?>
$( "#openFormSubmit" ).off().on( "click", function( event ) {
event.preventDefault();
$("#openFormSubmit").html("<i class='fa fa-spin fa-spinner'></i>Veuillez Patienter nous traitons vos données")
var answer = {
value:{
formId : "<?php echo $formId ?>",
type : "openForm",
"answers":{},
user : userId,
parentSlug : "<?php echo $el["slug"] ?>"
}
};
$("form#formQuest :input").each(function(){
if(typeof $(this).attr("id") != "undefined" && $(this).val() != "" )
answer.value.answers[ $(this).attr("id") ] = $(this).val();
});
mylog.log("#openFormSubmit", answer );
answer.collection = "answers";
if($(this).data("id"))
answer.id = $(this).data("id");
dataHelper.path2Value( answer , function(params) {
$("form#formQuest").html("<h2>Merci de votre participation!!</h2><a href='javascript:;'>Voir toutes les réponses</a>");
//location.reload();
} );
});
<?php } else {
//here answer allready exists is only completed by small updates
?>
$( ".saveOneByOne" ).off().on( "blur", function( event ) {
event.preventDefault();
//toastr.info('saving...'+$(this).attr("id"));
......@@ -211,8 +179,6 @@ jQuery(document).ready(function() {
}
});
<?php } ?>
if(initValues){
$.each(initValues, function(k,inp) {
if(inp.type == "tags"){
......
......@@ -72,7 +72,6 @@ var oform = {
// },
image : dyFInputs.image(),
formid : { inputType : "hidden",value:"<?php echo $el["slug"].count($forms) ?>"},
parentSlug : { inputType : "hidden",value:"<?php echo $el["slug"] ?>"},
parent : {
inputType : "finder",
label : tradDynForm.whoiscarrytheproject,
......
......@@ -2,34 +2,36 @@
<h2 class="text-center">Déposer une candidature</h2>
<div class="col-sm-10 col-sm-offset-1">
<h4>Etape</h4>
<div class="col-xs-12">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas id fringilla nulla. Sed commodo tellus vestibulum condimentum mollis. Integer sit amet ex vel lectus posuere maximus. Duis diam justo, convallis ac ultricies pellentesque, porttitor quis nunc. Pellentesque finibus purus sit amet ipsum sagittis vehicula. Nunc laoreet laoreet purus, condimentum efficitur augue vestibulum eu. Suspendisse purus dui, commodo sed nibh a, faucibus semper ipsum. Curabitur in blandit odio, eget placerat ex. In porttitor quis sem vel vestibulum. Vivamus eget facilisis enim.
<br/><br/>
Quisque eu molestie risus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi non nunc orci. Phasellus velit turpis, cursus scelerisque est id, rhoncus lacinia turpis. Etiam quis venenatis odio. Nam sollicitudin elementum faucibus. Ut pulvinar mi sit amet ante scelerisque, sit amet tempor enim sodales. Praesent imperdiet sit amet dolor vitae laoreet.
<br/><br/>
Ut mattis condimentum est. Praesent commodo dui sit amet augue elementum pulvinar. Maecenas sapien eros, volutpat quis rutrum a, faucibus quis dui. Fusce porta risus at arcu commodo, sit amet ullamcorper mauris pulvinar. Mauris rhoncus nibh ut ligula malesuada, sit amet auctor odio faucibus. Aenean a tempus nibh. Aliquam et sem et quam posuere accumsan eleifend at metus. Morbi non elementum dolor. Ut laoreet magna et hendrerit aliquet. Curabitur ut ante quis felis pulvinar dictum.
<br/><br/>
Sed enim odio, congue non lectus nec, ultricies congue nibh. Praesent scelerisque luctus nisl porttitor vulputate. Duis imperdiet cursus libero, et iaculis lacus finibus ut. Fusce malesuada gravida facilisis. Maecenas a urna purus. Sed hendrerit lectus nec nulla fermentum dapibus. Fusce in quam mi.
<br/><br/>
Ut mattis lacinia mattis. Morbi pharetra metus ligula, eget blandit neque fringilla vel. Mauris a orci a sem maximus scelerisque pulvinar vel arcu. Duis est est, hendrerit eu tincidunt non, ornare non massa. Donec sollicitudin tempor erat non vulputate. Ut nisl est, elementum vel aliquam et, euismod porttitor orci. Praesent rhoncus arcu vitae eros faucibus mattis. Nulla facilisi.
Voici la liste des formulaires disponible
</div>
<div class="col-xs-12 padding-10 text-center">
<div class="col-xs-12 padding-10">
<?php
if(!empty(Yii::app()->session['userId'])){ ?>
<a class="lbh btn btn-success" href="#answer.index.id.new.form.<?php echo $idForm; ?>" style="font-size: 17px;">Déposer un candidature</a>
<?php } else { ?>
<button class="btn btn-default bg-white letter-green bold" data-toggle="modal" data-target="#modalLogin" style="font-size: 17px;">
<i class="fa fa-sign-in"></i>
<span class="hidden-xs"><?php echo Yii::t("login", "Login") ?></span>
</button>
<button class="btn btn-default bg-white letter-blue bold" data-toggle="modal" data-target="#modalRegister" style="font-size: 17px;">
<i class="fa fa-plus-circle bold"></i>
<span class="hidden-xs"><?php echo Yii::t("login", "I create my account") ?></span>
</button>
<?php } ?>
if(!empty($forms)){
foreach ($forms as $key => $value) { ?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><?php echo @$value["name"] ; ?></h3>
</div>
<div class="panel-body">
<?php if(!empty(Yii::app()->session['userId'])){ ?>
<a class="lbh btn btn-success" href="#answer.index.id.new.form.<?php echo $key; ?>" style="font-size: 17px;"> Déposer un candidature</a>
<?php } else { ?>
<button class="btn btn-default bg-white letter-green bold" data-toggle="modal" data-target="#modalLogin" style="font-size: 17px;">
<i class="fa fa-sign-in"></i>
<span class="hidden-xs"><?php echo Yii::t("login", "Login") ?></span>
</button>
<button class="btn btn-default bg-white letter-blue bold" data-toggle="modal" data-target="#modalRegister" style="font-size: 17px;">
<i class="fa fa-plus-circle bold"></i>
<span class="hidden-xs"><?php echo Yii::t("login", "I create my account") ?></span>
</button>
<?php } ?>
</div>
</div>
<?php
}
} ?>
</div>
</div>
......
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