public function index()
 {
     if (!Auth::check()) {
         return LoginController::getIndex();
     }
     LoginController::updateUserPermissions();
     //why not
     # Trail
     Trail::clear();
     $tables = array_where(config('center.tables'), function ($key, $value) {
         return !$value->hidden && LoginController::checkPermission($value->name, 'view');
     });
     $groups = $objects = [];
     foreach ($tables as $table) {
         $latest = DB::table($table->name)->leftJoin(config('center.db.users') . ' as u2', $table->name . '.updated_by', '=', 'u2.id')->select('u2.name as updated_name', $table->name . '.updated_at')->orderBy($table->name . '.updated_at', 'desc')->first();
         if (!isset($groups[$table->list_grouping])) {
             $groups[$table->list_grouping] = [];
         }
         $groups[$table->list_grouping][] = (object) ['title' => $table->title, 'list_grouping' => $table->list_grouping, 'link' => action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name), 'updated_name' => isset($latest->updated_name) ? $latest->updated_name : '', 'updated_at' => isset($latest->updated_at) ? $latest->updated_at : '', 'count' => number_format(DB::table($table->name)->count())];
     }
     foreach ($groups as $group) {
         $objects = array_merge($objects, $group);
     }
     $table = new Table();
     $table->rows($objects);
     $table->column('title', 'string', trans('center::site.table'));
     $table->column('count', 'integer', trans('center::site.count'));
     $table->column('updated_name', 'updated_name', trans('center::site.updated_name'));
     $table->column('updated_at', 'updated_at', trans('center::site.updated_at'));
     $table->groupBy('list_grouping');
     $table = $table->draw('tables');
     return view('center::tables.index', compact('table'));
 }
Exemple #2
0
 public static function pdf($table, $row_id)
 {
     # Get object / field / whatever infoz
     $table = config('center.tables.' . $table);
     # Security
     if (!isset($table->name)) {
         return redirect()->action('\\LeftRight\\Center\\Controllers\\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
     } elseif (!LoginController::checkPermission($table->name, 'view') || !$table->editable) {
         return redirect()->action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name)->with('error', trans('center::site.no_permissions_edit'));
     }
     # Retrieve instance/row values
     $row = DB::table($table->name)->where('id', $row_id)->first();
     # Output PDF to the browser
     return PDF::loadView('center::rows.pdf', compact('table', 'row'))->setPaper('letter', 'portrait')->stream($table->name . '-' . $row->id . '.pdf');
 }