JSONquestionfilter recommitted : ps
This commit is contained in:
parent
078f5af917
commit
83088a1b26
@ -1319,78 +1319,28 @@ class Template_Management_Controller extends REST_Controller {
|
||||
$json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2);
|
||||
if(count($json_table)>0){
|
||||
$json = json_decode($json_table[0]['json'],true);
|
||||
// print_r($json['questions']);die();
|
||||
$quest = $json['questions'];
|
||||
if($form_id == 19) $quest = $json['questions'][0]['question'];
|
||||
// ch(1,2,22,20,11,13)
|
||||
// print_r($quest);die();
|
||||
$filter_arr = array();
|
||||
$key_arr = array();
|
||||
//try 1;
|
||||
// for($i= 0;$i<count($quest);$i++){
|
||||
// array_push($filter_arr,$quest[$i]['question']);
|
||||
// $filter_arr[$i] = $quest[$i]['question'];
|
||||
// $question_key = $quest[$i]['question_key'];
|
||||
// $onchange_properties = $quest[$i]['onchange_properties'];
|
||||
// for($j= 0;$j<count(array($onchange_properties));$j++){
|
||||
// $form_controls = isset($onchange_properties[$j]['form_controls'])?$onchange_properties[$j]['form_controls']:[];
|
||||
// for($k= 0;$k<count($form_controls);$k++){
|
||||
// $question_index = $form_controls[$k]['insert_index'];
|
||||
// if($question_key == $question_index){
|
||||
// $sub_quest = $form_controls[$k]['questions'];
|
||||
// for($l= 0;$l<count($sub_quest);$l++){
|
||||
// // array_push($filter_arr,$sub_quest[$l]['question']);
|
||||
// $filter_arr[$i][$quest[$i]['question']] = $sub_quest[$l]['question'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//try 2;
|
||||
// $i=0;
|
||||
// if(!empty($quest)){
|
||||
// foreach ($quest as $key => $value) {
|
||||
// // $filter_arr[$i] = $value['question'];
|
||||
// // $key_arr[$i] = $value['question_key'];
|
||||
// $onchange_properties = isset($value['onchange_properties'][0]['form_controls']) ? $value['onchange_properties'][0]['form_controls'] : array();
|
||||
// $count = isset($onchange_properties) ? count($onchange_properties) : 0 ;
|
||||
// if($count>0){
|
||||
// foreach ($onchange_properties as $key1 => $value1) {
|
||||
// // print_r($onchange_properties);
|
||||
// $question_index = $value1['insert_index'];
|
||||
// if($value1['insert_index'] == $value['question_key']){
|
||||
// $sub_quest = $value1['questions'];
|
||||
// $filter_sub_arr = array();
|
||||
// for($l= 0;$l<count($sub_quest);$l++){
|
||||
// // print_r($sub_quest);
|
||||
// array_push($filter_sub_arr,$sub_quest[$l]['question']);
|
||||
// }
|
||||
// if(!empty($filter_sub_arr)){
|
||||
// $filter_arr[] = array($value['question']=>$filter_sub_arr);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// $filter_arr[] = $value['question'];
|
||||
// }
|
||||
// // $i++;
|
||||
// }}
|
||||
//try 3;
|
||||
$arr =array();
|
||||
//try 4
|
||||
if(!empty($quest)){
|
||||
$a1 = $this->fns1($quest);//filter only question and question_key
|
||||
$arr = $this->fns2($quest,$a1); // filter the onchange;
|
||||
$arr1 = $this->call_arr1($quest);
|
||||
$arr2 = $this->call_arr2($quest);
|
||||
$filter_arr = $this->merged_arr($arr1,$arr2);
|
||||
}
|
||||
|
||||
|
||||
//end
|
||||
if(!empty($arr)){
|
||||
|
||||
if(!empty($filter_arr)){
|
||||
$data['dataStatus'] = true;
|
||||
$data['status'] = REST_Controller::HTTP_OK;
|
||||
$data['available_question'] = $arr;
|
||||
$data['available_question'] = $filter_arr;
|
||||
$data['json'] = $quest;
|
||||
$this->response($data,REST_Controller::HTTP_OK);
|
||||
}else{
|
||||
$data['dataStatus'] = false;
|
||||
$data['status'] = REST_Controller::HTTP_NOT_MODIFIED;
|
||||
$data['msg'] = 'Something Went Wrong! Try again Later';
|
||||
$data['msg'] = 'There is no JSON template. try again';
|
||||
$this->response($data,REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
@ -1404,39 +1354,27 @@ class Template_Management_Controller extends REST_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// public function Auto($quest){
|
||||
// // return 1;
|
||||
// $return_arr = array();
|
||||
// if(!empty($quest)){
|
||||
// foreach ($quest as $key => $value) {
|
||||
// $return_arr = $value['question'] && $var['question_key'];
|
||||
// }
|
||||
// }
|
||||
// return $return_arr;
|
||||
// }
|
||||
|
||||
public function fns1($quest){
|
||||
// return $key == 'question' && $key == 'question_key';
|
||||
// $new_array = array_filter($quest, function($var) use ($filter){
|
||||
// return ($var['question'] && $var['question_key']);
|
||||
// });
|
||||
// $filtered = array_filter($quest, function($v) { return ($v['question']); });
|
||||
//Step 1 : Question Filter Only
|
||||
public function call_arr1($quest){
|
||||
$return_arr = array();
|
||||
$i = 0 ;
|
||||
if(!empty($quest)){
|
||||
foreach ($quest as $key => $value) {
|
||||
$return_arr[$i] = array('question'=> $value['question'],'question_key'=>$value['question_key']);
|
||||
// $return_arr[$i] = array('question'=> $value['question'],'question_key'=>$value['question_key']);
|
||||
// $return_arr[$i]['question'] = $value['question'];
|
||||
// $return_arr[$i]['question_key'] = $value['question_key'];
|
||||
$return_arr[$i] = $value['question'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $return_arr;
|
||||
}
|
||||
|
||||
public function fns2($quest,$arr1){
|
||||
$arr2 = array();
|
||||
$i = 0;
|
||||
//Step 2 : Onchange fns - Question Filter
|
||||
public function call_arr2($quest){
|
||||
$return_arr = array();
|
||||
$i = 0 ;
|
||||
if(!empty($quest)){
|
||||
foreach ($quest as $key => $value) {
|
||||
if((isset($value['onchange_properties'])) && (!empty($value['onchange_properties'])) && ($value['onchange_properties'] != null)){
|
||||
$onchange_properties = isset($value['onchange_properties'][0]['form_controls']) ? $value['onchange_properties'][0]['form_controls'] : array();
|
||||
@ -1444,33 +1382,41 @@ class Template_Management_Controller extends REST_Controller {
|
||||
if($count>0 && !empty($onchange_properties)){
|
||||
foreach ($onchange_properties as $key1 => $value1) {
|
||||
if($value1['insert_index'] == $value['question_key']){
|
||||
// $arr2[$i]['child'] = $this->fns1($value1['questions']);
|
||||
$try2 = $this->fns1($value1['questions']);
|
||||
$arr2[$i]['child'] = self::fns2($value1,$try2);
|
||||
$temp[$i] = $this->call_arr1($value1['questions']);
|
||||
$arr2 = $this->call_arr2($value1['questions']);
|
||||
// $arr1 = $this->call_arr1($value1['questions']);
|
||||
// $arr2[$i]['child'] = $this->call_arr2($temp[$i],$arr2);
|
||||
$return_arr[$i] = $this->merged_arr($temp[$i],$arr2);
|
||||
// foreach($value1['question'] as $key2 => $value2){
|
||||
// $temp2[$i] = $this->call_arr1($value2['question']);
|
||||
// $arr3 = $this->call_arr2($value2['question']);
|
||||
// $return_arr[$i] = $this->merged_arr($temp2[$i],$arr3);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else{}
|
||||
$i++;
|
||||
$i++;
|
||||
}
|
||||
// $arr1 = $this->fns1($quest);
|
||||
}
|
||||
return $return_arr;
|
||||
}
|
||||
|
||||
//Step 3 : Mapping Here for single-array using 2-array(arr1,arr2)
|
||||
public function merged_arr($arr1,$arr2){
|
||||
$final_result = array();
|
||||
foreach($arr1 as $key=>$val){ // Loop though one array
|
||||
if (array_key_exists($key, $arr2))
|
||||
{
|
||||
$val2 = $arr2[$key]; // Get the values from the other array
|
||||
$final_result[$key] = $val + $val2; // combine 'em
|
||||
}
|
||||
else
|
||||
{
|
||||
$final_result[$key] = $val;
|
||||
}
|
||||
{
|
||||
$val2 = $arr2[$key]; // Get the values from the other array
|
||||
$final_result[$val] = $val2; // combine here (mapping as key)
|
||||
// $final_result[$key] = $val + $val2;
|
||||
// $final_result[$key][$val] = $val2;
|
||||
}
|
||||
else{
|
||||
$final_result[$key] = $val; // combine here (mapping as key)
|
||||
}
|
||||
}
|
||||
return $final_result;
|
||||
// }
|
||||
// $return_arr = $this->fns1($quest);
|
||||
// return $return_arr;
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user