Blame view
app/Http/Controllers/Admin/UsersController.php
5.74 KB
8de035475 Создание: Структу... |
1 2 3 4 5 |
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; |
313a7a805 Работа с разделом... |
6 |
use App\Http\Requests\BaseUserRequest; |
8de035475 Создание: Структу... |
7 8 |
use App\Models\User; use Illuminate\Http\Request; |
bb2fb443d Архитектурное доп... |
9 |
use Illuminate\Support\Facades\Auth; |
313a7a805 Работа с разделом... |
10 11 12 13 14 |
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; |
8de035475 Создание: Структу... |
15 16 17 18 |
class UsersController extends Controller { public function index(Request $request) { |
f64f4890f Блейды и контролл... |
19 |
$title = 'Админка - Пользователи системы'; |
bb2fb443d Архитектурное доп... |
20 |
$id_admin = Auth::user()->id; |
8de035475 Создание: Структу... |
21 22 23 24 25 |
if ($request->ajax()) { $user = User::find($request->id); $request->offsetUnset('id'); $user->update($request->all()); } |
93a3f79f0 Поисковый движок ... |
26 27 28 29 30 31 32 33 |
$find_key = ""; $users = User::query(); if (isset($request->find)) { $find_key = $request->find; $users = $users->where('name', 'LIKE', "%$find_key%") ->orWhere('email', 'LIKE', "%$find_key%"); } $users = $users->paginate(15); |
8de035475 Создание: Структу... |
34 35 |
if ($request->ajax()) { |
bb2fb443d Архитектурное доп... |
36 |
return view('admin.users.index_ajax', compact('users', 'id_admin')); |
8de035475 Создание: Структу... |
37 |
} else { |
93a3f79f0 Поисковый движок ... |
38 |
return view('admin.users.index', compact('users', 'title', 'id_admin', 'find_key')); |
8de035475 Создание: Структу... |
39 40 |
} } |
313a7a805 Работа с разделом... |
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
public function index_bd(Request $request) { $title = 'Админка - Пользователи базы данных'; $find_key = ""; $users = User::query(); if (isset($request->find)) { $find_key = $request->find; $users = $users->where('name', 'LIKE', "%$find_key%") ->orWhere('email', 'LIKE', "%$find_key%") ->orWhere('telephone', 'LIKE', "%$find_key%"); } $users = $users->Baseuser()->paginate(15); if ($request->ajax()) { return view('admin.users.index_bd_ajax', compact('users')); } else { return view('admin.users.index_bd', compact('users', 'title', 'find_key')); } } public function add_bd() { return view('admin.users.add'); } public function add_store_bd(BaseUserRequest $request) { $params = $request->all(); $user = User::create($params); return redirect()->route('admin.worker-profile-add', ['user' => $user]); } public function edit_bd(User $user) { return view('admin.users.edit', compact('user')); } public function update_bd(BaseUserRequest $request, User $user) { $params = $request->all(); $user->update($params); return redirect()->route('admin.basedata'); } public function destroy_bd(User $user) { $user->delete(); return redirect()->route('admin.basedata'); } |
29350503f Расширение полей ... |
86 87 88 89 90 91 |
public function roles(Request $request) { if ($request->ajax()) { $user = User::find($request->id); $request->offsetUnset('id'); $user->update($request->all()); } |
313a7a805 Работа с разделом... |
92 |
$users = User::query()->Realuser()->paginate(15); |
29350503f Расширение полей ... |
93 94 95 96 97 98 |
if ($request->ajax()) { return view('admin.users.roles.index_ajax', compact('users')); } else { return view('admin.users.roles.index', compact('users')); } |
bb2fb443d Архитектурное доп... |
99 |
} |
313a7a805 Работа с разделом... |
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
public function doc_bd(User $user) { $id = $user->id; $spreadsheet = new Spreadsheet(); $activeWorksheet = $spreadsheet->getActiveSheet(); $activeWorksheet->setCellValue('A1', 'Отчет по соискателю'); $activeWorksheet->getStyle('A1')->applyFromArray([ 'font' => [ 'name' => 'Arial', 'bold' => true, 'italic' => false, 'underline' => Font::UNDERLINE_DOUBLE, 'strikethrough' => false, 'color' => [ 'rgb' => '808080' ] ], 'borders' => [ 'allBorders' => [ 'borderStyle' => Border::BORDER_THIN, 'color' => [ 'rgb' => '808080' ] ], ], 'alignment' => [ 'horizontal' => Alignment::HORIZONTAL_CENTER, 'vertical' => Alignment::VERTICAL_CENTER, 'wrapText' => true, ] ]); $activeWorksheet->setCellValue('A2', "Псевдоним/имя: ".$user->name); $activeWorksheet->setCellValue('A3', "Фамилия: ".$user->surname); $activeWorksheet->setCellValue('A4', "Имя: ".$user->name_man); $activeWorksheet->setCellValue('A5', "Отчество: ".$user->surname2); $activeWorksheet->setCellValue('A6', "Телефон: ".$user->telephone); $activeWorksheet->setCellValue('A7', "Емайл: ".$user->email); if (isset($user->workers[0]->id)) { $activeWorksheet->setCellValue('A9', "Анкета: "); $activeWorksheet->setCellValue('A10', "Телефон: " . $user->workers[0]->telephone); $activeWorksheet->setCellValue('A11', "Емайл: " . $user->workers[0]->email); } if (isset($user->jobtitles[0]->id)) { $activeWorksheet->setCellValue('A12', "Должность: " . $user->jobtitles[0]->name); } $writer = new Xlsx($spreadsheet); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="user'.$id.'.xlsx"'); header('Cache-Control: no-cache'); $writer->save('php://output'); $writer->save(storage_path("app/public/export/user$id.xlsx")); //$spreadsheet->disconnectWorksheets(); return redirect()->route('admin.basedata'); } |
8de035475 Создание: Структу... |
162 |
} |