コード例 #1
0
 public function update($QuestionID)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $data = Request::capture();
     $count = $data['numAnswer'];
     // delete all old spaces with corresponding answers
     $oldSpaces = Spaces::where('QuestionID', '=', $QuestionID)->get()->toArray();
     foreach ($oldSpaces as $value) {
         SpacesController::destroy($value['id']);
     }
     for ($i = 0; $i < $count; $i++) {
         $rawAnswer = trim(AnswersController::c2s_convert($data['answer' . ($i + 1)]));
         preg_match_all('/([^;]+);/', $rawAnswer, $matches, PREG_PATTERN_ORDER);
         $arrayOfAnswer = $matches[1];
         $SpaceID = DB::table('spaces')->insertGetId(['QuestionID' => $QuestionID, 'created_at' => new \DateTime(), 'updated_at' => new \DateTime()]);
         $true = true;
         foreach ($arrayOfAnswer as $value) {
             $a = new Answers();
             $a->Logical = $true;
             $a->SpaceID = $SpaceID;
             $a->Detail = trim($value);
             $a->save();
             $true = false;
         }
     }
     return redirect(route('user.viewquestion', $QuestionID));
 }
コード例 #2
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $question = Questions::find($id);
     @unlink(public_path('images/imageQuestion/' . $question['Photo']));
     $postid = $question['PostID'];
     $format = $question['FormatID'];
     switch ($format) {
         case 1:
         case 6:
             $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($answers as $answer) {
                 AnswersController::destroy($answer['id']);
             }
             break;
         case 2:
             $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($spaces as $value) {
                 SpacesController::destroy($value['id']);
             }
             break;
         case 3:
             $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($answers as $answer) {
                 AnswersController::destroy($answer['id']);
             }
             break;
         case 4:
             $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($answers as $answer) {
                 AnswersController::destroy($answer['id']);
             }
             break;
         case 5:
             $subq = Subquestions::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($subq as $s) {
                 SubquestionsController::destroy($s['id']);
             }
     }
     $question->delete();
     return redirect(route('user.viewpost', $postid));
 }
コード例 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $question = Questions::find($id);
     @unlink(public_path('images/imageQuestion/' . $question['Photo']));
     $postid = $question['PostID'];
     $format = Posts::find($postid)['FormatID'];
     if ($format == 1) {
         $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
         foreach ($answers as $answer) {
             Answers::destroy($answer['id']);
         }
     } else {
         if ($format == 2) {
             $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($spaces as $value) {
                 SpacesController::destroy($value['id']);
             }
         }
     }
     $question->delete();
     return redirect(route('user.viewpost', $postid));
 }