示例#1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFeedbackComments()
 {
     return $this->hasMany(FeedbackComments::className(), ['user_id' => 'id']);
 }
 public function actionCreate()
 {
     $model = new SdaFeedback();
     $request = Yii::$app->request;
     $data = json_decode($request->post('data'), true);
     $congress_id = isset($data['congress_id']) ? $data['congress_id'] : "";
     $sda_id = isset($data['sda_id']) ? $data['sda_id'] : "";
     $session_id = isset($data['session_id']) ? $data['session_id'] : "";
     $additional_data = isset($data['additional_data']) ? $data['additional_data'] : "";
     $ol_feedback = isset($data['ol_feedback']) ? $data['ol_feedback'] : "";
     $ques_ans = !empty($data['ques_ans']) ? $data['ques_ans'] : [];
     $takeaway_summary = !empty($data['takeaway_summary']) ? $data['takeaway_summary'] : [];
     $audience_size = isset($data['audience_size']) && $data['audience_size'] != "" ? $data['audience_size'] : 0;
     $debrief = isset($data['debrief']) && $data['debrief'] != "" ? $data['debrief'] : 0;
     $attendee_id = isset($data['attendee_id']) && $data['attendee_id'] != "" ? $data['attendee_id'] : "";
     $imageCount = isset($data['imageCount']) && $data['imageCount'] != "" ? $data['imageCount'] : "";
     $user_id = isset($data['user_id']) && $data['user_id'] != "" ? $data['user_id'] : "";
     $is_active = 1;
     $datas = \Yii::$app->db->createCommand("select id from sda_feedback WHERE sda_id=:sda_id and congress_id=:congress_id and user_id=:user_id")->bindValue(':sda_id', $sda_id)->bindValue(':congress_id', $congress_id)->bindValue(':user_id', $user_id)->queryAll();
     if ($datas) {
         $debrief = $debrief == 'YES' ? 1 : 0;
         \Yii::$app->db->createCommand()->update('sda_feedback', ['congress_id' => $congress_id, 'sda_id' => $sda_id, 'session_id' => $session_id, 'additional_data' => $additional_data, 'ol_feedback' => $ol_feedback, 'questions_ans' => json_encode($ques_ans, JSON_UNESCAPED_SLASHES), 'audience_size' => $audience_size, 'takeaway_summary' => json_encode($takeaway_summary, JSON_UNESCAPED_SLASHES), 'attendee_id' => $attendee_id, 'user_id' => $user_id, 'debrief' => $debrief, 'modify_date' => date("Y-m-d H:i:s")], 'id =' . $datas[0]['id'])->execute();
         $lastid = $datas[0]['id'];
     } else {
         $model->congress_id = $congress_id;
         $model->sda_id = $sda_id;
         $model->session_id = $session_id;
         $model->additional_data = $additional_data;
         $model->ol_feedback = $ol_feedback;
         $model->questions_ans = json_encode($ques_ans, JSON_UNESCAPED_SLASHES);
         $model->audience_size = $audience_size;
         $model->takeaway_summary = json_encode($takeaway_summary, JSON_UNESCAPED_SLASHES);
         //implode(",",$takeaway_summary);// != "" ? ($takeaway_summary) : "";
         $model->attendee_id = $attendee_id;
         $model->user_id = $user_id;
         $model->debrief = $debrief == 'YES' ? 1 : 0;
         $model->is_active = 1;
         $model->save(FALSE);
         $lastid = $model->id;
     }
     $image_ids = '';
     if ($lastid > 0) {
         if (!empty($ques_ans)) {
             foreach ($ques_ans as $ques_anss) {
                 $commentmodel = new FeedbackComments();
                 $commentmodel->feedback_type = "questions_ans";
                 $commentmodel->feedback_id = $lastid;
                 $commentmodel->comment = $ques_anss['title'];
                 $commentmodel->pid = 0;
                 $commentmodel->user_id = $user_id;
                 $commentmodel->createdOn = date("Y-m-d H:i:s", strtotime(str_replace("at", "", $ques_anss['date'])));
                 $commentmodel->active = 1;
                 $commentmodel->save(FALSE);
             }
         }
         //takeaway summary
         if (!empty($takeaway_summary)) {
             foreach ($takeaway_summary as $takeaway_summarys) {
                 $commentmodel = new FeedbackComments();
                 $commentmodel->feedback_type = "takeaway_summary";
                 $commentmodel->feedback_id = $lastid;
                 $commentmodel->pid = 0;
                 $commentmodel->comment = $takeaway_summarys['title'];
                 $commentmodel->user_id = $user_id;
                 $commentmodel->createdOn = date("Y-m-d H:i:s", strtotime(str_replace("at", "", $takeaway_summarys['date'])));
                 $commentmodel->active = 1;
                 $commentmodel->save(FALSE);
             }
         }
         $validation = array('jpg', 'png', 'gif', 'jpeg');
         if ($imageCount > 0) {
             for ($i = 1; $i <= $imageCount; $i++) {
                 $imgsArr = explode(".", $_FILES['imageFile' . $i]['name']);
                 $ext = end($imgsArr);
                 if (in_array($ext, $validation)) {
                     $file = str_replace("." . $ext, "", $_FILES['imageFile' . $i]['name']);
                     $thumbFile = str_replace("." . $ext, "", $_FILES['thumb' . $i]['name']);
                     $imageName = time() . "_{$i}." . $ext;
                     $destination = 'feedbackattachments/' . $imageName;
                     $destination2 = 'feedbackattachments/thumb/' . $imageName;
                     //Moving main image
                     move_uploaded_file($_FILES['imageFile' . $i]['tmp_name'], $destination) or die("error in uploading");
                     //Moving Thumbnai
                     move_uploaded_file($_FILES['thumb' . $i]['tmp_name'], $destination2) or die("error in uploading");
                     $modelattachment = new \backend\models\SdaAttachments();
                     $modelattachment->sda_feedback_id = $lastid;
                     $modelattachment->congress_id = $congress_id;
                     $modelattachment->sda_id = $sda_id;
                     $modelattachment->session_id = $session_id;
                     $modelattachment->path = '/' . $destination;
                     $modelattachment->save(FALSE);
                     $image_ids .= $modelattachment->id . ",";
                 }
             }
         }
         return array('message' => "Information saved successfully !", 'sda_feedback_id' => $lastid, 'latest_image_id' => $image_ids);
     }
 }