Commit ddc1bcf3 authored by Raph El's avatar Raph El

Form : modification du form associer au answer

parent 37c91bcc
<?php
class IndexAction extends CAction
{
public function run($id=null, $answer=null, $mode=null)
public function run($id=null, $answer=null, $mode=null, $form=null)
{
$this->getController()->layout = "//layouts/empty";
$params = array();
if(!empty($form))
$form = PHDB::findOneById( Form::COLLECTION , $form);
if(!empty($id)){
if($id == "new"){
if(!empty(Yii::app()->session["userId"])){
$answer = Answer::generateAnswer();
$answer = Answer::generateAnswer($form);
$params["answerId"] = $answer["_id"];
$mode = "w" ;
} else {
......@@ -23,18 +25,21 @@ class IndexAction extends CAction
} else {
$params["answerId"]=$id;
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
//Rest::json($answer); exit;
if(empty($form) && !empty($answer["form"]))
$form = PHDB::findOneById( Form::COLLECTION , $answer["form"]);
}
$params["form"] = $form ;
//Rest::json($params); exit;
$params = Form::getDataForAnswer($params);
//Rest::json($params); exit;
$params["answer"] = $answer;
// TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer
//Rest::json($params); exit;
$form = PHDB::findOne( Form::COLLECTION , array("id"=>$_GET["form"]));
$parentForm = Slug::getElementBySlug($form["id"]);
//$parentForm = Slug::getElementBySlug($form["id"]);
$canEditForm = false;
$canEditAnswer = false;
$canSeeAnswer = false;
......@@ -45,7 +50,7 @@ class IndexAction extends CAction
$mode = "w";
}
if( $mode == "w" || $mode == "fa" ){
$canEditAnswer = Form::canEditAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
$canEditAnswer = Form::canEditAnswer(Yii::app()->session['userId'], $params["answer"], $form, @$parentForm);
if(empty($canEditAnswer))
$mode = "r";
else
......@@ -53,7 +58,7 @@ class IndexAction extends CAction
}
if(empty($canEditAnswer) && empty($canSeeAnswer)){
$canSeeAnswer = Form::canSeeAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
$canSeeAnswer = Form::canSeeAnswer(Yii::app()->session['userId'], $params["answer"], $form, @$parentForm);
if($canSeeAnswer === true && !empty($mode) && ($mode == "w" || $mode == "fa") )
$mode = "r";
}
......
......@@ -5,15 +5,22 @@ class NewAction extends CAction
{
$this->getController()->layout = "//layouts/empty";
$params = array();
// $params = array(
// "canEdit" => true,
// "answerId"=>"new"
// );
// if( isset($test) ){
// $params["tpl"]=$id;
// }
// $params = Form::getDataForAnswer($params);
// $tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
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"];
}
}
$tpl= "survey.views.tpls.views.new";
echo $this->getController()->renderPartial($tpl,$params );
......
......@@ -10,7 +10,7 @@ class Answer{
}
public static function generateAnswer($formId){
public static function generateAnswer($form){
$costum = CacheHelper::getCostum();
//Rest::json($costum); exit;
$ans = [
......@@ -27,13 +27,14 @@ class Answer{
$ans["parentSlug"] = Slug::getSlugByIdAndCol($costum["contextId"], $costum["contextType"]);
}
$formList = null ;
if( !empty($costum["form"]) && !empty($costum["form"]["ids"]) ){
$formList = $costum["form"]["ids"];
if( !empty($form) ){
$formList = $form["ids"];
$ans["form"] = (String)$form["_id"];
$ans["formId"] = implode("|", $formList);
$ans["formList"] = count($formList);
//$ans["step"] = $formList[0];
}
//var_dump($form); exit;
if(Costum::isSameFunction("generateAnswerBeforeSave")){
$paramBeforeSave=Costum::sameFunction("generateAnswerBeforeSave",
array("answer" => $ans, "formList"=>$formList) );
......
......@@ -427,8 +427,8 @@ class Form {
return true;
else if($answer["user"] == $userId)
return true;
else if(Authorisation::canEditItem(Yii::app()->session["userId"], $parentForm["type"], $parentForm["id"] ))
return true;
// else if(Authorisation::canEditItem(Yii::app()->session["userId"], $parentForm["type"], $answer["_id"] ))
// return true;
// else if(Costum::sameFunction("canEditAnswer", array("answer"=>$answer)))
// return true;
else if(Costum::isSameFunction("canEditAnswer", array("answer"=>$answer)))
......@@ -442,8 +442,8 @@ class Form {
$form = PHDB::findOne( Form::COLLECTION , array("_id"=>new MongoId($id)));
$res = false;
if( Yii::app()->session["userId"] == $form["author"] ||
Yii::app()->session["userId"] == $form["author"] ||
if( Yii::app()->session["userId"] == @$form["author"] ||
Yii::app()->session["userId"] == @$form["author"] ||
( !empty($form["links"]["members"][Yii::app()->session["userId"]]) &&
!empty($form["links"]["members"][Yii::app()->session["userId"]]["isAdmin"]) &&
$form["links"]["members"][Yii::app()->session["userId"]]["isAdmin"] == true /*&&
......@@ -708,88 +708,93 @@ class Form {
$params["el"]["id"] = $costum["contextId"];
}
//if(isset($_GET["form"]))
$form = PHDB::findOne( Form::COLLECTION, [ "_id" => new MongoId($_GET["form"]) ] );
$params["parentForm"] = $form;
if(isset($costum["hasOpenForm"]))
{
if(isset($costum["isMultiForms"]))
{
$answerId=null;
$answer=null;
$generateAnswer = false;
if(isset($_GET['answer']))
$answerId=$_GET['answer'];
else if(isset($params["answerId"]))
$answerId=$params["answerId"];
//var_dump($answerId);
if(!empty($answerId) && $answerId !="new")
$answer = self::getAnswerById($answerId);
//var_dump($answer);exit;
if(!empty($answer)){
$params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"];
}else if(isset($form)){
$params["formList"] = $form["ids"];
$params["formId"] = implode("|", $params["formList"]);
if(isset($_GET["form"]) || !empty($params["form"])){
if(!empty($params["form"]))
$form = $params["form"] ;
else
$form = PHDB::findOne( Form::COLLECTION, [ "_id" => new MongoId($_GET["form"]) ] );
$params["parentForm"] = $form;
if(isset($costum["hasOpenForm"]))
{
if(isset($costum["isMultiForms"]))
{
$answerId=null;
$answer=null;
$generateAnswer = false;
if(isset($_GET['answer']))
$answerId=$_GET['answer'];
else if(isset($params["answerId"]))
$answerId=$params["answerId"];
//var_dump($answerId);
if(!empty($answerId) && $answerId !="new")
$answer = self::getAnswerById($answerId);
//var_dump($answer);exit;
if(!empty($answer)){
$params["formList"] = explode("|", $answer["formId"]);
$params["formId"] = $answer["formId"];
}else if(isset($form)){
$params["formList"] = $form["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
$params=self::getFormData($params);
} else {
if(isset($_GET["form"]))
$params["formId"] = $_GET["form"];
else
$params["formId"] = (isset($form["id"])) ? $form["id"] : Form::generateOpenForm( $el["slug"] );
}
$params=self::getFormData($params);
} else {
if(isset($_GET["form"]))
$params["formId"] = $_GET["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"]))
$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($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] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$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;
} 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>";
// $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"]))
$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($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] ];
else {
//sinon on cherche la reponse incomplete
foreach ($myAnswers as $id => $ans)
{
//chercher les reponse incomplete
if(!isset( $ans["answers"]) && $answer == null )
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$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;
} 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>";
}
}
}
}
}
}
//var_dump($params);exit;
return $params;
......
......@@ -34,16 +34,17 @@
} else {
$totalInputs = 0;
$answeredInputs = 0;
foreach (Yii::app()->session["forms"] as $ix => $f)
{
$totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]);
if( isset( $ans["answers"][$f['id']] ) ){
$answeredInputs += count( $ans["answers"][$f['id']] );
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
}
// foreach (Yii::app()->session["forms"] as $ix => $f)
// {
// $totalInputs += count($f["inputs"]);
// //echo "|".$f['id']."-fi=".count($f["inputs"]);
// if( isset( $ans["answers"][$f['id']] ) ){
// $answeredInputs += count( $ans["answers"][$f['id']] );
// //echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
// }
// }
//echo "tot".$totalInputs."-ans".$answeredInputs;
$totalInputs = 1;
$percent = floor($answeredInputs*100/$totalInputs);
$percol = "primary";
$lblp = $percent."%";
......
......@@ -276,7 +276,7 @@ var answerObj = <?php echo (!empty($answer)) ? json_encode( $answer ) : "null";
<div class="col-xs-12 margin-top-20">
<?php
$wizardUid = "wizardForm";
if($showAnswerActions){
if(!empty($showAnswerActions)){
$params = [
"el" => $el,
"color1" => $color1,
......@@ -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($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>
......
......@@ -16,8 +16,10 @@
</div>
<div class="col-xs-12 padding-10 text-center">
<?php
if(!empty(Yii::app()->session['userId'])){ ?>
<a class="lbh btn btn-success" href="#answer.index.id.new" style="font-size: 17px;">Déposer un candidature</a>
<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>
......
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