2017-07-12 17:51:22 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-07-12 17:51:22 -07:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-07-12 17:51:22 -07:00
|
|
|
use App\Models\CustomFieldset;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class CustomFieldsetsTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformCustomFieldsets(Collection $fieldsets, $total)
|
2017-07-12 17:51:22 -07:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-07-12 17:51:22 -07:00
|
|
|
foreach ($fieldsets as $fieldset) {
|
|
|
|
$array[] = self::transformCustomFieldset($fieldset);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-07-12 17:51:22 -07:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformCustomFieldset(CustomFieldset $fieldset)
|
2017-07-12 17:51:22 -07:00
|
|
|
{
|
|
|
|
$fields = $fieldset->fields;
|
|
|
|
$models = $fieldset->models;
|
2021-06-10 13:15:52 -07:00
|
|
|
$modelsArray = [];
|
2017-07-12 19:23:15 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
foreach ($models as $model) {
|
2017-07-12 17:51:22 -07:00
|
|
|
$modelsArray[] = [
|
|
|
|
'id' => $model->id,
|
2021-06-10 13:15:52 -07:00
|
|
|
'name' => e($model->name),
|
2017-07-12 17:51:22 -07:00
|
|
|
];
|
|
|
|
}
|
2017-07-12 19:23:15 -07:00
|
|
|
|
2017-07-12 17:51:22 -07:00
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $fieldset->id,
|
2017-07-12 19:23:15 -07:00
|
|
|
'name' => e($fieldset->name),
|
2017-07-12 17:51:22 -07:00
|
|
|
'fields' => (new CustomFieldsTransformer)->transformCustomFields($fields, $fieldset->fields_count),
|
2017-07-29 17:01:03 -07:00
|
|
|
'models' => (new DatatablesTransformer)->transformDatatables($modelsArray, $fieldset->models_count),
|
|
|
|
'created_at' => Helper::getFormattedDateObject($fieldset->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($fieldset->updated_at, 'datetime'),
|
2017-07-12 17:51:22 -07:00
|
|
|
];
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-07-12 17:51:22 -07:00
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|