Example #1
1
 public function __construct(Request $request)
 {
     $this->currentModel = new Content();
     $this->langModel = new ContentLang();
     $this->validation = \Validator::make($request->all(), ['name' => 'required:structure|max:255']);
     $modelStructure = new Structure();
     $treeStructure = $modelStructure->get()->sortBy('position');
     foreach ($treeStructure as $key => $struct) {
         $lang = StructureLang::where(['structure_id' => $struct['id'], 'language_id' => FormLang::getCurrentLang()])->first();
         if ($lang) {
             $treeStructure[$key]->name = $lang->name;
             $treeStructure[$key]->link = action('\\Application\\Admin\\Http\\Controllers\\StructureController@getEdit', ['id' => $struct['id']]);
         } else {
             unset($treeStructure[$key]);
         }
     }
     $treeStructure->linkNodes();
     $str = $treeStructure->toArray();
     $witgetStructureTree = new TreeBuilder();
     $TreeStructure = $witgetStructureTree->view($str, '<ul>{val}</ul>', '<li data-href="/admin/content/structure/{id}">{name}</li>', '<li data-href="/admin/content/structure/{id}" class="folder expanded">{name}<ul>{|}</ul></li>');
     view()->share('StructureTree', $TreeStructure);
     view()->share('id_structure', $request->route('id_structure'));
     $this->itemName = 'Content';
     $this->template = 'content';
     $this->layout = 'dual_sidebars';
     parent::__construct();
 }
Example #2
0
 public function postRebuild(Request $request)
 {
     $build = new TreeBuilder();
     $data = json_decode($request->input('data'), true);
     $newRelations = $build->generateRelations($data);
     foreach ($newRelations as $item) {
         $struct = $this->currentModel->find($item['id']);
         $struct->parent_id = $item['parent_id'];
         $struct->position = $item['position'];
         $struct->save();
     }
     Structure::fixTree();
     return $newRelations;
 }