question_tree.php 2.58 KB
<?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())
	{
		DB::table('question_tree')->truncate();
	    	DB::table('question')->truncate();


		$qlist=DB::connection("conn")->select(DB::raw("SELECT * from question_tree"));
		
		foreach($qlist as $qline)
		{

			$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);
			DB::insert(DB::raw("insert into question_tree set $setstr"));

		}

		$slist=DB::connection("conn")->select(DB::raw("SELECT * from question_bank"));
		foreach($slist as $sline)
		{

			$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);
			DB::insert(DB::raw("insert into question set $setstr"));

		}
		DB::connection("conn")->disconnect();

	}

}		


}