420 lines
20 KiB
PHP
420 lines
20 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use App\Http\Requests\Creation;
|
|
use App\Models\Session;
|
|
use App\Models\Library;
|
|
use DB;
|
|
|
|
use PDF;
|
|
use Storage;
|
|
use Response;
|
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Exports\InvoicesExport;
|
|
|
|
class AnalyticController extends LocalController
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'mag';
|
|
$this->_module = 'magazine';
|
|
$this->_viewname = 'analytics';
|
|
$this->_title = 'Session';
|
|
$this->_base_url = '/analytic';
|
|
$this->_basemodel = new Session;
|
|
}
|
|
|
|
public function sessions(Request $request) {
|
|
$data = $this->_basemodel->orderby('id', 'desc')->get();
|
|
$values = [];
|
|
foreach($data->toArray() as $d) {
|
|
$values[] = (object)$d;
|
|
}
|
|
$fields = [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'sessionusers' => ['icon' => 'account', 'querystring' => 'id={ID}'] ] ],
|
|
'type' => ['title' => 'Session Type', 'type' => 'text'],
|
|
'number' => ['title' => 'Session Title', 'type' => 'text'],
|
|
'start_date' => ['title' => 'Date', 'type' => 'date'],
|
|
'venue' => ['title' => 'Venue', 'type' => 'text'],
|
|
'reg_count' => ['title' => 'Registered', 'type' => 'text'],
|
|
'reg_confirmed' => ['title' => 'Confirmed', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $values,
|
|
'buttons' => []
|
|
]);
|
|
}
|
|
|
|
public function sessionusers(Request $request) {
|
|
$id = $request->input('id');
|
|
$session = Session::find($id);
|
|
$response = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present', 'date_of_birth', 'gender', 'alternate_phone', 'city', 'state', 'highlight_qualification', 'specialization', 'type_of_setup', 'designation', 'clinic_institute_name']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
//echo '<pre>'; print_r($response->data->items); print_r($session); exit;
|
|
return view('session.attendance', ['session' => $session, 'doctors' => $response->data->items]);
|
|
|
|
}
|
|
|
|
public function sessionusersexport(Request $request) {
|
|
$id = $request->input('id');
|
|
$session = Session::find($id);
|
|
$response = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present', 'date_of_birth', 'gender', 'alternate_phone', 'city', 'state', 'highlight_qualification', 'specialization', 'type_of_setup', 'designation', 'clinic_institute_name']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
|
|
$fields = ["Name","Email","Phone","Date of Birth","Gender","Alternate Phone","City","State","Highlight Qualification","Specialization","Type Of Setup","Designation","Clinic Institute Name","Attendance"];
|
|
$exceldata = [];
|
|
$exceldata[] = $fields;
|
|
foreach($response->data->items as $item) {
|
|
$item = [$item->name ?? '',$item->email ?? '',$item->phone ?? '',$item->date_of_birth ?? '-',$item->gender ?? '-',$item->alternate_phone ?? '',$item->city ?? '',$item->state ?? '',$item->highlight_qualification ?? '',$item->specialization ?? '',is_array($item->type_of_setup ?? null) ? implode(', ', $item->type_of_setup) : ($item->type_of_setup ?? ''),$item->designation ?? '',$item->clinic_institute_name ?? '',isset($item->present) && $item->present == 'yes' ? 'Present':'Absent'];
|
|
$exceldata[] = $item;
|
|
}
|
|
return Excel::download(new InvoicesExport($exceldata), 'report.xlsx');
|
|
}
|
|
|
|
|
|
public function libraries(Request $request) {
|
|
$data = Library::orderby('id', 'desc')->get();
|
|
$values = [];
|
|
foreach($data->toArray() as $d) {
|
|
$values[] = (object)$d;
|
|
}
|
|
$sessions = Session::orderby('id', 'desc')->select("id", "number", "type", "start_date", "venue")->limit(8)->get();
|
|
$sessions_dd = [];
|
|
foreach($sessions as $sess){
|
|
$sessions_dd[$sess->id] = $sess->number . ' ('.$sess->type.') on ' . date("d M Y", strtotime($sess->start_date) ) . ' at ' . $sess->venue ;
|
|
}
|
|
foreach($values as &$value) {
|
|
$value->session = '';
|
|
if($value->session_id > 0) {
|
|
$value->session = $sessions_dd[$value->session_id];
|
|
}
|
|
}
|
|
$fields = [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'libraryreport' => ['icon' => 'chart-bar', 'querystring' => 'id={ID}'] ] ],
|
|
'title' => ['title' => 'Collection Name', 'type' => 'text'],
|
|
'session' => ['title' => 'Session Name', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
return $this->view('list')->with([
|
|
'title' => 'Content Libraries',
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $values,
|
|
'buttons' => []
|
|
]);
|
|
}
|
|
|
|
public function libraryreport(Request $request) {
|
|
$id = $request->input('id');
|
|
$library = Library::find($id);
|
|
$session = Session::find($library->session_id);
|
|
$response = LambdaRequest::getrequest('mag', 'mag_media_views/get_all', ['search' => json_encode(['library' => $library->code]), 'fields' => json_encode(['medias', 'library', 'contact_id', 'session_code']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$contacts = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$conts = [];
|
|
|
|
foreach($contacts->data->items as $cont) {
|
|
$conts[$cont->id] = $cont;
|
|
}
|
|
$views = [];
|
|
$phones = [];
|
|
|
|
//echo '<pre>'; print_r($response); exit;
|
|
foreach($response->data->items as $view) {
|
|
if(!in_array($conts[$view->contact_id]->phone, $phones)) {
|
|
$view->contact_name = $conts[$view->contact_id]->name;
|
|
$view->contact_phone = $conts[$view->contact_id]->phone;
|
|
$view->contact_email = $conts[$view->contact_id]->email;
|
|
$view->contact_present = $conts[$view->contact_id]->present;
|
|
$views[] = $view;
|
|
$phones[] = $conts[$view->contact_id]->phone;
|
|
}
|
|
}
|
|
|
|
$fields = [
|
|
//'actions' => ['title' => 'Actions', 'buttons' => [ ] ],
|
|
'magzine' => ['title' => 'Library', 'type' => 'text'],
|
|
'media' => ['title' => 'Media Name', 'type' => 'text'],
|
|
'contact_name' => ['title' => 'Vsitor Name', 'type' => 'text'],
|
|
'contact_phone' => ['title' => 'Phone', 'type' => 'text'],
|
|
'contact_email' => ['title' => 'Email', 'type' => 'text'],
|
|
'contact_present' => ['title' => 'Present', 'type' => 'text'],
|
|
'page_time' => ['title' => 'Page Time', 'type' => 'text'],
|
|
'video_time' => ['title' => 'Video Time', 'type' => 'text'],
|
|
'is_completed' => ['title' => 'Completed', 'type' => 'select'],
|
|
'createdAt' => ['title' => 'Date & Time', 'type' => 'date'],
|
|
];
|
|
return $this->view('list')->with([
|
|
'title' => 'Content Libraries Analytics',
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $views,
|
|
'buttons' => [ ['title' => 'Export Excel', 'link' => $this->_base_url.'/libraryreportexport?id='.$id ] ]
|
|
]);
|
|
}
|
|
|
|
public function libraryreportexport(Request $request) {
|
|
$id = $request->input('id');
|
|
$library = Library::find($id);
|
|
$session = Session::find($library->session_id);
|
|
$response = LambdaRequest::getrequest('mag', 'mag_media_views/get_all', ['search' => json_encode(['library' => $library->code]), 'fields' => json_encode(['medias', 'library', 'contact_id', 'session_code']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$contacts = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$conts = [];
|
|
|
|
foreach($contacts->data->items as $cont) {
|
|
$conts[$cont->id] = $cont;
|
|
}
|
|
$views = [];
|
|
|
|
foreach($response->data->items as $view) {
|
|
$view->contact_name = $conts[$view->contact_id]->name;
|
|
$view->contact_phone = $conts[$view->contact_id]->phone;
|
|
$view->contact_email = $conts[$view->contact_id]->email;
|
|
$view->contact_present = $conts[$view->contact_id]->present;
|
|
$views[] = $view;
|
|
}
|
|
|
|
$fields = ['Library','Media Name','Visitor Name','Phone','Email','Present','Page Time','Video Time','Completed','Date & Time'];
|
|
$exceldata = [];
|
|
$exceldata[] = $fields;
|
|
foreach($views as $view) {
|
|
$item = [$view->magzine,$view->media,$view->contact_name,$view->contact_phone,$view->contact_email, isset($view->contact_present) && $view->contact_present == 'yes' ? 'Present':'Absent',$view->page_time,$view->video_time,$view->is_completed,$view->createdAt];
|
|
$exceldata[] = $item;
|
|
}
|
|
return Excel::download(new InvoicesExport($exceldata), 'report.xlsx');
|
|
}
|
|
|
|
public function messages(Request $request) {
|
|
$data = $this->_basemodel->orderby('id', 'desc')->get();
|
|
$messages = DB::table('raphiwa_send')
|
|
->select('session_id', DB::raw('count(*) as count'))
|
|
->groupBy('session_id')
|
|
->get();
|
|
$msgs = [];
|
|
foreach($messages->toArray() as $d) {
|
|
$msgs[$d->session_id] = $d->count;
|
|
}
|
|
|
|
$values = [];
|
|
foreach($data->toArray() as $d) {
|
|
if( array_key_exists($d['id'], $msgs) ) {
|
|
$d['count'] = $msgs[$d['id']];
|
|
} else {
|
|
$d['count'] = 0;
|
|
}
|
|
$values[] = (object)$d;
|
|
}
|
|
$fields = [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'messageusers' => ['icon' => 'chart-bar', 'querystring' => 'id={ID}'] ] ],
|
|
'type' => ['title' => 'Session Type', 'type' => 'text'],
|
|
'number' => ['title' => 'Session Title', 'type' => 'text'],
|
|
'start_date' => ['title' => 'Date', 'type' => 'date'],
|
|
// 'venue' => ['title' => 'Venue', 'type' => 'text'],
|
|
'count' => ['title' => 'Messages Count', 'type' => 'text'],
|
|
// 'reg_confirmed' => ['title' => 'Confirmed', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
return $this->view('list')->with([
|
|
'title' => 'Messages Analytics',
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $values,
|
|
'buttons' => []
|
|
]);
|
|
}
|
|
|
|
public function messageusers(Request $request) {
|
|
$id = $request->input('id');
|
|
$messages = DB::table('raphiwa_send')->where('session_id', $id)->get();
|
|
$session = Session::find($id);
|
|
$contacts = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$conts = [];
|
|
|
|
foreach($contacts->data->items as $cont) {
|
|
$conts[$cont->id] = $cont;
|
|
}
|
|
$mess = [];
|
|
$phones = [];
|
|
foreach($messages as $mes) {
|
|
$mes->text = json_decode($mes->text);
|
|
$mes->text = $mes->text->template->name;
|
|
if(!in_array($conts[$mes->contact_id]->phone.'-'.$mes->text, $phones)) {
|
|
$mes->contact_name = $conts[$mes->contact_id]->name;
|
|
$mes->contact_phone = $conts[$mes->contact_id]->phone;
|
|
$mes->contact_email = $conts[$mes->contact_id]->email;
|
|
$mess[] = $mes;
|
|
$phones[] = $conts[$mes->contact_id]->phone.'-'.$mes->text;
|
|
}
|
|
}
|
|
|
|
$fields = [
|
|
//'actions' => ['title' => 'Actions', 'buttons' => [ ] ],
|
|
'text' => ['title' => 'Template', 'type' => 'text'],
|
|
'contact_name' => ['title' => 'Vsitor Name', 'type' => 'text'],
|
|
'contact_phone' => ['title' => 'Phone', 'type' => 'text'],
|
|
'contact_email' => ['title' => 'Email', 'type' => 'text'],
|
|
'contact_present' => ['title' => 'Present', 'type' => 'text'],
|
|
'is_sent' => ['title' => 'Sent', 'type' => 'select'],
|
|
'created_at' => ['title' => 'Date & Time', 'type' => 'date'],
|
|
];
|
|
return $this->view('list')->with([
|
|
'title' => 'Message Sent Analytics',
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $mess,
|
|
'buttons' => [ ['title' => 'Export Excel', 'link' => $this->_base_url.'/messageusersexports?id='.$id ] ]
|
|
]);
|
|
}
|
|
|
|
public function messageusersexports(Request $request) {
|
|
$id = $request->input('id');
|
|
$messages = DB::table('raphiwa_send')->where('session_id', $id)->get();
|
|
$session = Session::find($id);
|
|
$contacts = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$conts = [];
|
|
|
|
foreach($contacts->data->items as $cont) {
|
|
$conts[$cont->id] = $cont;
|
|
}
|
|
$mess = [];
|
|
|
|
foreach($messages as $mes) {
|
|
$mes->contact_name = $conts[$mes->contact_id]->name;
|
|
$mes->contact_phone = $conts[$mes->contact_id]->phone;
|
|
$mes->contact_email = $conts[$mes->contact_id]->email;
|
|
$mess[] = $mes;
|
|
}
|
|
//echo '<pre>'; print_r($mess); exit;
|
|
|
|
$fields = ['Message','Visitor Name','Phone','Email','Present','Sent','Date & Time'];
|
|
$exceldata = [];
|
|
$exceldata[] = $fields;
|
|
foreach($mess as $view) {
|
|
$item = [$view->text,$view->contact_name,$view->contact_phone,$view->contact_email,isset($view->contact_present) && $view->contact_present == 'yes' ? 'Present':'Absent',$view->is_sent,$view->created_at];
|
|
$exceldata[] = $item;
|
|
}
|
|
return Excel::download(new InvoicesExport($exceldata), 'report.xlsx');
|
|
}
|
|
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete', 'agenda' => ['icon' => 'format-list-text', 'querystring' => 'id={ID}'], 'visit' => ['icon' => 'eye', 'querystring' => 'id={ID}', 'target' => '_blank'], 'attendance' => ['icon' => 'account', 'querystring' => 'id={ID}', 'target' => '_blank'] ] ],
|
|
'type' => ['title' => 'Session Type', 'type' => 'text'],
|
|
'number' => ['title' => 'Session Title', 'type' => 'text'],
|
|
'start_date' => ['title' => 'Date', 'type' => 'date'],
|
|
'venue' => ['title' => 'Venue', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$faculties = DB::table('faculty')->where('status', 'active')->select('id', 'name')->get();
|
|
$faculty_bb = [];
|
|
foreach($faculties as $faculty){
|
|
$faculty_bb[$faculty->id] = $faculty->name;
|
|
}
|
|
$fields = [
|
|
'type' => ['title' => 'Session Type', 'type' => 'select', 'values' => ['road' => 'Road', 'casper' => 'Casper', 'casper_clinic' => 'Casper Clinic', 'APFT' => 'APFT', 'spirometry_simplified' => 'Spirometry Simplified', 'casper_clinic_new' => 'Casper Clinic New', 'casper_plus' => 'Casper Plus', 'ecampus' => 'E Campus'], 'required' => true],
|
|
'number' => ['title' => 'Title', 'type' => 'text', 'required' => true ],
|
|
'venue' => ['title' => 'Venue', 'type' => 'text', 'required' => true, 'fullwidth' => true],
|
|
'address' => ['title' => 'Address', 'type' => 'textarea', 'required' => true, 'fullwidth' => true],
|
|
'faculty' => ['title' => 'Faculty (multiple)', 'type' => 'multiselect', 'required' => true, 'values' => $faculty_bb ],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
];
|
|
return $fields;
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
if ($type == 'new') {
|
|
$data['code'] = \Str::random(20);
|
|
}
|
|
//echo '<pre>'; print_r($data); exit;
|
|
$data['start_date'] = $data['dates']['date'][0];
|
|
$data['dates'] = json_encode($data['dates']);
|
|
$data['faculty'] = '|'.implode('|',$data['faculty']).'|';
|
|
|
|
//$data['library_ids'] = implode(',', $data['library_ids']);
|
|
return $data;
|
|
}
|
|
protected function _beforeform($type, $values) {
|
|
//$values->library_ids = explode(',', $values->library_ids);
|
|
if($type == 'edit') {
|
|
$values->dates = json_decode($values->dates);
|
|
$values->faculty = explode('|', $values->faculty);
|
|
$values->faculty = array_filter($values->faculty, function($value) { return !is_null($value) && $value !== ''; });
|
|
}
|
|
//echo '<pre>'; print_r($values); exit;
|
|
return $values;
|
|
}
|
|
|
|
public function visit(Request $request) {
|
|
$id = $request->input('id');
|
|
$values = $this->_basemodel->find($id)->toArray();
|
|
return redirect('/microsite/'.$values['type'].'-'.$values['code']);
|
|
}
|
|
|
|
public function attendance(Request $request) {
|
|
$id = $request->input('id');
|
|
$session = $this->_basemodel->find($id);
|
|
$response = LambdaRequest::getrequest('contact', 'contact/get_all', ['source'=>'dynamodb', 'search' => json_encode(['session_code' => $session->code]), 'fields' => json_encode(['session_code', 'present', 'date_of_birth', 'gender', 'alternate_phone', 'city', 'state', 'highlight_qualification', 'specialization', 'type_of_setup', 'designation', 'clinic_institute_name']) ], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
//echo '<pre>'; print_r($response); print_r($session); exit;
|
|
return view('session.attendance', ['session' => $session, 'doctors' => $response->data->items]);
|
|
}
|
|
|
|
public function certificate(Request $request) {
|
|
$code = $request->input('code');
|
|
$session = $this->_basemodel->where('code', $code)->first();
|
|
$doctor = $request->input('doctor');
|
|
$response = LambdaRequest::getrequest('contact', 'contact/get_one', ['id'=>$doctor], env('LAMBDA_ACCESS_TOKEN', 'default_value') );
|
|
$doctor = $response->data->item;
|
|
//echo '<pre>'; print_r($doctor); exit;
|
|
$output = Creation::certificate($session, $doctor);
|
|
$filename = $output['filename'];
|
|
$folder = $output['folder'];
|
|
|
|
$headers = array('Content-Type: image/png',);
|
|
return Response::download($folder.'/'.$filename, 'certificate.png',$headers);
|
|
}
|
|
|
|
public function agenda(Request $request) {
|
|
$id = $request->input('id', 0);
|
|
if($id === 0) {
|
|
return redirect('/sessions')->withError('Session not found!');
|
|
} else {
|
|
$request->session()->put('session_id', $id);
|
|
return redirect('/sessionagendas');
|
|
}
|
|
}
|
|
|
|
protected function retimage($image) {
|
|
$size = getimagesize($image);
|
|
switch ($size['mime']) {
|
|
case 'image/jpeg':
|
|
$photoimg = imagecreatefromjpeg($image);
|
|
break;
|
|
case 'image/png':
|
|
$photoimg = imagecreatefrompng($image);
|
|
break;
|
|
case 'image/jpeg':
|
|
$photoimg = imagecreatefrompng($image);
|
|
break;
|
|
default:
|
|
# code...
|
|
break;
|
|
}
|
|
return $photoimg;
|
|
}
|
|
|
|
}
|