question_tree.php
3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Config;
use App\Models\User;
use App\Models\Accesslog;
use App\Models\CRMCall;
use Schema;
use PDO;
use Illuminate\Database\Schema\Blueprint;
class question_tree extends Command {
/**
* The console command name.
*
* @var string
*/
protected $signature = 'question_tree';
/**
* The console command description.
*
* @var string
*/
protected $description = 'question_tree';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$nowts=time();
echo "\n".date('Y-m-d H:i:s')."\n";
$tcol=0;$fieldsarr=array();$extrahdrarr=array();
$server_ip=env('app_ip');
$lead_form = "lead_form_details";
$central_ip=env('central_ip');
$conn = array(
'driver' => 'mysql',
'host' => $central_ip,
'database' => env('DB_DATABASE', 'kstych_flexydial'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'options' => array(
PDO::ATTR_TIMEOUT => 5,
),
);
Config::set("database.connections.conn", $conn);
if(DB::connection("conn")->getDatabaseName())
{
$qlist=DB::connection("conn")->select(DB::raw("SELECT * from question_tree"));
$parent_id='';
$parent_opt='';
foreach($qlist as $qline)
{
$lqlist=DB::select(DB::raw("SELECT parent_id,parent_opt from question_tree where parent_id='$qline->parent_id' and parent_opt='$qline->parent_opt'"));
if($lqlist){
$parent_id=$lqlist[0]->parent_id;
$parent_opt=$lqlist[0]->parent_opt;
}
$setstrarr=array();
$setstrarr[]="parent_id='$qline->parent_id'";
$setstrarr[]="parent_opt='$qline->parent_opt'";
$setstrarr[]="question_id='$qline->question_id'";
$setstrarr[]="priority='$qline->priority'";
$setstr=implode(",",$setstrarr);
if($parent_id==$qline->parent_id && $parent_opt==$qline->parent_opt){
DB::update(DB::raw("update question_tree set $setstr,updated_at=now() where parent_id='$qline->parent_id' and parent_opt='$qline->parent_opt'"));
}else{
DB::insert(DB::raw("insert into question_tree set $setstr,created_at=now()"));
}
}
$question_no='';
$slist=DB::connection("conn")->select(DB::raw("SELECT * from question_bank"));
foreach($slist as $sline)
{
$lslist=DB::select(DB::raw("SELECT question_no from question where question_no='$sline->question_no'"));
if($lslist){
$question_no=$lslist[0]->question_no;
}
$setstrarr=array();
$setstrarr[]="question_no='$sline->question_no'";
$setstrarr[]="questions='$sline->questions'";
$setstrarr[]="opt_1='$sline->opt_1'";
$setstrarr[]="opt_2='$sline->opt_2'";
$setstrarr[]="opt_3='$sline->opt_3'";
$setstrarr[]="opt_4='$sline->opt_4'";
$setstrarr[]="opt_5='$sline->opt_5'";
$setstrarr[]="opt_6='$sline->opt_6'";
$setstrarr[]="opt_7='$sline->opt_7'";
$setstrarr[]="opt_8='$sline->opt_8'";
$setstrarr[]="opt_9='$sline->opt_9'";
$setstrarr[]="opt_10='$sline->opt_10'";
$setstrarr[]="type='$sline->type'";
$setstrarr[]="compulsory_qes='$sline->compulsory_qes'";
$setstr=implode(",",$setstrarr);
if($question_no=$sline->question_no){
DB::update(DB::raw("update question set $setstr,updated_at=now() where question_no='$sline->question_no'"));
}else{
DB::insert(DB::raw("insert into question set $setstr,created_at=now()"));
}
}
DB::connection("conn")->disconnect();
}
}
}