/** * Create the table rows * * @param $modelVars * @param $useLang * * @return array * */ protected function makeTableRows($modelVars, $useLang) { $models = $modelVars['models']; $dash_models = $modelVars['dash-models']; $camelModel = $modelVars['camelModel']; $CamelModel = $modelVars['CamelModel']; $relationModelList = GeneratorsServiceProvider::getRelationsModelVarsList(GeneratorsServiceProvider::splitFields($this->cache->getFields(), true)); $fields = GeneratorsServiceProvider::splitFields($this->cache->getFields(), SCOPED_EXPLODE_WANT_ID_RECORD | SCOPED_EXPLODE_WANT_TEXT); $fields = GeneratorsServiceProvider::filterFieldHavingOption($fields, 'hidden'); // First, we build the table headings if ($useLang) { $headings = array_map(function ($field) use($dash_models, $fields, $models, $CamelModel) { $type = $fields[$field]; if (preg_match('/\\bbitset\\b/', $type)) { return <<<PHP @foreach({{app_namespace}}\\{$CamelModel}::\${$field}_bitset as \$type => \$flag) <th>@lang('{$models}.'.\$type)</th> @endforeach PHP; } else { return '<th>@lang(\'' . $dash_models . '.' . $field . '\')</th>'; } }, array_keys($fields)); } else { $headings = array_map(function ($field) use($CamelModel, $fields) { $type = $fields[$field]; if (preg_match('/\\bbitset\\b/', $type)) { $Type = ucwords($type); return <<<PHP @foreach({{app_namespace}}\\{$CamelModel}::\${$field}_bitset as \$type => \$flag) <th>{{ucwords(str_replace('_', ' ', \$type))}}</th> @endforeach PHP; } else { return '<th>' . ucwords($field) . '</th>'; } }, array_keys($fields)); } // And then the rows, themselves $nextIndent = ''; $fields = array_map(function ($field) use($camelModel, $fields, $relationModelList, $CamelModel, &$nextIndent) { list($type, $options) = GeneratorsServiceProvider::fieldTypeOptions($fields[$field]); $nullable = strpos($options, 'nullable') !== false; $indent = $nextIndent; $nextIndent = "\t"; if (strpos($options, 'hidden') !== false) { unset($fields[$field]); return null; } if (preg_match('/\\bbitset\\b/', $options)) { $params = preg_match('/bitset\\((.*)\\)/', $options, $matches) ? $matches[1] : ''; if ($params === '') { $params = $field; } $params = explode(',', $params); return <<<PHP @foreach({{app_namespace}}\\{$CamelModel}::\${$field}_bitset as \$type => \$flag) <td>{{ \${$camelModel}->\$type }}</td>; @endforeach PHP; } elseif ($type === 'integer' || $type === 'bigInteger') { if (array_key_exists($field, $relationModelList)) { $relFuncName = trim_suffix($field, '_id'); $nameCol = $relationModelList[$field]['name']; if ($nullable) { return "{$indent}<td>{{ is_null(\${$camelModel}->{$field}) ? '' : \${$camelModel}->{$field} . ':' . \${$camelModel}->{$relFuncName}->{$nameCol} }}</td>"; } else { return "{$indent}<td>{{ \${$camelModel}->{$field} . ':' . \${$camelModel}->{$relFuncName}->{$nameCol} }}</td>"; } } } return "{$indent}<td>{{ \${$camelModel}->{$field} }}</td>"; }, array_keys($fields)); // Now, we'll add the edit and delete buttons. $editAndDelete = <<<EOT <td> {!! Form::open(['style' => 'display: inline-block;', 'method' => 'DELETE', 'route' => ['{$models}.destroy', \${$camelModel}->id, ], ]) !!} {!! formSubmit('Delete', ['class' => 'btn btn-danger', ]) !!} {!! Form::close() !!} {!! link_to_route('{$models}.edit', 'Edit', array(\${$camelModel}->id), ['class' => 'btn btn-info',]) !!} </td> EOT; return [$headings, $fields, $editAndDelete]; }