Example #1
0
 public function getTabAction(Record $record, Table $table, Tab $tab)
 {
     $relations = $table->hasManyRelation(function (HasMany $relation) use($tab) {
         $relation->where('dynamic_table_tab_id', $tab->id);
         //$relation->withShowTable();
         //$relation->withOnField();
     });
     $table->morphsManyRelation(function (MorphsMany $relation) use($tab) {
         $relation->where('dynamic_table_tab_id', $tab->id);
         //$relation->withShowTable();
         //$relation->withOnField();
     })->each(function ($item) use($relations) {
         $relations->push($item);
     });
     $table->morphedByRelation(function (MorphedBy $relation) use($tab) {
         $relation->where('dynamic_table_tab_id', $tab->id);
         //$relation->withShowTable();
         //$relation->withOnField();
     })->each(function ($item) use($relations) {
         $relations->push($item);
     });
     $tabs = $table->tabs;
     $tabelizes = [];
     $relations->each(function (Relation $relation) use($tabs, $record, &$tabelizes) {
         $entity = $relation->showTable->createEntity();
         $entity->setStaticDynamicRecord($record);
         $entity->setStaticDynamicRelation($relation);
         $entity->where($relation->onField->field, $record->id);
         $tabelize = $this->getViewTableAction((new Tables())->where('id', $relation->showTable->id)->one(), $this->dynamic, $entity, 'related');
         $tabelizes[] = is_array($tabelize) ? \json_encode($tabelize) : (string) $tabelize;
     });
     $functionizes = [];
     $functions = $table->functions(function (HasMany $functions) use($tab) {
         $functions->where('dynamic_table_tab_id', $tab->id);
     });
     $pluginService = $this->pluginService;
     $args = [$record];
     if ($table->framework_entity) {
         $args[] = $table->createEntity()->where('id', $record->id)->one();
     }
     $functions->each(function (Func $function) use($tabs, &$functionizes, $pluginService, $record, $args) {
         $functionize = $pluginService->make($function->class, ($this->request()->isGet() ? 'get' : 'post') . ucfirst($function->method), $args);
         $functionizes[] = (string) $functionize;
     });
     /**
      * We have to build tab.
      */
     return view('edit/tab', ['functionizes' => $functionizes, 'tabelizes' => $tabelizes]);
 }