Commit 4e137b38 authored by Anatole Rakotoson's avatar Anatole Rakotoson
Browse files

ocecoform room and action

parent 97e8b0f8
...@@ -576,7 +576,7 @@ var formObj = { ...@@ -576,7 +576,7 @@ var formObj = {
$(".addAnswer").on('click', function() { $(".addAnswer").on('click', function() {
coInterface.showLoader("#mainDash"); coInterface.showLoader("#mainDash");
ajaxPost("#mainDash", baseUrl+'/survey/answer/index/id/new/form/'+$(this).data("parentformid"), ajaxPost("#mainDash", baseUrl+'/survey/answer/index/id/new/form/'+$(this).data("parentformid")+'/contextId/'+$(this).data("contextid")+'/contextType/'+$(this).data("contexttype"),
null, null,
function(){ function(){
if (typeof hashUrlPage != "undefined") { if (typeof hashUrlPage != "undefined") {
......
...@@ -7,20 +7,68 @@ class GenerateprojectAction extends CTKAction ...@@ -7,20 +7,68 @@ class GenerateprojectAction extends CTKAction
public function run($answerId=null,$parentId=null, $parentType=null) public function run($answerId=null,$parentId=null, $parentType=null)
{ {
$name = ""; $name = "";
$descr = "";
$links = []; $links = [];
$action = []; $action = [];
$parent = []; $parent = [];
$financer = [];
$form = "";
$depense = [];
$answer =PHDB::findOneById( Form::ANSWER_COLLECTION, $answerId); $answer =PHDB::findOneById( Form::ANSWER_COLLECTION, $answerId);
if (isset($answer["answers"]["opalProcess1"]["titre"])) { if (isset($answer["form"])) {
$name = $answer["answers"]["opalProcess1"]["titre"]; $form = PHDB::findOneById( Form::COLLECTION, $answer["form"]);
if (isset($form["mapping"])) {
if (isset($form["mapping"]["proposition"])) {
$namemap = explode(".", $form["mapping"]["proposition"]);
}
if (isset($form["mapping"]["description"])) {
$descrmap = explode(".", $form["mapping"]["description"]);
}
if (isset($form["mapping"]["depense"])) {
$depensemap = explode(".", $form["mapping"]["depense"]);
}
}
}
if (!empty($namemap) && isset($answer[$namemap[0]][$namemap[1]][$namemap[2]])) {
$name = $answer[$namemap[0]][$namemap[1]][$namemap[2]];
}
if (!empty($descrmap) && isset($answer[$descrmap[0]][$descrmap[1]][$descrmap[2]])) {
$descr = $answer[$descrmap[0]][$descrmap[1]][$descrmap[2]];
}
if (!empty($depensemap) && isset($answer[$depensemap[0]][$depensemap[1]][$depensemap[2]])) {
foreach ($answer[$depensemap[0]][$depensemap[1]][$depensemap[2]] as $keyf => $valuef) {
if (isset($valuef["financer"])) {
foreach ($valuef["financer"] as $keyi => $valuei) {
if (isset($valuei["id"])) {
array_push($financer, $valuei["id"]);
}
}
}
}
$descr = $answer[$descrmap[0]][$descrmap[1]][$descrmap[2]];
} }
if (isset($answer["answers"]["opalProcess1"]["depense"])) { if (isset($answer["answers"]["opalProcess1"]["depense"])) {
foreach ($answer["answers"]["opalProcess1"]["depense"] as $k => $v) { foreach ($answer["answers"]["opalProcess1"]["depense"] as $k => $v) {
if (isset($v["poste"])) { $act = [];
array_push($action, $v["poste"]);
if (!empty($v["poste"])) {
$act["nom"] = $v["poste"];
}
if (!empty($v["estimates"])) {
foreach ($v["estimates"] as $eskey => $esvalue) {
if (!empty($esvalue["selected"]) && $esvalue["selected"] == true ) {
$act["user"] = $eskey;
}
}
}
if (!empty($act) && !empty($act["user"])) {
array_push($action,$act);
} }
} }
} }
...@@ -45,7 +93,7 @@ class GenerateprojectAction extends CTKAction ...@@ -45,7 +93,7 @@ class GenerateprojectAction extends CTKAction
$context = null; $context = null;
if ($name != "") { if ($name != "") {
$project = Answer::GenerateProjectFromAnswer($name, array_unique($links), $parent, $action); $project = Answer::GenerateProjectFromAnswer($name, $descr, array_unique($links), $financer, $parent, $action);
return Rest::json($project); return Rest::json($project);
} else { } else {
return false; return false;
......
...@@ -502,24 +502,81 @@ class Answer{ ...@@ -502,24 +502,81 @@ class Answer{
return ( $boolval===null && !$return_null ? false : $boolval ); return ( $boolval===null && !$return_null ? false : $boolval );
} }
public static function GenerateProjectFromAnswer($name, $links = null, $parent, $action){ public static function GenerateProjectFromAnswer($name, $descr, $links = null, $financer=null, $parent, $action){
$project = [ $project = [
"collection" => Project::COLLECTION, "collection" => Project::COLLECTION,
"name" => $name, "name" => $name,
"shortDescription" => $descr,
"created" => time(),
"creator" => Yii::app()->session["userId"]
]; ];
$p_id = "";
$p_type = "";
foreach ($parent as $keyp => $valuep) {
if (isset($valuep["type"])) {
$p_id = $keyp;
$p_type = $valuep["type"];
}
}
$room = [
"collection" => Room::COLLECTION,
"name" => $name,
"description" => $descr,
"parentId" => $p_id,
"parentType" => $p_type,
"status" => "open",
"created" => time(),
"creator" => Yii::app()->session["userId"]
];
$project["parent"] = $parent; $project["parent"] = $parent;
PHDB::insert(Project::COLLECTION, $project); PHDB::insert(Project::COLLECTION, $project);
PHDB::insert(Room::COLLECTION, $room);
foreach ($links as $keylink => $valuelink) { foreach ($links as $keylink => $valuelink) {
$child = []; $child = [];
$child["childType"] = Person::COLLECTION; $child["childType"] = Person::COLLECTION;
$child["childId"] = $valuelink; $child["childId"] = $valuelink;
Link::connectParentToChild($project["_id"], Project::COLLECTION, $child, true, Yii::app()->session["userId"], ""); Link::connectParentToChild($project["_id"], Project::COLLECTION, $child, false, Yii::app()->session["userId"], "");
}
foreach ($financer as $keyf => $valuef) {
$child = [];
$child["childType"] = Organization::COLLECTION;
$child["childId"] = $valuef;
Link::connectParentToChild($project["_id"], Project::COLLECTION, $child, false, Yii::app()->session["userId"], "Financeur");
}
//add action
foreach ($action as $akey => $avalue) {
$action = [
"name" => $avalue["nom"],
"credits" => 1,
"parentId" => $project["_id"],
"parentType" => Project::COLLECTION,
"status" => "todo",
"idUserAuthor" => Yii::app()->session["userId"],
"idParentRoom" => $room["_id"]
];
PHDB::insert(Action::COLLECTION, $action);
$paramsaction = [
"id" => $action["_id"]
];
$paramsaction["child"] = [
"id" => $avalue["user"],
"type" => Person::COLLECTION
];
ActionRoom::assignPeople($paramsaction);
} }
return (string)$project["_id"]; return ["projet" => (string)$project["_id"], "room" => (string)$room["_id"]];
} }
......
...@@ -51,9 +51,15 @@ echo $this->renderPartial("survey.views.tpls.answers.header",["parentFormId" => ...@@ -51,9 +51,15 @@ echo $this->renderPartial("survey.views.tpls.answers.header",["parentFormId" =>
<?php if ($adminRight) { ?> <?php if ($adminRight) { ?>
<button class="btn btn-outline-dark titleparams"><i class="fa fa-cog"></i> Paramètre </button> <button class="btn btn-outline-dark titleparams"><i class="fa fa-cog"></i> Paramètre </button>
<?php } <?php }
if ($p_active && isset(Yii::app()->session["userId"])) if ($p_active && isset(Yii::app()->session["userId"])){
if ($contextId != null && $contextType != null) {
$btndatacontext= " data-contextid='".$contextId."' data-contexttype='".$contextType."'";
}else{
$btndatacontext= "";
}
?> ?>
<button class="btn btn-outline-dark application addAnswer" data-type="openform" data-id='<?php echo $allanswers['parentFormId'] ?>' data-parentformid='<?php echo $allanswers['parentFormId'] ?>' ><i class="fa fa-plus"></i> Ajouter </button> <button class="btn btn-outline-dark application addAnswer" data-type="openform" data-id='<?php echo $allanswers['parentFormId'] ?>' data-parentformid='<?php echo $allanswers['parentFormId'] ?>' <?php echo $btndatacontext ?>><i class="fa fa-plus"></i> Ajouter </button>
<?php } ?>
</div> </div>
</div> </div>
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
margin: 0 auto; margin: 0 auto;
} }
</style> </style>
<div class="form-group" style="overflow-x: auto;">
<div >
<?php <?php
$isAdmin = false; $isAdmin = false;
if (!empty($contextId) && !empty($contextType)) { if (!empty($contextId) && !empty($contextType)) {
...@@ -16,12 +18,13 @@ ...@@ -16,12 +18,13 @@
if ($isAdmin) { if ($isAdmin) {
?> ?>
<button type="button" class="btn btn-primary op-addquestion"><?php echo $label ?></button> <button type="button" class="btn btn-primary op-addquestion text-center"><?php echo $label ?></button>
<?php <?php
} }
?> ?>
</div>
</div>
<script type="text/javascript"> <script type="text/javascript">
var input_col_id = "<?php echo (isset($inputsEl["_id"]) ? (string)$inputsEl["_id"] : ""); ?>"; var input_col_id = "<?php echo (isset($inputsEl["_id"]) ? (string)$inputsEl["_id"] : ""); ?>";
var formInputs = <?php echo (isset($form["inputs"]) ? json_encode($form["inputs"]) : "[]") ?>; var formInputs = <?php echo (isset($form["inputs"]) ? json_encode($form["inputs"]) : "[]") ?>;
...@@ -107,12 +110,12 @@ ...@@ -107,12 +110,12 @@
mylog.log("create openDynform save tplCtx",tplCtx); mylog.log("create openDynform save tplCtx",tplCtx);
dataHelper.path2Value( tplCtx, function(params) { dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").modal('hide'); $("#ajax-modal").modal('hide');
// urlCtrl.loadByHash(location.hash); urlCtrl.loadByHash(location.hash);
} ); } );
} else { } else {
$("#ajax-modal").modal('hide'); $("#ajax-modal").modal('hide');
// urlCtrl.loadByHash(location.hash); urlCtrl.loadByHash(location.hash);
} }
} ); } );
......
...@@ -48,8 +48,12 @@ if( isset($parentForm["params"][$kunik]) ) { ...@@ -48,8 +48,12 @@ if( isset($parentForm["params"][$kunik]) ) {
if( isset($parentForm["params"][$kunik]["openFinancing"]) ) if( isset($parentForm["params"][$kunik]["openFinancing"]) )
$paramsData["openFinancing"] = $parentForm["params"][$kunik]["openFinancing"]; $paramsData["openFinancing"] = $parentForm["params"][$kunik]["openFinancing"];
} }
if (!empty($contextId) && !empty($contextType)) {
$communityLinks = Element::getCommunityByTypeAndId( $contextType, $contextId );
}else{
$communityLinks = Element::getCommunityByParentTypeAndId( $parentForm["parent"] );
}
$communityLinks = Element::getCommunityByParentTypeAndId( $parentForm["parent"] );
$organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] ); $organizations = Link::groupFindByType( Organization::COLLECTION,$communityLinks,["name","links"] );
$orgs = []; $orgs = [];
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
} }
} }
if ($isAdmin && !isset($answer["project"])) { if ($isAdmin && empty($answer["project"])) {
?> ?>
<button type="button" class="text-center btn btn-primary op-generateproject" data-collection="<?php echo Form::ANSWER_COLLECTION ?>"><?php echo $info ?></button> <button type="button" class="text-center btn btn-primary op-generateproject" data-collection="<?php echo Form::ANSWER_COLLECTION ?>"><?php echo $info ?></button>
<?php <?php
}else{ }elseif(isset($answer["project"])){
$el = Element::getElementById($answer["project"]["id"],Project::COLLECTION,null,["name","description","tags"] ); $el = Element::getElementById($answer["project"]["id"],Project::COLLECTION,null,["name","description","shortDescription", "profilImageUrl"] );
if (isset($el["el"]["profilImageUrl"])) if (isset($el["el"]["profilImageUrl"]))
{ {
?> ?>
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
<?php <?php
echo "<div class='text-center'><a href='#page.type.".Project::COLLECTION.".id.".$answer["project"]["id"]."' class='lbh-preview-element' >".$el["name"]."</a></div>"; echo "<div class='text-center'><a href='#page.type.".Project::COLLECTION.".id.".$answer["project"]["id"]."' class='lbh-preview-element' >".$el["name"]."</a></div>";
if (isset($el["shortDescription"])) {
echo "<div class='text-center text-success'>".$el["shortDescription"]."</div>";
}
} }
} }
?> ?>
...@@ -59,7 +63,7 @@ ...@@ -59,7 +63,7 @@
tplCtx.collection = tplCtxCollection; tplCtx.collection = tplCtxCollection;
tplCtx.path = "project"; tplCtx.path = "project";
tplCtx.value = { tplCtx.value = {
"id" : data "id" : data["projet"]
}; };
dataHelper.path2Value( tplCtx, function(params) {} ); dataHelper.path2Value( tplCtx, function(params) {} );
......
...@@ -714,36 +714,37 @@ $(document).ready(function() { ...@@ -714,36 +714,37 @@ $(document).ready(function() {
if(sectionDyf.<?php echo $kunik ?>ParamsData.useActions!="true"){ if(sectionDyf.<?php echo $kunik ?>ParamsData.useActions!="true"){
listObj.data = eval( todoPath ); listObj.data = eval( todoPath );
} else { } else {
<?php // <?php
$actions = PHDB::find(Actions::COLLECTION); // // $actions = PHDB::find(Actions::COLLECTION);
$list = []; // $actions = null;
$ct = 0; // $list = [];
foreach ($actions as $id => $a) { // $ct = 0;
if( !empty($a['name']) && isset($a['idUserAuthor']) && $ct <= 10 ){ // foreach ($actions as $id => $a) {
$ct++; // if( !empty($a['name']) && isset($a['idUserAuthor']) && $ct <= 10 ){
$item = [ // $ct++;
"id" => $id, // $item = [
"what" => $a['name'], // "id" => $id,
"uid" => $a['idUserAuthor'], // "what" => $a['name'],
"created" => $a['created'], // "uid" => $a['idUserAuthor'],
"who" => [], // "created" => $a['created'],
"price" => "300" // "who" => [],
]; // "price" => "300"
if(isset($a['startDate'])) // ];
$item['when'] = $a['startDate']; // if(isset($a['startDate']))
if(isset($a['links']['contributors'])){ // $item['when'] = $a['startDate'];
$links = Link::groupFindByType( Person::COLLECTION,$a["links"]['contributors'],["name",'username'] ); // if(isset($a['links']['contributors'])){
foreach ($links as $i => $u) { // $links = Link::groupFindByType( Person::COLLECTION,$a["links"]['contributors'],["name",'username'] );
$item['who'][] = $u['name']; // foreach ($links as $i => $u) {
} // $item['who'][] = $u['name'];
} // }
$list[] = $item; // }
$ct++; // $list[] = $item;
} // $ct++;
} // }
// }
?>
listObj.data = <?php echo json_encode( $list ); ?>; // ?>
// listObj.data = <?php //echo json_encode( $list ); ?>;
} }
mylog.log("build actions",listObj.data); mylog.log("build actions",listObj.data);
$.each(listObj.data, function(ix,todo) { $.each(listObj.data, function(ix,todo) {
......
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