Commit 97e8b0f8 authored by Anatole Rakotoson's avatar Anatole Rakotoson
Browse files

ocecoform

parent 0210ac5e
......@@ -778,7 +778,11 @@ var formObj = {
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
urlCtrl.loadByHash(location.hash);
ajaxPost("", baseUrl+'/survey/form/generateinputs/form/'+formData.openform+'/contextId/'+contextId+'/contextType/'+contextType,
null,
function(){
urlCtrl.loadByHash(location.hash);
},"html");
} );
}
......
......@@ -16,6 +16,8 @@
'delete' => 'survey.controllers.form.DeleteAction',
'admindirectory'=>'survey.controllers.form.admin.DirectoryAction',
'schema' => 'survey.controllers.form.SchemaAction',
'generateinputs' => 'survey.controllers.form.GenerateinputsAction',
'generateproject' => 'survey.controllers.ocecoform.GenerateprojectAction',
);
}
}
......@@ -55,7 +55,7 @@ class DashboardAction extends CAction
foreach ($prntForm["parent"] as $ip => $vp) {
$communityLinks = Element::getCommunityByTypeAndId($vp["type"],$ip);
foreach ($communityLinks as $cmid => $cmvalue) {
if ($cmid == Yii::app()->session["userId"] && $cmvalue["isAdmin"] == true) {
if ($cmid == Yii::app()->session["userId"] && isset($cmvalue["isAdmin"]) && $cmvalue["isAdmin"] == true) {
$adminRight = true;
}
}
......
<?php
class GenerateinputsAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//http://127.0.0.1/survey/form/get/slug/dealAH
//if $id : opens the forms
public function run($form=null, $contextId=null, $contextType=null)
{
$formParent =PHDB::findOneById( Form::COLLECTION, $form);
$context = null;
if(!empty($contextId) && !empty($contextType)){
$ctxEl = PHDB::findOneById( $contextType , $contextId,["name","address"]);
$context = [
$contextId => [
"type" => $contextType,
"name" => $ctxEl["name"]
]
];
}
$inputs = Form::generateInputs($formParent, $context);
return Rest::json($inputs);
}
}
\ No newline at end of file
<?php
class GenerateprojectAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//http://127.0.0.1/survey/form/get/slug/dealAH
//if $id : opens the forms
public function run($answerId=null,$parentId=null, $parentType=null)
{
$name = "";
$links = [];
$action = [];
$parent = [];
$answer =PHDB::findOneById( Form::ANSWER_COLLECTION, $answerId);
if (isset($answer["answers"]["opalProcess1"]["titre"])) {
$name = $answer["answers"]["opalProcess1"]["titre"];
}
if (isset($answer["answers"]["opalProcess1"]["depense"])) {
foreach ($answer["answers"]["opalProcess1"]["depense"] as $k => $v) {
if (isset($v["poste"])) {
array_push($action, $v["poste"]);
}
}
}
if($parentId != null && $parentType != null){
$parents =PHDB::findOneById( $parentType, $parentId);
$parent[$parentId] = [
"type" => $parentType,
"name" => $parents["name"]
];
}
if(!empty($answer["links"])){
foreach ($answer["links"] as $key => $value) {
if ($key == "answered") {
$links = array_unique(array_merge($links,$value), SORT_REGULAR);
} elseif (is_array($value)) {
array_push($links, array_keys($value)[0]);
}
}
}
$context = null;
if ($name != "") {
$project = Answer::GenerateProjectFromAnswer($name, array_unique($links), $parent, $action);
return Rest::json($project);
} else {
return false;
}
}
}
\ No newline at end of file
......@@ -502,5 +502,26 @@ class Answer{
return ( $boolval===null && !$return_null ? false : $boolval );
}
public static function GenerateProjectFromAnswer($name, $links = null, $parent, $action){
$project = [
"collection" => Project::COLLECTION,
"name" => $name,
];
$project["parent"] = $parent;
PHDB::insert(Project::COLLECTION, $project);
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"], "");
}
return (string)$project["_id"];
}
}
?>
\ No newline at end of file
......@@ -33,6 +33,7 @@ class Form {
"creator" => array("name" => "creator"),
"created" => array("name" => "created"),
"isSpecific" => array("name" => "isSpecific"),
"subForm" => array("name" => "subForm"),
);
public static $riskWeight = array(
......@@ -782,5 +783,22 @@ class Form {
}
return $parent;
}
public static function generateInputs($form, $context = null){
if (!empty($form["rules"]["editableSubForms"])) {
foreach ($form["rules"]["editableSubForms"] as $key => $value) {
$inp = [];
$inp = [
"isSpecific" => true,
"subForm" => $value,
];
$inp["parent"] = $context;
PHDB::insert(self::INPUTS_COLLECTION, $inp);
}
}
return true;
}
}
?>
\ No newline at end of file
......@@ -22,7 +22,6 @@ if(isset($parentForm["openForm"]) && $parentForm["openForm"] == true && isset($c
if( isset( $form["inputs"] ) ){
if (isset($inputsEl["inputs"])) {
var_dump($inputsEl["inputs"]);
$form["inputs"] = array_merge($form["inputs"] , $inputsEl["inputs"]);
}
?>
......
<style type="text/css">
.op-generateproject {
border-radius: 15px;
margin: 0 auto;
}
</style>
<div class="form-group" style="overflow-x: auto;">
<div ><h4 class="titlecolor<?php echo $kunik ?> pdftittlecolor text-center" style="padding-top:20px;"><?php echo $label ; ?></h4>
</div>
<?php
$isAdmin = false;
if (!empty($contextId) && !empty($contextType)) {
$elCom = Element::getCommunityByTypeAndId($contextType, $contextId);
if(isset($elCom[Yii::app()->session["userId"]]) && $elCom[Yii::app()->session["userId"]] != null && $elCom[Yii::app()->session["userId"]]["isAdmin"] == true){
$isAdmin = true;
}
}
if ($isAdmin && !isset($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"] );
if (isset($el["el"]["profilImageUrl"]))
{
?>
<div class="text-center">
<img src="<?php echo Yii::app()->createUrl('/'.$el["el"]["profilImageUrl"]); ?>" class="text-center img-circle" width='60px' height='60px' />
</div>
<?php
} else
{
?>
<div class="text-center">
<img src="<?php echo Yii::app()->getModule('co2')->assetsUrl.'/images/thumb/default_organizations.png'; ?>" class="text-center img-circle" width='60px' height='60px' />
</div>
<?php
echo "<div class='text-center'><a href='#page.type.".Project::COLLECTION.".id.".$answer["project"]["id"]."' class='lbh-preview-element' >".$el["name"]."</a></div>";
}
}
?>
</div>
<script type="text/javascript">
var answerId = "<?php echo (string)$answer["_id"]; ?>";
var cntxtId = "<?php echo $contextId; ?>";
var cntxtType = "<?php echo $contextType; ?>";
var murirStep = "<?php echo (isset($parentForm['mapping']['murir']) ? $parentForm['mapping']['murir'] : ""); ?>";
$('.op-generateproject').off().click(function() {
var tplCtxCollection = $(this).data("collection");
ajaxPost("", baseUrl+'/survey/form/generateproject/answerId/'+answerId+'/parentId/'+cntxtId+'/parentType/'+cntxtType,
null,
function(data){
tplCtx.id = answerId;
tplCtx.collection = tplCtxCollection;
tplCtx.path = "project";
tplCtx.value = {
"id" : data
};
dataHelper.path2Value( tplCtx, function(params) {} );
tplCtx.path = "step";
tplCtx.value = murirStep;
dataHelper.path2Value( tplCtx, function(params) {
reloadInput("<?php echo $key ?>", "<?php echo (string)$form["_id"] ?>");
} ); },"html");
});
</script>
\ No newline at end of file
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