Exemplo n.º 1
0
 public function index($table_name = null)
 {
     $files = Csv::getCsvFiles();
     //edit for tab display
     foreach ($files as $file) {
         $tabs[] = substr($file, 0, -4);
     }
     if (Request::ajax()) {
         if (Input::has('tab')) {
             $table_name = Input::get('tab');
             //replace the tab variable stored in the session
             Session::put('table_name', $table_name);
         } else {
             if (Input::has('page')) {
                 //return Input::get('page');
                 $table_name = Session::get('table_name');
             }
         }
         //get the contents of the file
         $data = Csv::getCsvContents($table_name . '.csv');
         //return an object containing data
         $dataObject = Csv::prepareData($data);
         //display working with correct pagination - will not actually work tho
         $paginator = CustomPagination::createPagination($dataObject, Input::get('page'));
         return View::make('layouts.table')->with('paginator', $paginator)->with('heading', $dataObject->tableHeading)->with('colHeadings', $dataObject->colHeadings);
     }
     //no requests made then reset the session variable
     Session::put('table_name', $tabs[0]);
     $data = $table_name == null ? Csv::getCsvContents($files[0]) : Csv::getCsvContents($table_name . '.csv');
     $dataObject = Csv::prepareData($data);
     //no input given defaults to 1
     $input = Input::get('page', 1);
     $paginator = CustomPagination::createPagination($dataObject, $input);
     return View::make('home.index')->with('tabs', $tabs)->with('paginator', $paginator)->with('heading', $dataObject->tableHeading)->with('colHeadings', $dataObject->colHeadings);
 }