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

ocecoform room and action

parent 97e8b0f8
......@@ -576,7 +576,7 @@ var formObj = {
$(".addAnswer").on('click', function() {
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,
function(){
if (typeof hashUrlPage != "undefined") {
......
......@@ -7,20 +7,68 @@ class GenerateprojectAction extends CTKAction
public function run($answerId=null,$parentId=null, $parentType=null)
{
$name = "";
$descr = "";
$links = [];
$action = [];
$parent = [];
$financer = [];
$form = "";
$depense = [];
$answer =PHDB::findOneById( Form::ANSWER_COLLECTION, $answerId);
if (isset($answer["answers"]["opalProcess1"]["titre"])) {
$name = $answer["answers"]["opalProcess1"]["titre"];
if (isset($answer["form"])) {
$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"])) {
foreach ($answer["answers"]["opalProcess1"]["depense"] as $k => $v) {
if (isset($v["poste"])) {
array_push($action, $v["poste"]);
$act = [];
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
$context = null;
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);
} else {
return false;
......
......@@ -502,24 +502,81 @@ class Answer{
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 = [
"collection" => Project::COLLECTION,
"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;
PHDB::insert(Project::COLLECTION, $project);
PHDB::insert(Room::COLLECTION, $room);
foreach ($links as $keylink => $valuelink) {
$child = [];
$child["childType"] = Person::COLLECTION;
$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" =>
<?php if ($adminRight) { ?>
<button class="btn btn-outline-dark titleparams"><i class="fa fa-cog"></i> Paramètre </button>
<?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>
......
......@@ -4,6 +4,8 @@
margin: 0 auto;
}
</style>
<div class="form-group" style="overflow-x: auto;">
<div >
<?php
$isAdmin = false;
if (!empty($contextId) && !empty($contextType)) {
......@@ -16,12 +18,13 @@
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
}
?>
</div>
</div>
<script type="text/javascript">
var input_col_id = "<?php echo (isset($inputsEl["_id"]) ? (string)$inputsEl["_id"] : ""); ?>";
var formInputs = <?php echo (isset($form["inputs"]) ? json_encode($form["inputs"]) : "[]") ?>;
......@@ -107,12 +110,12 @@
mylog.log("create openDynform save tplCtx",tplCtx);
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").modal('hide');
// urlCtrl.loadByHash(location.hash);
urlCtrl.loadByHash(location.hash);
} );
} else {
$("#ajax-modal").modal('hide');
// urlCtrl.loadByHash(location.hash);
urlCtrl.loadByHash(location.hash);
}
} );
......
......@@ -48,8 +48,12 @@ if( isset($parentForm["params"][$kunik]) ) {
if( isset($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"] );
$orgs = [];
......
......@@ -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>
<?php
}else{
$el = Element::getElementById($answer["project"]["id"],Project::COLLECTION,null,["name","description","tags"] );
}elseif(isset($answer["project"])){
$el = Element::getElementById($answer["project"]["id"],Project::COLLECTION,null,["name","description","shortDescription", "profilImageUrl"] );
if (isset($el["el"]["profilImageUrl"]))
{
?>
......@@ -40,6 +40,10 @@
<?php
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 @@
tplCtx.collection = tplCtxCollection;
tplCtx.path = "project";
tplCtx.value = {
"id" : data
"id" : data["projet"]
};
dataHelper.path2Value( tplCtx, function(params) {} );
......
......@@ -714,36 +714,37 @@ $(document).ready(function() {
if(sectionDyf.<?php echo $kunik ?>ParamsData.useActions!="true"){
listObj.data = eval( todoPath );
} else {
<?php
$actions = PHDB::find(Actions::COLLECTION);
$list = [];
$ct = 0;
foreach ($actions as $id => $a) {
if( !empty($a['name']) && isset($a['idUserAuthor']) && $ct <= 10 ){
$ct++;
$item = [
"id" => $id,
"what" => $a['name'],
"uid" => $a['idUserAuthor'],
"created" => $a['created'],
"who" => [],
"price" => "300"
];
if(isset($a['startDate']))
$item['when'] = $a['startDate'];
if(isset($a['links']['contributors'])){
$links = Link::groupFindByType( Person::COLLECTION,$a["links"]['contributors'],["name",'username'] );
foreach ($links as $i => $u) {
$item['who'][] = $u['name'];
}
}
$list[] = $item;
$ct++;
}
}
?>
listObj.data = <?php echo json_encode( $list ); ?>;
// <?php
// // $actions = PHDB::find(Actions::COLLECTION);
// $actions = null;
// $list = [];
// $ct = 0;
// foreach ($actions as $id => $a) {
// if( !empty($a['name']) && isset($a['idUserAuthor']) && $ct <= 10 ){
// $ct++;
// $item = [
// "id" => $id,
// "what" => $a['name'],
// "uid" => $a['idUserAuthor'],
// "created" => $a['created'],
// "who" => [],
// "price" => "300"
// ];
// if(isset($a['startDate']))
// $item['when'] = $a['startDate'];
// if(isset($a['links']['contributors'])){
// $links = Link::groupFindByType( Person::COLLECTION,$a["links"]['contributors'],["name",'username'] );
// foreach ($links as $i => $u) {
// $item['who'][] = $u['name'];
// }
// }
// $list[] = $item;
// $ct++;
// }
// }
// ?>
// listObj.data = <?php //echo json_encode( $list ); ?>;
}
mylog.log("build actions",listObj.data);
$.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