added report data to api
This commit is contained in:
parent
36d7d6aae4
commit
cd42769029
@ -3,6 +3,7 @@
|
|||||||
namespace App\Transformers\Common;
|
namespace App\Transformers\Common;
|
||||||
|
|
||||||
use App\Models\Common\Report as Model;
|
use App\Models\Common\Report as Model;
|
||||||
|
use App\Utilities\Reports as Utility;
|
||||||
use League\Fractal\TransformerAbstract;
|
use League\Fractal\TransformerAbstract;
|
||||||
|
|
||||||
class Report extends TransformerAbstract
|
class Report extends TransformerAbstract
|
||||||
@ -16,16 +17,34 @@ class Report extends TransformerAbstract
|
|||||||
return [
|
return [
|
||||||
'id' => $model->id,
|
'id' => $model->id,
|
||||||
'company_id' => $model->company_id,
|
'company_id' => $model->company_id,
|
||||||
|
'class' => $model->class,
|
||||||
'name' => $model->name,
|
'name' => $model->name,
|
||||||
'alias' => $model->alias,
|
|
||||||
'description' => $model->description,
|
'description' => $model->description,
|
||||||
'type' => $model->type,
|
'settings' => $model->settings,
|
||||||
'group' => $model->group,
|
'data' => $this->getReportData($model),
|
||||||
'period' => $model->period,
|
|
||||||
'basis' => $model->basis,
|
|
||||||
'graph' => $model->graph,
|
|
||||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getReportData($model)
|
||||||
|
{
|
||||||
|
if (!Utility::canShow($model->class)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$report = Utility::getClassInstance($model);
|
||||||
|
|
||||||
|
if (empty($report)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$unset_attributes = ['model', 'views', 'loaded', 'column_name_width', 'column_value_width'];
|
||||||
|
|
||||||
|
foreach ($unset_attributes as $attribute) {
|
||||||
|
unset($report->$attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user