Commit 5742b00c authored by Sylvany Mirana's avatar Sylvany Mirana

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

parents 4b2d93d6 6070f279
......@@ -30,7 +30,28 @@ var formObj = {
this.urls.form(this, hashArray[5]);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.answer.")>=0){
var hashArray = location.hash.split('.');
this.urls.answer(this, hashArray[5]);
mylog.log("formObj.initViews hashArray", hashArray);
var form = null;
var mode = null ;
if( typeof hashArray[6] != "undefined" ){
if(hashArray[6] === "form"){
form = hashArray[7];
} else if(hashArray[6] === "mode"){
mode = hashArray[7];
}
}
if( typeof hashArray[8] != "undefined" ){
if(hashArray[8] === "form"){
form = hashArray[9];
} else if(hashArray[8] === "mode"){
mode = hashArray[9];
}
}
this.urls.answer(this, hashArray[5], form , mode);
}else if(location.hash.indexOf(hashUrlPage+".view.forms.dir.answers.form")>=0){
var hashArray = location.hash.split('.');
this.urls.answers(this, hashArray[6]);
......@@ -70,18 +91,30 @@ var formObj = {
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.form."+id);
},"html");
},
answer : function(fObj, id, form, mode){
answer : function(fObj, id, form, mode, contextId, contextType){
mylog.log("fObj.urls.answer", fObj, id, form);
var url = '/survey/answer/index/id/'+id;
var addHash = ".view.forms.dir.answer."+id;
if(typeof form != "undefined" && form != null)
url += '/form/'+form;
if(typeof mode != "undefined" && mode != null)
if(typeof mode != "undefined" && mode != null){
url += '/mode/'+mode;
addHash += ".mode."+mode;
}
if(typeof contextId != "undefined" && contextId != null &&
typeof contextType != "undefined" && contextType != null)
url += '/contextId/'+contextId+'/contextType/'+contextType;
ajaxPost(fObj.container, baseUrl+url,
null,
function(){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.answer."+answerId);
console.log("formWizard!! FORM", hashUrlPage, location.hash);
if(id === "new" && typeof answerId != "undefined"){
history.replaceState(location.hash, "", hashUrlPage+".view.forms.dir.answer."+answerId+'.mode.w');
} else
history.replaceState(location.hash, "", hashUrlPage+addHash);
},"html");
},
answers : function(fObj, form){
......@@ -250,7 +283,6 @@ var formObj = {
var lbl = "";
if(typeof answers != "undefined" && answers != null && Object.keys(answers).length > 0 )
str +='<div id="allAnswersContainer" class="col-xs-12 no-padding">';
str +='tol';
$.each(answers, function(id, ans){
//mylog.log("formProfil.views.answers each", id, ans);
ct++;
......
......@@ -19,9 +19,11 @@
'get' => 'survey.controllers.answer.GetAction',
'sendmail' => 'survey.controllers.answer.mail.SendAction',
'validate' => 'survey.controllers.answer.ValidateAction',
"reloadinput" => 'survey.controllers.answer.ReloadinputAction'
);
}
public function actionViews($tpl="survey.views.tpls.forms.cplx.answers"){
// Rest::json($_POST);exit;
echo $this->renderPartial($tpl, $_POST, true);
}
}
......@@ -3,6 +3,8 @@ class AnswerAction extends CAction
{
public function run($id,$view=null)
{
var_dump("ici"); exit;
$ctrl = $this->getController();
$ctrl->layout = "//layouts/empty";
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
......
......@@ -16,6 +16,42 @@ class DashboardAction extends CAction
$countForm = 0;
$tittleList = [];
$adminRight = false;
$active = true;
$canModify = true;
$canReadOtherAnswers = false;
$oneAnswerPerPers = false;
$private = true;
$showAnswers = true;
if(isset($prntForm["active"]) ){
$active = filter_var($prntForm["active"], FILTER_VALIDATE_BOOLEAN);
}
if(isset($prntForm["canModify"]) ){
$canModify = filter_var($prntForm["canModify"], FILTER_VALIDATE_BOOLEAN);
}
if(isset($prntForm["canReadOtherAnswers"]) ){
$canReadOtherAnswers = filter_var($prntForm["canReadOtherAnswers"], FILTER_VALIDATE_BOOLEAN);
}
if(isset($prntForm["oneAnswerPerPers "]) ){
$oneAnswerPerPers = filter_var($prntForm["oneAnswerPerPers "], FILTER_VALIDATE_BOOLEAN);
}
if(isset($prntForm["private "]) ){
$private = filter_var($prntForm["private "], FILTER_VALIDATE_BOOLEAN);
}
if(isset($prntForm["showAnswers"]) ){
$showAnswers = filter_var($prntForm["showAnswers"], FILTER_VALIDATE_BOOLEAN);
}
foreach ($prntForm["parent"] as $ip => $vp) {
$communityLinks = Element::getCommunityByTypeAndId($vp["type"],$ip);
foreach ($communityLinks as $cmid => $cmvalue) {
if ($cmid == Yii::app()->session["userId"] && $cmvalue["isAdmin"] == true) {
$adminRight = true;
}
}
}
for ( $i = 0; $i < sizeof($prntForm["subForms"]); $i++){
......@@ -33,7 +69,7 @@ class DashboardAction extends CAction
$countForm += sizeof($value["inputs"]);
foreach ($value["inputs"] as $inpId => $inp) {
if ($inp["type"] == "tpls.forms.text") {
if ($inp["type"] == "tpls.forms.text" or $inp["type"] == "tpls.forms.cplx.multitextvalidation") {
array_push($tittleList, [
"sectionId" => $prntForm["subForms"][$i],
"sectionName" => $value["name"],
......@@ -48,8 +84,8 @@ class DashboardAction extends CAction
}
$title = [];
$title[0] = "sommomForm1";
$title[1] = "sommomForm120";
$title[0] = "";
$title[1] = "";
$what = "dossier";
if(isset($prntForm["what"])){
......@@ -68,6 +104,7 @@ class DashboardAction extends CAction
$users = [];
$responsetitle = [];
$right = [];
foreach ($myanswer as $idAns => $valueAns) {
if(isset($valueAns["answers"])){
......@@ -78,6 +115,21 @@ class DashboardAction extends CAction
array_push($responsetitle , $what);
}
$cn = false;
if(isset($valueAns["user"]) && $valueAns["user"] == Yii::app()->session["userId"]){
$cn = true;
}
if (isset($valueAns["links"]["answered"])) {
foreach ($valueAns["links"]["answered"] as $linkid => $linkvalue) {
if($linkid == Yii::app()->session["userId"]){
$cn = true;
}
}
}
array_push($right , $cn);
$countrsp = 0;
$percntrsp = 0;
foreach ($valueAns["answers"] as $formName => $formAns) {
......@@ -125,15 +177,23 @@ class DashboardAction extends CAction
"titleparams" => $tittleList,
"parentFormId" => $answer,
"selectedtitleparams" => $title[1],
"dossier" => $what
"dossier" => $what,
"right" => $right
];
// $allfields = [$index,$updatedate,$countAns,$countForm];
$params = [
"allanswers" => $allfields
"allanswers" => $allfields,
"adminRight" => $adminRight,
"p_active" => $active,
"p_canModify" => $canModify,
"p_canReadOtherAnswers" => $canReadOtherAnswers,
"p_oneAnswerPerPers " => $oneAnswerPerPers ,
"p_private " => $private ,
"p_showAnswers" => $showAnswers
];
$tpl= "survey.views.tpls.answers.dashboard";
echo $controller->renderPartial($tpl,$params,true);
}
......
......@@ -10,6 +10,7 @@ class GraphbuilderAction extends CAction
public function run($id=null, $answer=null, $mode=null, $form=null, $title = "")
{
$adminRight = false;
$index = [];
$type = [];
$title = [];
......@@ -17,11 +18,26 @@ class GraphbuilderAction extends CAction
$allgraph = [];
$allanswers = [];
$render = [];
$countForm = 0;
$tittleList = [];
$controller = $this->getController();
$myanswer = PHDB::find( Form::ANSWER_COLLECTION, array("form"=>$answer));
$prntForm = PHDB::findOneById(Form::COLLECTION, $answer );
foreach ($prntForm["parent"] as $ip => $vp) {
$communityLinks = Element::getCommunityByTypeAndId($vp["type"],$ip);
foreach ($communityLinks as $cmid => $cmvalue) {
if ($cmid == Yii::app()->session["userId"] && $cmvalue["isAdmin"] == true) {
$adminRight = true;
}
}
}
//if (isset(Yii::app()->session["userId"]) && Yii::app()->session["userId"] == $prntForm[""] ) {
// # code...
// }
function getvalue($myanswer, $value){
$allvalue = [];
foreach ($myanswer as $n => $m) {
......@@ -49,7 +65,7 @@ class GraphbuilderAction extends CAction
foreach ($allanswers as $key => $value) {
// var_dump($value);
foreach ($value as $k => $v) {
if($k == $question){
if(strpos($k , $question) !== false){
$count ++;
}
}
......@@ -64,7 +80,7 @@ class GraphbuilderAction extends CAction
foreach ($allanswers as $key => $value) {
// var_dump($value);
foreach ($value as $k => $v) {
if($k == $question){
if(strpos($k , $question) !== false){
$count += $v;
}
}
......@@ -80,24 +96,26 @@ class GraphbuilderAction extends CAction
foreach ($allanswers as $key => $value) {
// var_dump($value);
foreach ($value as $k => $v) {
if($k == $question){
if(strpos($k , $question) !== false){
$count += $v;
$number++;
}
}
}
return round($count/$number,2) ;
if ($count == 0) {
return 0;
} else {
return round($count/$number,2) ;
}
}
function sorting($allanswers, $subtype, $question){
$data = [ "label" => [], "dataset" => [], "type" => $subtype ];
foreach ($allanswers as $key => $value) {
foreach ($value as $k => $v) {
if($k == $question){
if(strpos($k , $question) !== false){
if(is_array($v)){
if (!in_array($v["value"], $data["label"])) {
......@@ -131,9 +149,20 @@ class GraphbuilderAction extends CAction
${$value."data"} = [];
}
foreach ($allanswers as $key => $value) {
foreach ($value as $k => $v) {
if(strpos($k , $variables["label"]) !== false){
$variables["label"] = $k;
}
if(strpos($k , $variables["var1"]) !== false){
$variables["var1"] = $k;
}
}
}
foreach ($allanswers as $key => $value) {
foreach ($value as $k => $v) {
if($k == $variables["label"]){
if(strpos($k , $variables["label"]) !== false){
if(is_array($v)){
if (!in_array($v["value"], $data["label"])) {
......@@ -152,7 +181,7 @@ class GraphbuilderAction extends CAction
foreach ($allanswers as $key => $value) {
foreach ($value as $k => $v) {
if($k == $variables["var1"]){
if(strpos($k , $variables["var1"]) !== false){
if(is_array($v)){
if (!in_array($v["value"], $data["labels"])) {
......@@ -177,42 +206,44 @@ class GraphbuilderAction extends CAction
foreach ($data["label"] as $m => $n) {
foreach ($allanswers as $key => $value) {
if(is_array($value[$variables["label"]])){
if($value[$variables["label"]]["value"] == $n){
foreach ($data["labels"] as $w => $x) {
if(is_array($value[$variables["var1"]])){
if($value[$variables["var1"]]["value"] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
}
} else {
if($value[$variables["var1"]] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
if (isset($value[$variables["label"]])) {
if(is_array($value[$variables["label"]])){
if($value[$variables["label"]]["value"] == $n){
foreach ($data["labels"] as $w => $x) {
if(is_array($value[$variables["var1"]])){
if($value[$variables["var1"]]["value"] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
}
} else {
if($value[$variables["var1"]] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
}
}
}
}
}
} else {
} else {
if($value[$variables["label"]] == $n){
foreach ($data["labels"] as $w => $x) {
if(is_array($value[$variables["var1"]])){
if($value[$variables["var1"]]["value"] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
}
} else {
if($value[$variables["var1"]] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
if($value[$variables["label"]] == $n){
foreach ($data["labels"] as $w => $x) {
if(is_array($value[$variables["var1"]])){
if($value[$variables["var1"]]["value"] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
}
} else {
if($value[$variables["var1"]] == $x){
$range = array_search($n, $data["label"]);
${"datafor".$x}[$range]++;
}
}
}
}
}
}
}
}
}
......@@ -226,6 +257,36 @@ class GraphbuilderAction extends CAction
return $data;
}
for ( $i = 0; $i < sizeof($prntForm["subForms"]); $i++){
${"childForm".$i} = PHDB::find( Form::COLLECTION, array("id"=>$prntForm["subForms"][$i]));
//array_push($sectionName, $prntForm["subForms"][$i]);
// array_push($sectionId, $prntForm["subForms"][$i]);
//if(isset(var))
//array_push($sectionName, ${"childForm".$i}["name"]);
// var_dump(${"childForm".$i});
foreach (${"childForm".$i} as $key => $value) {
if(isset($value["inputs"])){
$countForm += sizeof($value["inputs"]);
foreach ($value["inputs"] as $inpId => $inp) {
if ($inp["type"] == "tpls.forms.text" or $inp["type"] == "tpls.forms.cplx.multitextvalidation" or $inp["type"] == "tpls.forms.cplx.multiCheckboxPlus" or $inp["type"] == "tpls.forms.cplx.multiRadio") {
array_push($tittleList, [
"sectionId" => $prntForm["subForms"][$i],
"sectionName" => $value["name"],
"title" => $inp["label"],
"id" => $inpId
]);
}
}
}
}
}
foreach ($myanswer as $idans => $ans) {
if(isset($ans["answers"])){
foreach ($ans["answers"] as $name => $content) {
......@@ -282,13 +343,17 @@ class GraphbuilderAction extends CAction
elseif ($value["type"] == "sorting") {
if(isset($value["render"]["subtype"])){
array_push($render, sorting($allanswers, $value["render"]["subtype"], $value["render"]["variables"]["question"]));
}
} else {
$canRender = false;
}
}
elseif ($value["type"] == "crossing") {
if(isset($value["render"]["subtype"])){
array_push($render, crossing($allanswers, $value["render"]["subtype"], $value["render"]["variables"], $value["render"]["func"]));
}
} else {
$canRender = false;
}
}
// elseif(isset($value["function"]["variables"]) and $value["function"]["variables"] != "")
......@@ -357,11 +422,13 @@ class GraphbuilderAction extends CAction
"type" => $type,
"title" => $title,
"height" => $height,
"render" => $render
];
"render" => $render,
"titleparams" => $tittleList
];
$params = [
"allanswers" => $allfields
"allanswers" => $allfields,
"adminRight" => $adminRight
];
$tpl= "survey.views.tpls.answers.graphbuilder";
......
<?php
<?php
class IndexAction extends CAction
{
public function run($id=null, $answer=null, $mode=null, $form=null, $contextId=null, $contextType=null)
......
<?php
<?php
class NewAction extends CAction
{
public function run($id=null, $type=null , $tpl=null, $contextId=null, $contextType=null)
{
$this->getController()->layout = "//layouts/empty";
$params = array();
if(!empty($id) && !empty($type)){
if(!empty($id)){
$params["forms"] = PHDB::find(Form::COLLECTION,
[ "parent.".$id => ['$exists'=>1] ],
[ "name" ] ) ;
......@@ -30,6 +30,8 @@ class NewAction extends CAction
//var_dump($this->getController()->costum); exit;
if($tpl == null)
$tpl= "survey.views.tpls.views.new";
// Rest::json($params);exit;
echo $this->getController()->renderPartial($tpl,$params );
......
<?php
class ReloadinputAction extends CAction
{
public function run($answerId=null, $key=null, $formId=null, $wizard=null, $titleColor=null, $mode=null, $canEdit=null, $canEditForm = null, $canAdminAnswer=null, $canAnswer=null, $editQuestionBtn=null, $saveOneByOne=null)
{
$controller = $this->getController();
$answer = PHDB::findOneById(Form::ANSWER_COLLECTION, $answerId );
$parentForm = PHDB::findOneById(Form::COLLECTION, $answer["form"] );
foreach ($parentForm["parent"] as $elkey => $elvalue) {
$el = PHDB::findOneById($elvalue["type"], $elkey );
}
$form = PHDB::findOneById(Form::COLLECTION, $formId );
$answers = [];
$input = $form["inputs"][$key];
$answerPath = "answers.".$key.".";
$kunikT = explode( ".", $input["type"]);
$keyTpl = ( count($kunikT)>1 ) ? $kunikT[ count($kunikT)-1 ] : $input["type"];
$kunik = $keyTpl.$key;
if(isset($wizard))
{
if($wizard){
$answerPath = "answers.".$form["id"].".".$key.".";
if( isset($answer["answers"][$form["id"]][$key]) && count($answer["answers"][$form["id"]][$key])>0 )
$answers = $answer["answers"][$form["id"]][$key];
}
else {
if(isset($answer["answers"][$key]))
$answers = $answer["answers"][$key];
}
}
$tpl = $input["type"];
if(in_array($tpl, ["textarea","markdown","wysiwyg"])){
$tpl = "tpls.forms.textarea";
}
else if(empty($tpl) || in_array($tpl, ["text","button","color","date","datetime-local","email","image","month","number","radio","range","tel","time","url","week","tags"])){
$tpl = "tpls.forms.text";
}
else if(in_array($tpl, ["sectionTitle"])){
$tpl = "tpls.forms.".$tpl;
}
$p = [
"el" => $el,
"parentForm"=> $parentForm,
"form" => $form,
"key" => $key,
"kunik" => $kunik,
"input" => $input,
"type" => $input["type"],
"answerPath"=> $answerPath,
"answer" => $answer,
"answers" => $answers,//sub answers for this input
"label" => $input["label"] ,//$ct." - ".$input["label"] ,
"titleColor"=> $titleColor,
"info" => isset($input["info"]) ? $input["info"] : "" ,
"placeholder" => isset($input["placeholder"]) ? $input["placeholder"] : "" ,
"mode" => $mode,
"canEdit" => $canEdit,
"canEditForm" => @$canEditForm,
"canAdminAnswer" => $canAdminAnswer,
"canAnswer" => $canAnswer,
"editQuestionBtn" => @$editQuestionBtn,
"saveOneByOne" => $saveOneByOne,
"wizard" => (isset($wizard) && $wizard == true),
"tpl" => $tpl ];