this is the controller for message view: public function actionView(int $id): Response…
- User
this is the controller for message view:
public function actionView(int $id): Response|string { $model = $this->findModel($id); $replyForm = new ReplyForm($model->id); //$replyForm = new ReplyForm($model);// Dependency injection. $request = \Yii::$app->request; if (($request->isPost) && ($replyForm->load($request->post()))) { // Check that Form status is not STATUS_REPLIED, this status should not be manually set via a form. $inputStatus = (int)$replyForm->status; if ($inputStatus !== Message::STATUS_REPLIED) { // Check that current model status is not STATUS_REPLIED and a reply hasn't been set. if (($model->status !== Message::STATUS_REPLIED) && (ValueHelper::isSetAndNull($model->replied))) { // Determine if a reply has been provided via the form. $getReply = ValueHelper::isSetNotNull($replyForm->reply); // Check if the status has changed from the original model status. $getStatus = $replyForm->status !== $model->status; // Determine scenario based on form changes. if ($getReply && $getStatus) { $replyForm->scenario = 'both'; } elseif ($getReply) { $replyForm->scenario = 'replyOnly'; } elseif ($getStatus) { $replyForm->scenario = 'statusOnly'; } } // Only status change is possible if replied is set. else { $replyForm->scenario = 'statusOnly'; } } // Use the selected scenario to validate form and process. if ($replyForm->validate()) { // Double-check that STATUS_REPLIED is not being saved. if ($inputStatus !== Message::STATUS_REPLIED) { if ($replyForm->process()) { $this->setScenarioSuccessFlash($replyForm->scenario, $model); return $this->redirect(['index']); } else { // Note: Error logging is handled within form Model(s) and user-facing error messages wthin the controller. $msg = \Yii::t('app', 'There was an error processing your request. Please try again.'); \Yii::$app->session->setFlash('error', $msg); } } // If trying to save $status as STATUS_REPLIED, give error. else { $msg = \Yii::t('app', 'Cannot save status to replied.'); \Yii::$app->session->setFlash('error', $msg); } } else { // Validation failed. $msg = \Yii::t('app', 'There was a validation error. Please check your input.'); \Yii::$app->session->setFlash('error', $msg); } } // First time viewing Message, change status to Read. if (($request->isGet) && ($model->status === Message::STATUS_UNREAD)) { $model->addStatus(Message::STATUS_READ); $model->save(false); } // Fetch replies for the message. $replies = $model->getReplies()->all(); return $this->render('view', [ 'model' => $model, 'replyForm' => $replyForm, 'replies' => $replies, ]); } private function setScenarioSuccessFlash(string $scenario, $model): void { switch ($scenario) { case 'statusOnly' : $msg = \Yii::t('app', 'The status for {to} has been updated.', ['to' => $model->email]); break; case 'replyOnly' : case 'both' : default : $msg = \Yii::t('app', 'Your reply to {to} has been sent.', ['to' => $model->email]); break; } \Yii::$app->session->setFlash('success', $msg); } - Assistant
- User
- Assistant
- User
oh i see what you did.. you made the dropdown list a checkboxes.. that isn't what the goal is, Im not sure if bootstrap 5 dropdownlist gives the option for multi select, but if it does... thats what i want.
- Assistant
- User
- Assistant