public function validatePoll(Request $request, $eid)
 {
     $data = json_decode($request->getContent());
     $pollArray = $data->polloptions;
     //json list of poll options
     if (!empty($pollArray)) {
         $poll = new Poll();
         $poll->eid = $eid;
         $poll->polltype = 'date';
         $saveflag = $poll->save();
         if ($saveflag) {
             foreach ($pollArray as $poll_index) {
                 $poll_options = new PollOption();
                 $poll_options->pid = $poll['pid'];
                 $poll_options->option = $poll_index->option;
                 try {
                     PollOption::savePollOption($poll_options);
                 } catch (Exception $e) {
                     print '<script type="text/javascript">';
                     print 'alert( There have been issues adding options to your poll please
                     check home page for details)';
                     print '</script>';
                 }
             }
         } else {
             print '<script type="text/javascript">';
             print 'alert("Unable to save poll to database")';
             print '</script>';
         }
     }
 }
示例#2
0
 public function testRetrievePoll()
 {
     $this->startup();
     $poll = new Poll();
     $poll->eid = $this->event->eid;
     $poll->polltype = 'test_type';
     $poll->save();
     $this->seeInDatabase('polls', array('polltype' => 'test_type'));
 }
示例#3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, $orgId)
 {
     $poll = new \App\Poll();
     $poll->organization_id = $orgId;
     $poll->fill($request->input('Poll', []));
     $poll->closed_by = date("Y-m-d H:i:s", strtotime($poll->closed_by));
     if ($poll->isValid()) {
         $poll->save();
         return redirect()->route('poll.index', ['orgId' => $poll->organization_id]);
     } else {
         return redirect()->route('poll.create')->withErrors($poll->getErrors())->withInput();
     }
 }
 /**
  * Creates new polls from formdata
  * @param Request $request
  * @return mixed
  */
 public function create(Request $request)
 {
     // Ensure that they filled out the form properly
     if ($request->has('title')) {
         // Auth check, to make sure they are still valid
         if (Auth::check()) {
             // Pull the formdata
             $formdata = $request->all();
             echo '<pre>';
             var_dump($formdata);
             echo '</pre>';
             // This will hold question objects as we create them
             $questionArray = array();
             // Create a new poll object
             $poll = new Poll();
             // Save the formdata to the new poll object
             $poll->title = $formdata['title'];
             $poll->description = $formdata['description'];
             $poll->owner_id = Auth::id();
             // Save the poll object
             $poll->save();
             // Now we are going to look at questions / answers and create those attached to the poll
             foreach ($formdata as $key => $value) {
                 // If this is related to questions / answers, let's look further into it
                 if (strpos($key, 'question') !== FALSE) {
                     // Check if this is a question answer
                     if (strpos($key, 'answer') !== FALSE) {
                         // Extract the important stuff
                         $answer = explode('answer', $key);
                         // Get the answer number
                         $answer[0] = explode('question', $answer[0])[1];
                         // Get the question number
                         // Create a poll question answer object
                         $answerObject = new PollQuestionChoice();
                         // Look for the question this belongs to
                         foreach ($questionArray as $question) {
                             // Check to see if this is the question this answer belongs to
                             if ($question['formId'] == $answer[0]) {
                                 // Save the question ID onto the answer
                                 $answerObject->poll_question_id = $question['questionObject']->id;
                             }
                         }
                         // Save the last bits of data to the answer object and save
                         $answerObject->text = $value;
                         $answerObject->save();
                         // Otherwise this is a question
                     } else {
                         // Break apart the form input name so we can get at the number
                         $question = explode('question', $key);
                         // Instantiate a question object to represent our data
                         $questionObject = new PollQuestion();
                         // Attach our data to the new question object
                         $questionObject->text = $value;
                         $questionObject->poll_id = $poll->id;
                         // Save the data to the question
                         $questionObject->save();
                         // Save the question to an array
                         $questionArray[] = array('formId' => $question[1], 'questionObject' => $questionObject);
                     }
                 }
             }
             // Redirect the user back to their homepage with a success message
             return Redirect::to('/home')->with('success', 'Poll created successfully');
         }
     }
     // Redirect the user back to their homepage with a failure message
     return Redirect::to('/home')->with('error', 'Please fill out all required fields and try again');
 }
示例#5
0
 public function validatePoll($eid)
 {
     $input = Request::all();
     $dateList = $input['returndatepolls'];
     $pollArray = array_map('trim', explode(',', $dateList));
     if (!empty($pollArray)) {
         $poll = new Poll();
         $poll->eid = $eid;
         $poll->polltype = 'date';
         $saveflag = $poll->save();
         if ($saveflag) {
             foreach ($pollArray as $poll_index) {
                 $poll_options = new PollOption();
                 $poll_options->pid = $poll['pid'];
                 $poll_options->option = $poll_index;
                 try {
                     PollOption::savePollOption($poll_options);
                 } catch (Exception $e) {
                     print '<script type="text/javascript">';
                     print 'alert( There have been issues adding options to your poll please
                     check home page for details)';
                     print '</script>';
                     return view('events/invite_event');
                 }
             }
         } else {
             print '<script type="text/javascript">';
             print 'alert("Unable to save poll to database")';
             print '</script>';
             return view('events/create_poll');
         }
     }
     return view('events/invite_event')->with('eventID', $eid);
 }