Commit 11d2569d authored by Clément Damiens's avatar Clément Damiens
Browse files

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

parents b5f19ec5 f9b675ca
......@@ -123,6 +123,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
......@@ -403,23 +403,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 ;
}
......
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