227 lines
10 KiB
PHP
227 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Exports\InvoicesExport;
|
|
|
|
class MagmediaController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'mag';
|
|
$this->_module = 'mag_media';
|
|
$this->_viewname = 'magmedia';
|
|
$this->_title = 'Magazine Media';
|
|
$this->_base_url = '/magmedia';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$mag_id = $request->session()->get('mag_id');
|
|
if($mag_id === 0) {
|
|
return redirect('/magazines')->withError('Magazine not found!');
|
|
}
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all', ['mag_id' => $mag_id]);
|
|
//echo '<pre>'; print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_buttons() {
|
|
return [ ['title' => 'Add New', 'link' => $this->_base_url.'/addnew' ], ['title' => 'Back to Magzines', 'link' => '/magazines'] ];
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete', 'viewers' => ['icon' => 'account-multiple', 'querystring' => 'id={ID}'] ] ],
|
|
//'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image'],
|
|
'name' => ['title' => 'Media Name', 'type' => 'text'],
|
|
'points' => ['title' => 'Points', 'type' => 'text'],
|
|
'media_type' => ['title' => 'Media Type', 'type' => 'text'],
|
|
'likes_count' => ['title' => 'Likes', 'type' => 'text'],
|
|
'comments_count' => ['title' => 'Comments', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$groups = $this->getlambda('get', 'ums', 'group', 'dropdown');
|
|
$groups_dd = [];
|
|
foreach($groups->data->items as $group){
|
|
$groups_dd[$group->id] = $group->name;
|
|
}
|
|
|
|
$forms = $this->getlambda('get', 'form', 'formentity', 'dropdown');
|
|
$forms_dd = [];
|
|
foreach($forms->data->items as $form){
|
|
$forms_dd[$form->id] = $form->title;
|
|
}
|
|
|
|
$forms = $this->getlambda('get', 'form', 'survey', 'dropdown');
|
|
foreach($forms->data->items as $form){
|
|
$forms_dd[$form->id] = $form->title . ' (Survey)';
|
|
}
|
|
|
|
$quizs = $this->getlambda('get', 'form', 'quiz', 'dropdown');
|
|
foreach($quizs->data->items as $form){
|
|
$forms_dd[$form->id] = $form->name . ' (Quiz)';
|
|
}
|
|
$metrics = $this->getlambda('get', 'metric', 'metric', 'get_all');
|
|
$metric_dd = ['NA' => 'Tracking Not Needed'];
|
|
foreach($metrics->data->items as $metric){
|
|
$metric_dd[$metric->id] = $metric->name;
|
|
}
|
|
$fields = [
|
|
'name' => ['title' => 'Media Name', 'type' => 'text', 'required' => true],
|
|
'points' => ['title' => 'Points', 'type' => 'text', 'required' => true],
|
|
'description' => ['title' => 'Media Description', 'type' => 'textarea', 'required' => true, 'fullwidth' => true],
|
|
'media_type' => ['title' => 'Media Types', 'type' => 'select', 'required' => true, 'values' => ['image' => 'Image', 'video' => 'Video', 'pdf' => 'PDF', 'audio' => 'Audio', 'gallery' => 'Gallery', 'form' => 'Form', 'quiz' => 'Quiz', 'survey' => 'Survey', 'external' => 'External Url', 'scorm' => 'Scorm'] ],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'form_id' => ['title' => 'Form', 'type' => 'select', 'values' => $forms_dd ],
|
|
//'media_thumb' => ['title' => 'Media Thumb', 'type' => 'image', 'required' => true],
|
|
'media_url' => ['title' => 'Media File (image, video, pdf, audio, scorm) (for gallery, upload zip file with all images)', 'type' => 'file'],
|
|
'gallery' => ['title' => 'Multiple Media File (only for gallery)', 'type' => 'multiimage'],
|
|
'ext_url' => ['title' => 'Media Url (form, external)', 'type' => 'text'],
|
|
|
|
'mapped_metric' => ['title' => 'Point Metric', 'type' => 'select', 'values' => $metric_dd, 'required' => true ],
|
|
'count_metric' => ['title' => 'Count Metric', 'type' => 'select', 'values' => $metric_dd, 'required' => true ],
|
|
];
|
|
return $fields;
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$data['magazine_id'] = $request->session()->get('mag_id');
|
|
// if( $request->file('media_thumb') ) {
|
|
// $data['media_thumb'] = $this->_uploadMedia($request, 'media_thumb', 'magazine_media_thumb');
|
|
// }
|
|
if( $request->file('media_url') ) {
|
|
$data['media_url'] = $this->_uploadMedia($request, 'media_url', 'magazine_media');
|
|
}
|
|
if($data['media_type'] == 'form' || $data['media_type'] == 'external') {
|
|
$data['media_url'] = $data['ext_url'];
|
|
}
|
|
if($data['media_type'] == 'gallery') {
|
|
$galleries = [];
|
|
if($request->file('gallery')) {
|
|
foreach($request->file('gallery') as $img) {
|
|
$galleries[] = env('AWS_URL').'/'.$img->store('magazine_media', 's3');
|
|
}
|
|
}
|
|
if(isset($data['gallery_existing'])) {
|
|
foreach($data['gallery_existing'] as $gallery_existing) {
|
|
$galleries[] = $gallery_existing;
|
|
}
|
|
}
|
|
$data['media_url'] = json_encode($galleries);
|
|
}
|
|
unset($data['gallery_existing']);
|
|
unset($data['gallery']);
|
|
unset($data['ext_url']);
|
|
//echo '<pre>'; print_r($data); exit;
|
|
return $data;
|
|
}
|
|
|
|
protected function _beforeform($type, $values) {
|
|
if($type == 'edit') {
|
|
if($values->media_type == 'form' || $values->media_type == 'external') {
|
|
$values->ext_url = $values->media_url;
|
|
} else {
|
|
$values->ext_url = '';
|
|
}
|
|
if($values->media_type == 'gallery' ) {
|
|
$values->gallery = json_decode($values->media_url);
|
|
}
|
|
unset($values->user_info);
|
|
unset($values->likes);
|
|
unset($values->likes_users);
|
|
unset($values->comments);
|
|
unset($values->views);
|
|
unset($values->comments_users);
|
|
unset($values->likes_count);
|
|
unset($values->comments_count);
|
|
if(!isset($values->mapped_metric)) {
|
|
$values->mapped_metric = '';
|
|
}
|
|
if(!isset($values->count_metric)) {
|
|
$values->count_metric = '';
|
|
}
|
|
|
|
//echo '<pre>'; print_r($values); exit;
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
public function viewers(Request $request) {
|
|
$id = $request->input('id', '');
|
|
$media = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_one', ['id' => $id]);
|
|
$media = $media->data->item;
|
|
$viewers = array_unique($media->views);
|
|
$users = LambdaRequest::signedrequest('get', 'ums', 'users/get_all', ['start' => 0, 'length' => 9999, 'search' => json_encode([]), 'keyword' => "" ]);
|
|
$users = $users->data->items;
|
|
$visitors = [];
|
|
foreach($users as $user) {
|
|
if( in_array($user->id, $viewers) ) {
|
|
$visitors[] = $user;
|
|
}
|
|
}
|
|
|
|
return $this->view('list')->with([
|
|
'title' => 'Viewers of Media : ' .$media->name,
|
|
'fields' => [
|
|
'employee_code' => ['title' => 'Employee Code', 'type' => 'text'],
|
|
'firstname' => ['title' => 'Firstname', 'type' => 'text'],
|
|
'lastname' => ['title' => 'Lastname', 'type' => 'text'],
|
|
'email' => ['title' => 'Email', 'type' => 'text'],
|
|
'roles' => ['title' => 'Roles', 'type' => 'text'],
|
|
'phone' => ['title' => 'Phone', 'type' => 'text'],
|
|
'designation' => ['title' => 'Designation', 'type' => 'text'],
|
|
'state' => ['title' => 'State', 'type' => 'text'],
|
|
'city' => ['title' => 'City', 'type' => 'text'],
|
|
],
|
|
'base_url' => $this->_base_url,
|
|
'items' => $visitors,
|
|
'buttons' => [ ['title' => 'Back to Media', 'link' => '/magmedias'], ['title' => 'Export Visitors', 'link' => '/magmedia/exportviewers?id='.$id] ]
|
|
]);
|
|
}
|
|
|
|
public function exportviewers(Request $request) {
|
|
$id = $request->input('id', '');
|
|
$media = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_one', ['id' => $id]);
|
|
$media = $media->data->item;
|
|
$viewers = array_unique($media->views);
|
|
$users = LambdaRequest::signedrequest('get', 'ums', 'users/get_all', ['start' => 0, 'length' => 9999, 'search' => json_encode([]), 'keyword' => "" ]);
|
|
$users = $users->data->items;
|
|
$visitors = [];
|
|
|
|
$headers = ['Employee Code', 'Firstname', 'Lastname', 'Email', 'Roles', 'Phone', 'Designation', 'State', 'City'];
|
|
$exceldata[] = $headers;
|
|
foreach($users as $user) {
|
|
if( in_array($user->id, $viewers) ) {
|
|
$row = [];
|
|
$row[] = isset($user->employee_code) ? $user->employee_code : '-';
|
|
$row[] = isset($user->firstname) ? $user->firstname : '-';
|
|
$row[] = isset($user->lastname) ? $user->lastname : '-';
|
|
$row[] = isset($user->email) ? $user->email : '-';
|
|
$row[] = isset($user->roles) ? $user->roles : '-';
|
|
$row[] = isset($user->phone) ? $user->phone : '-';
|
|
$row[] = isset($user->designation) ? $user->designation : '-';
|
|
$row[] = isset($user->state) ? $user->state : '-';
|
|
$row[] = isset($user->city) ? $user->city : '-';
|
|
$exceldata[] = $row;
|
|
}
|
|
}
|
|
return Excel::download(new InvoicesExport($exceldata), $media->name . ' - visitors.xlsx');
|
|
}
|
|
}
|