58 lines
1.6 KiB
PHP
Executable File
58 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Contracts\MobileAnalyticsResourceInterface;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use App\Libraries\ParameterHelper;
|
|
|
|
class ReportMobileUsageExport implements FromCollection
|
|
{
|
|
private $mobileAnalytics;
|
|
|
|
public function __construct(MobileAnalyticsResourceInterface $mobileAnalytics)
|
|
{
|
|
$this->mobileAnalytics = $mobileAnalytics;
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
public function collection()
|
|
{
|
|
$request = request();
|
|
|
|
$params = [
|
|
'page_size' => null,
|
|
'page' => null,
|
|
'date_start' => ($request->has('date_start') ? $request->get('date_start') : null),
|
|
'date_end' => ($request->has('date_end') ? $request->get('date_end') : null),
|
|
'sorting' => ParameterHelper::prepareSortingParameter($request)
|
|
];
|
|
|
|
|
|
if(ParameterHelper::validateStartEndDate($params))
|
|
{
|
|
return $this->format->unprocessableEntity('Start date must not be greater than end date');
|
|
}
|
|
|
|
$list = $this->mobileAnalytics->report_mobileUsage($params, true);
|
|
|
|
$data = collect([['Date', 'Active', 'Inactive', 'Locked']]);
|
|
|
|
if($list->count())
|
|
{
|
|
foreach ($list as $key => $value) {
|
|
$data->push([
|
|
date('d-M-Y',strtotime($value->date)),
|
|
$value->active == 0 ? "0" : $value->active,
|
|
$value->inactive == 0 ? "0" : $value->inactive,
|
|
$value->locked == 0 ? "0" : $value->locked,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|