Commit f717887a authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

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

parents e50b8cfb 2d2bde81
......@@ -133,6 +133,7 @@ var formObj = {
fObj.events.add(fObj);
},
form : function(id, form){
mylog.log("formProfil.views.form", id, form);
var panelColor = "panel-primary";
var formCostum = false;
var urlCostum = "";
......
......@@ -15,98 +15,7 @@ class DirectoryAction extends CAction
//var_dump($params["form"]);exit;
$answers=Answer::globalAutocomplete($res["form"], $searchParams);
$answerList = Form::listForAdmin($answers["results"]) ;
$globalLinks = [];
$gUids = [];
foreach ($answerList as $key => $ans) {
if(isset($res["form"]["mapping"])){
$answerList[$key]["mappingValues"]=Answer::getMappingValues($res["form"]["mapping"], $ans);
}
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION));
$localLinks = [];
$uids = [];
$todo = 0;
$done = 0;
$tasksPerson = [];
// $imgAnsw=(isset($ans["profilMediumImageUrl"])) ? Yii::app()->createUrl($ans["profilMediumImageUrl"]) : Yii::app()->getModule( Yii::app()->params["module"]["parent"] )->getAssetsUrl()."/images/thumbnail-default.jpg";
if(!isset($ans["answers"])) {
$percent = 0;
} else {
$totalInputs = 0;
$answeredInputs = 0;
foreach ($res["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] );
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
//todo lists are on depense for the moment
//todo genereaclly not with a fixed input ID
if( isset( $ans["answers"][$fid]["depense"] ) ){
foreach ( $ans["answers"][$fid]["depense"] as $ix => $dep) {
if( isset( $dep["todo"] ) ){
foreach ($dep["todo"] as $ixx => $t) {
if(!isset($t["done"]) || $t["done"] == "0"){
$todo++;
$whos = (is_array($t["who"])) ? $t["who"] : explode(",",$t["who"]);
foreach ( $whos 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] = [];
// if($type == "operators"){
// $lblstate = "Opérateur à valider";
// $statecol = "warning";
// foreach ($ls as $oid => $ov) {
// if($ov != "0"){
// $lblstate = "Opérateur OK";
// $statecol = "primary";
// }
// }
// }
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 );
}
}
}
}
$percent = floor( $answeredInputs*100 / $totalInputs );
}
$answerList[$key]["percent"] = $percent;
$answerList[$key]["uids"] = $uids;
$answerList[$key]["todo"] = $todo;
$answerList[$key]["done"] = $done;
$answerList[$key]["tasksPerson"] = $tasksPerson;
}
$answerList = Answer::getDataAnswers($answerList, $res["forms"]);
if(isset($answers["count"]))
$res["count"]=$answers["count"];
......
......@@ -160,5 +160,105 @@ class Answer{
return $arrayToAccess[$indexes[0]];
}
}
public static function getDataAnswers($answerList, $forms){
$globalLinks = [];
$gUids = [];
if(!empty($answerList)){
foreach ($answerList as $key => $ans) {
if(isset($res["form"]["mapping"])){
$answerList[$key]["mappingValues"]=Answer::getMappingValues($res["form"]["mapping"], $ans);
}
$answerList[$key]["countComment"] = PHDB::count(Comment::COLLECTION, array("contextId"=>$key,"contextType"=>Form::ANSWER_COLLECTION));
$localLinks = [];
$uids = [];
$todo = 0;
$done = 0;
$tasksPerson = [];
// $imgAnsw=(isset($ans["profilMediumImageUrl"])) ? Yii::app()->createUrl($ans["profilMediumImageUrl"]) : Yii::app()->getModule( Yii::app()->params["module"]["parent"] )->getAssetsUrl()."/images/thumbnail-default.jpg";
if(!isset($ans["answers"])) {
$percent = 0;
} else {
$totalInputs = 0;
$answeredInputs = 0;
foreach ($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] );
//echo "|".$f['id']."-ai=".count( $ans["answers"][$f['id']] )."<br/>";
}
//todo lists are on depense for the moment
//todo genereaclly not with a fixed input ID
if( isset( $ans["answers"][$fid]["depense"] ) ){
foreach ( $ans["answers"][$fid]["depense"] as $ix => $dep) {
if( isset( $dep["todo"] ) ){
foreach ($dep["todo"] as $ixx => $t) {
if(!isset($t["done"]) || $t["done"] == "0"){
$todo++;
$whos = (is_array($t["who"])) ? $t["who"] : explode(",",$t["who"]);
foreach ( $whos 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] = [];
// if($type == "operators"){
// $lblstate = "Opérateur à valider";
// $statecol = "warning";
// foreach ($ls as $oid => $ov) {
// if($ov != "0"){
// $lblstate = "Opérateur OK";
// $statecol = "primary";
// }
// }
// }
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 );
}
}
}
}
$percent = floor( $answeredInputs*100 / $totalInputs );
}
$answerList[$key]["percent"] = $percent;
$answerList[$key]["uids"] = $uids;
$answerList[$key]["todo"] = $todo;
$answerList[$key]["done"] = $done;
$answerList[$key]["tasksPerson"] = $tasksPerson;
}
}
return $answerList;
}
}
?>
\ No newline at end of file
......@@ -441,23 +441,26 @@ class Form {
$form = PHDB::findOneById( Form::COLLECTION , $id);
$res = false;
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 /*&&
!empty($form["links"]["members"][Yii::app()->session["userId"]]["roles"]) &&
in_array("TCO", $form["links"]["members"][Yii::app()->session["userId"]]["roles"]) */ )
||
( !empty( $form["links"]["contributors"][Yii::app()->session["userId"]] ) &&
!empty( $form["links"]["contributors"][Yii::app()->session["userId"]]["isAdmin"] ) &&
$form["links"]["contributors"][Yii::app()->session["userId"]]["isAdmin"] == true ) ){
$res = true;
} else if(Authorisation::isInterfaceAdmin()){
$res = true;
} else if (Authorisation::isParentAdmin($id, Form::COLLECTION , Yii::app()->session["userId"], $form) )
$res = true;
if(!empty(Yii::app()->session["userId"])){
if(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 /*&&
!empty($form["links"]["members"][Yii::app()->session["userId"]]["roles"]) &&
in_array("TCO", $form["links"]["members"][Yii::app()->session["userId"]]["roles"]) */ )
||
( !empty( $form["links"]["contributors"][Yii::app()->session["userId"]] ) &&
!empty( $form["links"]["contributors"][Yii::app()->session["userId"]]["isAdmin"] ) &&
$form["links"]["contributors"][Yii::app()->session["userId"]]["isAdmin"] == true ) ){
$res = true;
} else if(Authorisation::isInterfaceAdmin()){
$res = true;
} else if (Authorisation::isParentAdmin($id, Form::COLLECTION , Yii::app()->session["userId"], $form) ){
$res = true;
}
}
return $res ;
}
......@@ -661,7 +664,15 @@ class Form {
else
$form = PHDB::findOneById( Form::COLLECTION, $_GET["form"] );
$params["parentForm"] = $form;
$communityLinks = array();
if(!empty($form["parent"])){
foreach ($form["parent"] as $key => $value) {
$cl= Element::getCommunityByTypeAndId($value["type"],$key);
if(!empty($cl))
$communityLinks = array_merge($communityLinks, $cl);
}
}
$params["parentForm"]["communityLinks"]=$communityLinks;
if( !isset($params["el"]) && !empty($form) && isset($form["parent"]) ){
$params["el"]=self::getFirstParentForm($form);
$allforms = [];
......
......@@ -54,7 +54,7 @@ if( isset( $form["inputs"] ) ){ ?>
$dragNDrop = ($canEditForm) ? "dragNDrop" : "" ;
echo "<ul class='questionList ".$dragNDrop."'>";
foreach ( $form["inputs"] as $key => $input) {
$canAnswer = Yii::app()->session["userId"] == $answer["user"] || $parentForm["anyOnewithLinkCanAnswer"];
$canAnswer = (Yii::app()->session["userId"] == $answer["user"] || !empty($parentForm["anyOnewithLinkCanAnswer"])) ? true :false;
$editQuestionBtn = ($canEditForm) ? " <a class='btn btn-xs btn-danger editQuestion' href='javascript:;' data-form='".$form["id"]."' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='".$key."' data-path='inputs.".$key."'><i class='fa fa-pencil'></i></a>".
" <a class='btn btn-xs btn-danger deleteLine' href='javascript:;' data-id='".$form["_id"]."' data-collection='".Form::COLLECTION."' data-key='question".$key."' data-path='inputs.".$key."'><i class='fa fa-trash'></i></a>" : "";
......
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