Commit 82790fc9 authored by Raph El's avatar Raph El
Browse files

Merge branch 'qa' of https://gitlab.adullact.net/pixelhumain/survey into qa

parents e0a798a7 6ad2106f
......@@ -38,7 +38,9 @@ class DirectoryAction extends CAction
$params["results"] = array();
$answers = PHDB::findAndLimitAndIndex ( Form::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));
}
$params["results"]["count"][Form::ANSWER_COLLECTION] = PHDB::count( Form::ANSWER_COLLECTION , $query);
$params["results"][Form::ANSWER_COLLECTION] = $answerList ;
......
......@@ -10,4 +10,24 @@ class EditAction extends CAction
echo $this->getController()->renderPartial($tpl,$params );
}
}
\ No newline at end of file
}
// Propriétaire
[] Rempli un dossier Etape 1
( ) Soit logué / Pas Loggué
[ ] Nom prénom (propriétaire)
[ ] Email (propriétaire)
[ ] Téléphone (propriétaire)
[ ] Title
[ ] Image
[ ] Date
[ ] Description
[ ] Opérateur lien
[ ] validate
Valide => answer (Pas dopérateur)
// Place au marché
Je mengage =>
tel opérateur (orga / -> admin)
// Une fois crée étape 2
[ ] Rempli step 2 avec le gadjo
\ No newline at end of file
......@@ -4,6 +4,7 @@ class Form {
const COLLECTION = "forms";
const CONTROLLER = "forms";
const ANSWER_COLLECTION = "answers";
const ANSWER_CONTROLLER = "answer";
const ICON = "fa-list-alt";
const ICON_ANSWER = "fa-calendar-check-o";
......@@ -134,7 +135,7 @@ class Form {
unset($data["formId"]);
unset($data["parentSurvey"]);
$data["created"] = time();
return PHDB::update( Form::ANSWER_COLLECTION,
return PHDB::update( self::ANSWER_COLLECTION,
array( "_id" => new MongoId((string)$id)),
array( '$set' => array( "answers.".$step => $data)));
} catch (CTKException $e){
......@@ -145,7 +146,8 @@ class Form {
public static function delAnswer($id)
{
try {
return PHDB::remove( Form::ANSWER_COLLECTION,
Document::removeAllForElement($id, self::ANSWER_COLLECTION);
return PHDB::remove( self::ANSWER_COLLECTION,
array( "_id" => new MongoId((string)$id)));
} catch (CTKException $e){
return $e->getMessage();
......@@ -628,8 +630,54 @@ class Form {
$res = array("render"=>"co2.views.default.unTpl", "msg"=>Yii::t("project", "Source Copy doesn't exist."),"icon"=>"fa-lock");
return $res;
}
public static function canFormAccess($rules){
if(Authorisation::isInterfaceAdmin())
return true;
if(isset($rules["roles"])
&& isset(Yii::app()->session["costum"]["hasRoles"])
&& !empty(array_intersect(Yii::app()->session["costum"]["hasRoles"], $rules["roles"])))
return true;
return false;
}
public static function getFormData($params){
if(isset(Yii::app()->session["costum"]["form"]["rules"])){
foreach ($params["formList"] as $k => $value) {
if(isset(Yii::app()->session["costum"]["form"]["rules"][$value])){
if(!self::canFormAccess(Yii::app()->session["costum"]["form"]["rules"][$value])){
array_splice($params["formList"], $k, -1);
}
}
}
}
//when inputs are interdependant on other inputs
$budgetInputList = [];
$allforms = [];
$stockBudgetInputs = false;
foreach ($params["formList"] as $i => $formId)
{
$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(count($budgetInputList))
Yii::app()->session["budgetInputList"] = $budgetInputList;
//use the cache
Yii::app()->session["forms"] = $allforms;
return $params;
}
public static function getDataForAnswer($params){
//var_dump(Yii::app()->session['costum']);exit;
if(isset(Yii::app()->session["costum"]["contextType"]) && isset(Yii::app()->session["costum"]["contextId"]))
......@@ -658,33 +706,8 @@ class Form {
$params["formList"] = Yii::app()->session["costum"]["form"]["ids"];
$params["formId"] = implode("|", $params["formList"]);
}
//when inputs are interdependant on other inputs
$budgetInputList = [];
$allforms = [];
$stockBudgetInputs = false;
foreach ($params["formList"] as $i => $formId)
{
$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(count($budgetInputList))
Yii::app()->session["budgetInputList"] = $budgetInputList;
//use the cache
Yii::app()->session["forms"] = $allforms;
} else {
$params=self::getFormData($params);
} else {
if(isset($_GET["form"]))
$params["formId"] = $_GET["form"];
else
......@@ -718,7 +741,8 @@ class Form {
$answer = $ans;
}
}
if( $answer == null && count( $myAnswers ) > 1 && !$canEdit )
if( $answer == null && count( $myAnswers ) > 1 && !$params["canEdit"] )
$showForm = false;
//si aucune reponse existe
......@@ -733,7 +757,6 @@ class Form {
if( stripos( $inp["type"] , "tpls.forms.cplx" ) !== false )
$generateAnswer = true;
}
}
}
......
......@@ -7,7 +7,7 @@
<a href="javascript:;" class='btn btn- btn-default' id="showAnswerBtn"><i class="fa fa-bars"></i> Les <?php echo $what ?></a>
<a href="#dashboard" class='lbh btn btn-default'><i class="fa fa-area-chart"></i> Observatoire Global</a>
<a href="#community" class='lbh btn btn-default'><i class="fa fa-group"></i> Communauté</a>
<a href="/costum/co/index/slug/<?php echo $el["slug"] ?>/answer/new" class='btn btn-primary' id="showAnswerBtn"><i class="fa fa-plus"></i> Ajouter <?php echo $what ?></a>
<a href="#answer.new" class='btn btn-primary' id="showAnswerBtn"><i class="fa fa-plus"></i> Ajouter <?php echo $what ?></a>
</div>
<div id="allAnswersContainer" class="hide col-xs-12 col-lg-offset-2 col-lg-8 margin-top-20">
......@@ -15,12 +15,12 @@
<?php
$lbl = $what." ";
$ct = 0;
if(!empty($allAnswers)){
if(!empty($allAnswers)){
foreach ($allAnswers as $k => $ans) {
$ct++;
?>
<li class="answerLi col-xs-12" >
<li class="answerLi col-xs-12 ansline<?php echo $k ?>" >
<div class="col-xs-3 text-center">
<a href="#answer.index.id.<?php echo $ans["_id"] ?>" class="lbh"> <?php echo $lbl." ".$ct ?></a>
</div>
......@@ -79,20 +79,65 @@
<br/>
<?php if ( $percent!= 0) {?>
<a href="#dashboard.answer.<?php echo $ans["_id"] ?>" class='margin-5 lbh btn btn-default '> <i class="fa fa-group "></i>Communauté <span class="margin-5 label label-primary"> 3 </span></a>
<a href="#dashboard.answer.<?php echo $ans["_id"] ?>" class='margin-5 lbh btn btn-default '> <i class="fa fa-group "></i>Communauté <span class="margin-5 label label-primary"> 3 </span></a>
<a href="#dashboard.answer.<?php echo $ans["_id"] ?>" class='margin-5 lbh btn btn-default '> <i class="fa fa-pie-chart "></i> Observatoire Local</a>
<a href="#dashboard.answer.<?php echo $ans["_id"] ?>" class='margin-5 lbh btn btn-default '> <i class="fa fa-pie-chart "></i> Observatoire Local</a>
<?php } ?>
</div>
<div class="col-xs-1">
<a class='text-red pull-right' href=""> <i class="fa fa-trash"></i> </a>
<a class='text-red pull-right deleteAnswer' data-id="<?php echo $k ?>" href="javascript:;"><i class="fa fa-trash"></i> </a>
</div>
</li>
<?php }
}?>
<li class="text-center"><a href="#answer.new" class="btn btn-xs btn-primary lbh-menu-app"><i class="fa fa-plus"></i> Ajouter</a></li>
<li class="text-center"><a href="#answer.new" class="btn btn-xs btn-primary lbh-menu-app"><i class="fa fa-plus"></i> <?php echo Yii::t("common","Add") ?></a></li>
</ul>
</div>
\ No newline at end of file
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
mylog.log("render","/modules/survey/views/tpls/answers/allAnswers.php");
<?php if($canEdit) { ?>
$('.deleteAnswer').off().click( function(){
id = $(this).data("id");
var $this=$(this);
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
buttons: [
{
label: "Ok",
className: "btn btn-primary pull-left",
callback: function() {
$this.find("i").removeClass("fa-trash").addClass("fa-spin fa-spinner");
getAjax("",baseUrl+"/survey/co/delete/id/"+id,function(){
toastr.success("La candidature a été supprimée avec succès");
$("#allAnswersList .ansline"+id).remove();
},"html");
}
},
{
label: "Annuler",
className: "btn btn-default pull-left",
callback: function() {}
}
]
});
});
<?php } ?>
});
</script>
\ No newline at end of file
......@@ -144,28 +144,28 @@ jQuery(document).ready(function() {
$('.deleteAnswer').off().click( function(){
id = $(this).data("id");
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
buttons: [
{
label: "Ok",
className: "btn btn-primary pull-left",
callback: function() {
getAjax("",baseUrl+"/survey/co/delete/id/"+id,function(){
//urlCtrl.loadByHash(location.hash);
$("#line"+id).remove();
},"html");
}
},
{
label: "Annuler",
className: "btn btn-default pull-left",
callback: function() {}
}
]
});
id = $(this).data("id");
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
buttons: [
{
label: "Ok",
className: "btn btn-primary pull-left",
callback: function() {
getAjax("",baseUrl+"/survey/co/delete/id/"+id,function(){
toastr.success("La réponse a été supprimée avec succès !!");
$("#line"+id).remove();
},"html");
}
},
{
label: "Annuler",
className: "btn btn-default pull-left",
callback: function() {}
}
]
});
});
......
<style type="text/css">
#allAnswersList,.communityList ul{ list-style: none }
#allAnswersList,.communityList ul,.tasksList ul{ list-style: none }
#allAnswersList li{ padding:5px; border-bottom: 1px solid #ccc; }
</style>
<div class="col-xs-12 text-center">
<a href="javascript:;" class='btn btn- btn-default' id="showAnswerBtn"><i class="fa fa-bars"></i> Les <?php echo $what ?></a>
<a href="#dashboard" class='lbh btn btn-default'><i class="fa fa-area-chart"></i> Observatoire Global</a>
<a href="#community" class='lbh 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>
<a href="<?php echo Yii::app()->createUrl("/costum")?>/co/index/slug/<?php echo $el["slug"] ?>/answer/new" class='btn btn-primary' id="showAnswerBtn"><i class="fa fa-plus"></i> Ajouter <?php echo $what ?></a>
</div>
......@@ -17,71 +17,115 @@
$ct = 0;
$globalLinks = [];
$gUids = [];
if(!empty($allAnswers)){
if(!empty($allAnswers)){
foreach ($allAnswers as $k => $ans) {
$ct++;
?>
$lbl = $what." ".$ct;
if(isset(Yii::app()->session["costum"]["form"]["title"]))
{
$titlePath = explode( ".", Yii::app()->session["costum"]["form"]["title"] );
if(isset($ans["answers"][$titlePath[0]][$titlePath[1]]))
$lbl = $ans["answers"][$titlePath[0]][$titlePath[1]];
}
<li class="answerLi col-xs-12" >
<div class="col-xs-3 text-center">
<a href="<?php echo Yii::app()->createUrl("/costum")?>/co/index/slug/<?php echo $el["slug"] ?>/answer/<?php echo $ans["_id"] ?>"> <?php echo $lbl." ".$ct ?></a>
</div>
<?php
$lblp = "";
$percol = "danger";
$step = "ouvert";
$icon = "folder-open-o";
$localLinks = [];
$uids = [];
if(!isset($ans["answers"])) {
$lblp = "no answers" ;
$percent = 0;
} else {
$totalInputs = 0;
$answeredInputs = 0;
//var_dump(Yii::app()->session["forms"]);
foreach (Yii::app()->session["forms"] as $fid => $f)
{
$totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]);
if( isset( $ans["answers"][$fid] ) ){
$answeredInputs += count( $ans["answers"][$fid] );
$step = $f['name'];
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
$lblp = "";
$percol = "danger";
$step = "ouvert";
$icon = "folder-open-o";
$localLinks = [];
$uids = [];
$todo = 0;
$done = 0;
$tasksPerson = [];
if(!isset($ans["answers"])) {
$lblp = "no answers" ;
$percent = 0;
} else {
$totalInputs = 0;
$answeredInputs = 0;
//var_dump(Yii::app()->session["forms"]);
foreach (Yii::app()->session["forms"] as $fid => $f)
{
$totalInputs += count($f["inputs"]);
//echo "|".$f['id']."-fi=".count($f["inputs"]);
if( isset( $ans["answers"][$fid] ) ){
$answeredInputs += count( $ans["answers"][$fid] );
$step = $f['name'];
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
if(isset($ans["links"]))
//todo lists are on depense for the moment
//todo genereaclly not with a fixed input ID
if( isset( $ans["answers"][$fid]["depense"] ) )
{
foreach ( $ans["links"] as $type => $ls )
foreach ( $ans["answers"][$fid]["depense"] as $ix => $dep)
{
if(!isset($localLinks[$type]))
$localLinks[$type] = [];
foreach ($ls as $uid => $time) {
if(is_string($uid) && strlen($uid) == 24 && ctype_xdigit($uid)){
if(!in_array($uid, $localLinks[$type] ))
$localLinks[$type][] = $uid;
if(!in_array($uid, $uids ))
$uids[] = new MongoId( $uid );
if(!in_array($uid, $gUids ))
$gUids[] = new MongoId( $uid );
if( isset( $dep["todo"] ) )
{
foreach ($dep["todo"] as $ixx => $t)
{
if(!isset($t["done"]) || $t["done"] == "0")
{
$todo++;
foreach ( explode(",",$t["who"]) as $whoix => $who ) {
if( !isset( $tasksPerson[ $who ] ) )
$tasksPerson[ $who ] = [];
$tasksPerson[ $who ][] = $t["what"];
}
}
else
$done++;
}
}
}
}
}
if(isset($ans["links"]))
{
foreach ( $ans["links"] as $type => $ls )
{
if(!isset($localLinks[$type]))
$localLinks[$type] = [];
if(!isset($globalLinks[$type]))
$globalLinks[$type] = [];
//echo "tot".$totalInputs."-ans".$answeredInputs;
$percent = floor( $answeredInputs*100 / $totalInputs );
$percol = "primary";
$lblp = $percent."%";
foreach ($ls as $uid => $time) {
if(is_string($uid) && strlen($uid) == 24 && ctype_xdigit($uid)){
if(!in_array($uid, $localLinks[$type] ))
$localLinks[$type][] = $uid;
if(!in_array($uid, $uids ))
$uids[] = new MongoId( $uid );
if(!in_array($uid, $globalLinks[$type] ))
$globalLinks[$type][] = $uid;
if(!in_array($uid, $gUids ))
$gUids[] = new MongoId( $uid );
}
}
}
}
if( $percent > 50 )
$percol = "warning";
if( $percent > 75 )
$percol = "success";
?>
//echo "tot".$totalInputs."-ans".$answeredInputs;
$percent = floor( $answeredInputs*100 / $totalInputs );
$percol = "primary";
$lblp = $percent."%";
}
if( $percent > 50 )
$percol = "warning";
if( $percent > 75 )
$percol = "success";
$liBg = ($todo>0) ? "style='background-color:lightGreen'" : "";
?>
<li class="answerLi col-xs-12" <?php echo $liBg ?>>
<div class="col-xs-3 text-center">
<a href="<?php echo Yii::app()->createUrl("/costum")?>/co/index/slug/<?php echo $el["slug"] ?>/answer/<?php echo $ans["_id"] ?>"> <?php echo $lbl ?></a>
</div>
<div class="col-xs-8">
<span class="margin-5" style="font-size:0.8em"> <i class="fa fa-calendar"></i> <?php echo date("d/m/y H:i",$ans["created"]); ?></span>
<?php if ( isset($ans["updated"] )) {?>
......@@ -97,9 +141,12 @@
<br/>
<?php if ( $percent!= 0 && count($uids)) {?>
<a href="javascript:;" data-id='<?php echo $ans["_id"] ?>' class='answerCommunityBtn margin-5 btn btn-default '> <i class="fa fa-group "></i>Communauté <span class="margin-5 label label-primary"> <?php echo count($uids) ?> </span></a>
<a href="#dashboard.answer.<?php echo $ans["_id"] ?>" class='margin-5 lbh btn btn-default '> <i class="fa fa-pie-chart "></i> Observatoire Local</a>
<a href="javascript:;" data-id='<?php echo $ans["_id"] ?>' class='answerCommunityBtn margin-5 btn btn-xs btn-default '> <i class="fa fa-group "></i>Communauté <span class="margin-5 label label-primary"> <?php echo count($uids) ?> </span></a>
<?php if ( count($tasksPerson)) {?>
<a href="javascript:;" data-id='<?php echo $ans["_id"] ?>' class='answerTasksBtn margin-5 btn btn-xs btn-default '> <i class="fa fa-cogs "></i>Tasks <span class="margin-5 label label-primary"> <i class="fa fa-square-o"></i> <?php echo $todo ?> </span> <span class="margin-5 label label-success"> <i class="fa fa-check-square-o"></i> <?php echo $done ?> </span></a>
<?php } ?>
<a href="#dashboard.answer.<?php echo $ans["_id"] ?>" class='margin-5 lbh btn btn-xs btn-default '> <i class="fa fa-pie-chart "></i> Observatoire Local</a>
<?php } ?>
</div>
......@@ -121,14 +168,41 @@
}
}?>
</div>
<?php if ( count($tasksPerson)) {?>
<div id="tasks<?php echo $ans["_id"] ?>" class="tasksList col-xs-12 col-lg-offset-2 col-lg-8 hide">
<?php
foreach ($tasksPerson as $person => $ls) {
echo "<h5>".$person."</h5><ul>";
foreach ($ls as $ix => $t) {
echo "<li>".$t."</li>";
}
echo "</ul><hr>";
}?>
</div>
<?php } ?>
</li>
<?php }
}?>
} ?>
<li class="text-center"><a href="<?php echo Yii::app()->createUrl("/costum")?>/co/index/slug/<?php echo $el["slug"] ?>/answer/new" class="btn btn-xs btn-primary"><i class="fa fa-plus"></i> Ajouter</a></li>
</ul>
</div>
<div id="globalCommunity" class="col-xs-12 col-lg-offset-2 col-lg-8 hide">
<?php
if( count($gUids) ){
$people = PHDB::find(Person::COLLECTION,["_id" => array( '$in'=>$gUids )], ["name","username"]);
foreach ($globalLinks as $type => $ls) {
echo "<h5>".$type."</h5><ul>";
foreach ($ls as $ix => $uid) {
echo "<li><a class='lbh' href='#@".$people[$uid]["username"]."' >".$people[$uid]["name"]."</a></li>";
}
echo "</ul><hr>";
}
}?>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
......@@ -167,12 +241,22 @@ jQuery(document).ready(function() {
<?php } ?>
$('#showAnswerBtn').off().on("click",function() {
$("#allAnswersContainer").toggleClass("hide");
$('#<?php echo $wizid ?>').toggleClass("hide");
$('#<?php echo @$wizid ?>').toggleClass("hide");
$('#globalCommunity').addClass("hide");
});
$('#globalCommunityBtn').off().on("click",function() {
$("#allAnswersContainer").addClass("hide");
$('#<?php echo @$wizid ?>').addClass("hide");
$('#globalCommunity').removeClass("hide");
});
$('.answerCommunityBtn').off().on("click",function() {
$( "#community"+$(this).data("id") ).toggleClass("hide");
});
$('.answerTasksBtn').off().on("click",function() {
$( "#tasks"+$(this).data("id") ).toggleClass("hide");
});
......
......@@ -466,10 +466,48 @@ echo "<h4 style='color:".(($titleColor) ? $titleColor : "black")."'>Suivi des d
<br/> -->
<form id="form-add-todo" class="form-add-todo">
<!-- <label for="todo">To do:</label> -->
<input type="text" id="new-todo-item" class="new-todo-item col-xs-6" name="todo" placeholder="Quoi" />
<input type="date" id="new-todo-item-date" class="new-todo-item-date col-xs-4" name="when" placeholder="Pour quand"/>
<input type="text" id="new-todo-item-who" class="new-todo-item-who col-xs-2" name="who" placeholder="Qui"/>
<!-- <input type="submit" id="add-todo-item" class="add-todo-item" value="ADD" /> -->
<?php
$uids = [];;