svyatoslav-kubakh /
postfix-admin
| 1 | <?php |
||
| 2 | namespace backend\controllers; |
||
| 3 | |||
| 4 | use Yii; |
||
| 5 | use backend\models\Log; |
||
| 6 | use backend\models\User; |
||
| 7 | use backend\models\search\UserSearch; |
||
| 8 | use backend\models\search\LogSearch; |
||
| 9 | use backend\components\Controller; |
||
| 10 | use yii\web\NotFoundHttpException; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * MailerDomainController implements the CRUD actions for User model. |
||
| 14 | * @method User findModel($id) |
||
| 15 | */ |
||
| 16 | class UsersController extends Controller |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $modelClass = User::class; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Lists all User models. |
||
| 25 | * @return mixed |
||
| 26 | */ |
||
| 27 | public function actionIndex() |
||
| 28 | { |
||
| 29 | $searchModel = new UserSearch(); |
||
| 30 | $dataProvider = $searchModel->search( |
||
| 31 | Yii::$app->request->queryParams |
||
| 32 | ); |
||
| 33 | return $this->render('index', [ |
||
| 34 | 'dataProvider' => $dataProvider, |
||
| 35 | 'searchModel' => $searchModel, |
||
| 36 | ]); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Displays a single User model. |
||
| 41 | * @param integer $id |
||
| 42 | * @return mixed |
||
| 43 | * @throws NotFoundHttpException if the model cannot be found |
||
| 44 | */ |
||
| 45 | public function actionView($id) |
||
| 46 | { |
||
| 47 | $user = $this->findModel($id); |
||
| 48 | $logsSearchModel = new LogSearch(); |
||
| 49 | $logsDataProvider = $logsSearchModel->search([ |
||
| 50 | 'LogSearch' => ['user' => $user->username], |
||
| 51 | ]); |
||
| 52 | $logsDataProvider->pagination = false; |
||
| 53 | return $this->render('view', [ |
||
| 54 | 'model' => $user, |
||
| 55 | 'logsDataProvider' => $logsDataProvider, |
||
| 56 | 'itemTypes' => Log::listItemTypes(), |
||
| 57 | 'itemActions' => Log::listActions(), |
||
| 58 | ]); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Creates a new User model. |
||
| 63 | * If creation is successful, the browser will be redirected to the 'view' page. |
||
| 64 | * @return mixed |
||
| 65 | */ |
||
| 66 | public function actionCreate() |
||
| 67 | { |
||
| 68 | $model = new User(); |
||
| 69 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||
| 70 | return $this |
||
| 71 | ->addFlashMessage('User created: ' . $model->username, self::FLASH_SUCCESS) |
||
| 72 | ->redirect(['view', 'id' => $model->id]); |
||
| 73 | } |
||
| 74 | return $this->render('create', [ |
||
| 75 | 'model' => $model, |
||
| 76 | ]); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Updates an existing User model. |
||
| 81 | * If update is successful, the browser will be redirected to the 'view' page. |
||
| 82 | * @param integer $id |
||
| 83 | * @return mixed |
||
| 84 | * @throws NotFoundHttpException if the model cannot be found |
||
| 85 | */ |
||
| 86 | public function actionUpdate($id) |
||
| 87 | { |
||
| 88 | $model = $this->findModel($id); |
||
| 89 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||
| 90 | return $this |
||
| 91 | ->addFlashMessage('User updated: ' . $model->username, self::FLASH_SUCCESS) |
||
| 92 | ->redirect(['view', 'id' => $model->id]); |
||
| 93 | } |
||
| 94 | return $this->render('update', [ |
||
| 95 | 'model' => $model, |
||
| 96 | ]); |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Deletes an existing User model. |
||
| 101 | * If deletion is successful, the browser will be redirected to the 'index' page. |
||
| 102 | * @param integer $id |
||
| 103 | * @return mixed |
||
| 104 | * @throws NotFoundHttpException if the model cannot be found |
||
| 105 | */ |
||
| 106 | public function actionDelete($id) |
||
| 107 | { |
||
| 108 | $model = $this->findModel($id); |
||
| 109 | if ($model->delete()) { |
||
|
0 ignored issues
–
show
|
|||
| 110 | $this->addFlashMessage('User deleted: ' . $model->username, self::FLASH_WARNING); |
||
| 111 | } |
||
| 112 | return $this->redirect(['index']); |
||
| 113 | } |
||
| 114 | } |
||
| 115 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: