static function find($search_id) { $found_promptr = null; $promptrs = Promptr::getAll(); foreach ($promptrs as $promptr) { $id = $promptr->getId(); if ($search_id == $id) { $found_promptr = $promptr; } } return $found_promptr; }
$app->post("/promptr/{id}", function ($id) use($app) { $promptr = Promptr::find($id); $topic = Topic::find($promptr->getTopicId()); $new_question_text = $_POST['question']; $new_description = $_POST['description']; $new_question = new Question($new_question_text, $new_description); $new_question->save(); $promptr->addQuestion($new_question); return $app['twig']->render('promptr.html.twig', array('promptr' => $promptr, 'questions' => $promptr->getQuestions(), 'topic' => $topic)); }); // PROMPTRS.HTML.TWIG // ADD PROMPTR -- adds a prompter and displays promptrs within the topic $app->post("/promptrs", function () use($app) { $promptr_name = $_POST['promptr_name']; $topic_id = $_POST['topic_id']; $new_promptr = new Promptr($promptr_name, $topic_id); $new_promptr->save(); return $app['twig']->render('promptrs.html.twig', array('promptrs' => Promptr::getAll(), 'topic' => $topic_id, 'topic_picked' => true)); // flag for included template }); $app->get("/topic/{id}", function ($id) use($app) { $topic = Topic::find($id); $promptrs = $topic->getPromptrs(); $allT = Topic::getAll(); return $app['twig']->render("topic.html.twig", array('topic' => $topic, 'promptrs' => $promptrs, 'all_topics' => $allT)); }); // PROMPTR.HTML.TWIG //delete question from NEW PROMPTR route -- then displays promptr page $app->get("promptr/{id}", function ($id) use($app) { $promptr = Promptr::find($id); $questions = $promptr->getQuestions();
function test_getTrendingPromptrs() { $name = "mikes 5 top interview questions"; $topic_id = 5; $trending_index = 3; $test_promptr = new Promptr($name, $topic_id, $trending_index); $test_promptr->save(); $name2 = "mikes 50 top interview questions"; $trending_index2 = 4; $test_promptr2 = new Promptr($name2, $topic_id, $trending_index2); $test_promptr2->save(); $name3 = "mikes 500 top interview questions"; $trending_index3 = 5; $test_promptr3 = new Promptr($name3, $topic_id, $trending_index3); $test_promptr3->save(); $name4 = "mikes 5000 top interview questions"; $trending_index4 = 6; $test_promptr4 = new Promptr($name4, $topic_id, $trending_index4); $test_promptr4->save(); $name5 = "mikes 50000 top interview questions"; $trending_index5 = 7; $test_promptr5 = new Promptr($name5, $topic_id, $trending_index5); $test_promptr5->save(); $name6 = "mikes 500000 top interview questions"; $trending_index6 = 8; $test_promptr6 = new Promptr($name6, $topic_id, $trending_index6); $test_promptr6->save(); //Act $result = Promptr::getTrendingPromptrs(); //Assert $this->assertEquals([$test_promptr6, $test_promptr5, $test_promptr4, $test_promptr3, $test_promptr2], $result); }
}); // QUESTION.HTML.TWIG -- needs fixed -- if a question has been deleted, id # is skipped and // end_flag = true. Need to somehow loop through just the questions in promptr->getQuestions // the following pages of promptr run -- adding more answers $app->post("/promptr/{id}/question/{quid}", function ($id, $quid) use($app) { $promptr = Promptr::find($id); $end_flag = false; $answer_field = $_POST['answer']; $new_answer = new Answer($answer_field, $quid); $new_answer->save(); ++$quid; $question = Question::findTempById($quid); $questions = Question::getTempQuestions(); if ($question != null) { $question->addAnswer($new_answer->getId()); $last_question = end($questions); if ($question == $last_question) { $end_flag = true; } } return $app['twig']->render('question.html.twig', array('question' => $question, 'end' => $end_flag, 'promptr' => $promptr, 'questions' => $questions)); }); // DISPLAY.HTML.TWIG // DISPLAY FINISHED answers to promptr run //will show the concatted together display of the list $app->get("/promptr/{id}/display", function ($id) use($app) { $promptr = Promptr::find($id); $questions = Question::getTempQuestions(); Question::deleteTempQuestions(); return $app['twig']->render('display.html.twig', array('promptr' => $promptr, 'questions' => $questions)); });
function test_getPromptrs() { $name = "Writing"; $test_topic = new Topic($name); $test_topic->save(); $name2 = "Interview"; $test_topic2 = new Topic($name2); $test_topic2->save(); $promptr_name = "mikes 5 tips"; $topic_id = $test_topic->getId(); $test_promptr = new Promptr($promptr_name, $topic_id); $test_promptr->save(); $promptr_name2 = "ians 5 tips"; $topic_id = $test_topic->getId(); $test_promptr2 = new Promptr($promptr_name2, $topic_id); $test_promptr2->save(); $result = $test_topic->getPromptrs(); $this->assertEquals([$test_promptr, $test_promptr2], $result); }