Skip to content

Commit

Permalink
added report data to api
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jan 29, 2021
1 parent 36d7d6a commit cd42769
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions app/Transformers/Common/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Transformers\Common;

use App\Models\Common\Report as Model;
use App\Utilities\Reports as Utility;
use League\Fractal\TransformerAbstract;

class Report extends TransformerAbstract
Expand All @@ -16,16 +17,34 @@ public function transform(Model $model)
return [
'id' => $model->id,
'company_id' => $model->company_id,
'class' => $model->class,
'name' => $model->name,
'alias' => $model->alias,
'description' => $model->description,
'type' => $model->type,
'group' => $model->group,
'period' => $model->period,
'basis' => $model->basis,
'graph' => $model->graph,
'settings' => $model->settings,
'data' => $this->getReportData($model),
'created_at' => $model->created_at ? $model->created_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;
}
}

0 comments on commit cd42769

Please sign in to comment.