public function destroy($id)
 {
     $question = Question::find($id);
     $question->delete();
     Session::flash('message', 'Usuário deletado com sucesso!');
     return Redirect::to('questions');
 }
Example #2
0
 public function postQues()
 {
     if (Session::get('currentqid') != Input::get('qid')) {
         return Response::json('error', 400);
     }
     if (Session::get('currentbatchid') != Input::get('batchid')) {
         return Response::json('error', 400);
     }
     $question = Question::find(Session::get('currentqid'));
     $question->user_id = Auth::id();
     $question->batchentry_id = Input::get('batchid');
     $question->qbodytext = Input::get('qbodytext');
     $question->aoptiontext = Input::get('aoptiontext');
     $question->boptiontext = Input::get('boptiontext');
     $question->coptiontext = Input::get('coptiontext');
     $question->doptiontext = Input::get('doptiontext');
     $question->solutiontext = Input::get('solutiontext');
     $question->exam_id = Input::get('exam_id');
     $question->exam_year = Input::get('examyear');
     $question->topic_id = Input::get('topicid');
     $question->doubt = Input::get('doubt');
     $question->page_no = Input::get('pageNo');
     $question->correctans = Input::get('correctans');
     $question->complete = 1;
     $question->save();
     return Response::json(array('flash' => 'Question id', Session::get('currentqid') . 'sucessfully updated!'), 200);
 }
 public function postSave()
 {
     $postData = Input::all();
     if ($postData['formOrigin'] == "edit") {
         $rules = array('topic' => 'required', 'correct_answer' => 'required');
         $validator = Validator::make($postData, $rules);
         if ($validator->fails()) {
             return Redirect::to('backends/quizz/edit/' . $postData['id'])->withInput()->withErrors($validator);
         } else {
             $question = Question::find($postData['id']);
             $question->topic = $postData['topic'];
             $question->correct_answer = $postData['correct_answer'];
             $question->save();
             return Redirect::to('backends/quizz/edit/' . $question->id);
         }
     } else {
         $rules = array('topic' => 'required');
         $validator = Validator::make($postData, $rules);
         if ($validator->fails()) {
             return Redirect::to('backends/quizz/add')->withInput()->withErrors($validator);
         } else {
             $question = Question::create(['topic' => $postData['topic']]);
             return Redirect::to('backends/quizz/edit/' . $question->id);
         }
     }
 }
 private function question_belongs_to_users($id)
 {
     $question = Question::find($id);
     if ($question->user_id == Auth::user()->user_id) {
         return true;
     }
     return false;
 }
 public function singleQuestion($qid)
 {
     $insertView = Question::find($qid);
     $currentNumberOfView = $insertView->numsofview;
     $insertView->numsofview = $currentNumberOfView + 1;
     $insertView->save();
     return View::make('questions.single-question')->with('title', 'Single Question')->with('singleQuestion', Question::find($qid));
 }
Example #6
0
 public function getQuestion($id)
 {
     $i = -1;
     $question = Question::find($id);
     $choices = Choice::orderby('id')->having('question_id', '=', $id)->get();
     $choices_count = Choice::where('question_id', $id)->count();
     return View::make('admin.student.studentqcm')->with(compact('question', 'choices', 'choices_count', 'i'));
 }
Example #7
0
 public function deleteQuestions($id)
 {
     $question = Question::find($id);
     Question::destroy($id);
     Session::flash('flash_msg', "La question N° " . $question->idQuestion . " a bien été supprimée.");
     Session::flash('flash_type', "success");
     return Redirect::to('/admin/questions');
 }
Example #8
0
 public static function findByPapernameAndNums($paper_name, $numbers)
 {
     $paper_id = Paper::findId($paper_name);
     $qlist = Question::find(array('paper_id = :pid: AND number IN ({numbers:array})', 'bind' => array('pid' => $paper_id, 'numbers' => array_values($numbers))));
     if (count($qlist) == 0) {
         throw new Exception("Can not find any questions.");
     }
     return $qlist;
 }
Example #9
0
 public function postEdit($id)
 {
     $question = Question::find($id);
     $question->title = Input::get('title');
     $question->question = Input::get('question');
     $question->last_session = Session::getId();
     $question->answer = Input::get('answer');
     $question->is_visible = Input::get('is_visible', '1');
     $question->pin = Input::get('pin', '0');
     $question->save();
     return Redirect::to('faq');
 }
Example #10
0
 public function getDownvotequestion($id, $uID)
 {
     if (Auth::check() == NULL) {
         return Redirect::back()->with('alertError', "you have to be logged in to perform this action.");
     }
     //return $id . $uID;
     $data['question'] = Question::find($id);
     //return $data['question']->user_id . '==' . Auth::user()->id;
     if ($data['question']->user_id == Auth::user()->id) {
         return Redirect::back()->with('alertError', "You can not downvote your own question.");
     }
     $hasUserVoted = Qvote::where('user_id', '=', User::find(Auth::user()->id)->id)->where('question_id', '=', $id)->count();
     if ($hasUserVoted == 0) {
         $reputationTest = User::find(Auth::user()->id);
         if ($reputationTest->reputation < 125) {
             return Redirect::back()->with('alertError', "You need 125 reputation to downvote a question.");
         } else {
             $vote = new Qvote();
             $vote->user_id = User::find(Auth::user()->id)->id;
             $vote->question_id = $id;
             $vote->save();
             $userToUpdate = User::find($uID);
             $reputation = $userToUpdate->reputation;
             $reputation -= 2;
             //$userToUpdate->reputation = $reputation - 2;
             if ($reputation < 1) {
                 $userToUpdate->reputation = 1;
             } else {
                 $userToUpdate->reputation = $reputation;
             }
             $userToUpdate->save();
             $questionToDownVote = Question::find($id);
             $votes = $questionToDownVote->votes;
             $questionToDownVote->votes = $votes - 1;
             $questionToDownVote->save();
             $questionReputation = new Qreputation();
             $questionReputation->user_id = $uID;
             $questionReputation->question_id = $id;
             $questionReputation->points = "-2";
             $questionReputation->action = "downvote";
             $questionReputation->save();
             return Redirect::back();
         }
     } else {
         return Redirect::back()->with('alertError', "you have already voted this question.");
     }
 }
 public function generateQuestionChart($question_id, $title)
 {
     $answers = Question::find($question_id)->answers;
     $content = $answers->lists('content');
     $total = 0;
     $index = 0;
     $votes = array();
     foreach ($answers as $answer) {
         $count = UserAnswer::where('answer_id', '=', $answer->id)->count();
         $total += $count;
         $votes[$index++] = $count;
     }
     $index = 0;
     $percentages = array();
     foreach ($votes as $vote) {
         $percentages[$index++] = round($vote / $total * 100, 0, PHP_ROUND_HALF_UP);
     }
     return array('title' => $title, 'xaxis' => $content, 'percentages' => $percentages, 'votes' => $votes, 'total' => $total);
 }
 public function imgUpload()
 {
     $destinationPath = 'public/Figures';
     $file = Input::file('file');
     $type = Input::get('type');
     $extension = Input::file('file')->getClientOriginalExtension();
     //extension to check if specefic file type is allowed
     $fileName = Session::get('currentqid') . '_' . $type . '_' . '1' . '.' . $extension;
     $upload_success = Input::file('file')->move($destinationPath, $fileName);
     if ($upload_success) {
         $question = Question::find(Session::get('currentqid'));
         if ($type == 'qbody') {
             $question->qbodyimgname = $fileName;
             $question->save();
         }
         if ($type == 'aopt') {
             $question->aoptionimgname = $fileName;
             $question->save();
         }
         if ($type == 'bopt') {
             $question->boptionimgname = $fileName;
             $question->save();
         }
         if ($type == 'copt') {
             $question->coptionimgname = $fileName;
             $question->save();
         }
         if ($type == 'dopt') {
             $question->doptionimgname = $fileName;
             $question->save();
         }
         if ($type == 'sol') {
             $question->solutionimgname = $fileName;
             $question->save();
         }
         return Response::json($fileName);
     } else {
         return Response::json('error', 400);
     }
 }
 public function postGuardar()
 {
     $bandera = false;
     $id = Input::get('idQues');
     $ans = Input::get('res');
     $answers = Answer::all();
     $question = Question::find($id);
     $cantidad = Question::count();
     foreach ($answers as $a) {
         if ($a->id_question == $id) {
             $bandera = true;
             $answer = $a;
             break;
         }
     }
     if (!$bandera) {
         $answer = new Answer();
         $answer->id_question = $id;
         $ids = Auth::id();
         $student = Student::where('id_user', '=', $ids)->get()->first();
         $answer->id_student = $student->id;
         $answer->answer = $ans;
         $answer->result = QuestionsController::verifyAnswer($question, $ans);
         $answer->save();
     } else {
         $answer->result = QuestionsController::verifyAnswer($question, $ans);
         $answer->answer = $ans;
         $answer->save();
     }
     if ($cantidad == $id) {
         return Redirect::to('questions/exam?endTest=yes');
         //"holi ".$id." ".$ans;
     } else {
         if ($cantidad > $id) {
             return Redirect::to('questions/exam?numberQIn=' . ++$id);
         }
     }
 }
Example #14
0
 public function testAction()
 {
     $frontCache = new Phalcon\Cache\Frontend\Data(array("lifetime" => 172800));
     // Create the component that will cache "Data" to a "File" backend
     // Set the cache file directory - important to keep the "/" at the end of
     // of the value for the folder
     $cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => "../cache/cachefile/"));
     // Try to get cached records
     $cacheKey = "questions.txt";
     if ($cache->exists($cacheKey)) {
         $questions = $cache->get($cacheKey);
         foreach ($questions as $item) {
             echo $item->topic, "<br>";
         }
     } else {
         $questions = Question::find(array("order" => "q_id"));
         // Store it in the cache
         $cache->save($cacheKey, $questions);
         echo "from db<br>";
         foreach ($questions as $item) {
             echo $item->topic, "<br>";
         }
     }
 }
 public function getQuestion($id)
 {
     $question = Question::find($id);
     $fb_og = array('url' => Request::url(), 'title' => $question->content, 'description' => $question->content);
     return View::make('question')->with('question', $question);
 }
 public function postQuestionChange()
 {
     //message-notification
     $messages = array();
     //handle navigation
     $admin_navigation = new AdminNavigation();
     if ($admin_navigation->isNavigate()) {
         return $admin_navigation->goToN();
     }
     //handle chapter-text change
     //redirect after changed
     if (Input::has('chapter_change')) {
         $chapter = Chapter::find(Input::get('chapter_change'));
         $chapter->text = Input::get('chapter_text');
         $chapter->save();
         $messages['chapter_change_text'] = 'chapter-' . $chapter->id . ':saved';
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //handle delete-question
     //redirect after deleted, no need to modify other inputs
     if (Input::has('delete_question')) {
         $question = Question::find(Input::get('delete_question'));
         $store_question_id = $question->id;
         $question->delete();
         $messages['delete_question'] = 'question-' . $store_question_id . ':deleted';
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //handle change on a question (both this one, and it's options)
     //redirect after all-changes saved
     if (Input::has('question_change')) {
         $question = Question::find(Input::get('question_change'));
         //question-change, change question-text
         if (Input::has('question_text')) {
             $question->text = Input::get('question_text');
             $question->save();
             $messages['question_change_text'] = 'question-' . $question->id . ':saved';
         }
         //question-change, change question-chapter_id
         if (Input::has('chapter_id')) {
             $question->chapter_id = Input::get('chapter_id');
             $question->save();
             $new_chapter = $question->getChapter;
             $messages['question_change_chapter_id'] = 'question-' . $question->id . ':now belongs to chapter-' . $new_chapter->id;
         }
         //options-change
         if (Input::has('options')) {
             $options = Input::get('options');
             //save options-change
             $i = -1;
             foreach ($options as $option_id => $option_text) {
                 $option = Option::find($option_id);
                 $option->text = $option_text;
                 //reset all option-is_right = 0
                 //is_right set again with input-is_right checked
                 $option->is_right = 0;
                 $option->save();
                 $messages['options_change[' . ++$i . ']'] = 'option-' . $option->id . ':saved';
             }
             //modify option-is_right
             if (Input::has('is_right')) {
                 $option = Option::find(Input::get('is_right'));
                 //this option set is_right = 1
                 $option->is_right = 1;
                 $option->save();
                 $messages['options_change_is_right'] = 'option-' . $option->id . '-is_right:saved';
             }
         }
         //send message-notification
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //new-question
     //redirect after create new-one
     if (Input::has('new_question')) {
         //save new question
         $question = new Question();
         //delete + auto_increment >>> modify question-id not continuous
         //manually change question-id
         $last_question = Question::all()->last();
         $question->id = $last_question->id + 1;
         $question->text = Input::get('question_text');
         $question->chapter_id = Input::get('chapter_id');
         $question->save();
         $question_id = $question->id;
         $messages['new_question'] = 'question-' . $question->id . ':saved';
         //save new options
         $options_text = Input::get('options');
         $created_options = array();
         for ($i = 0; $i < 4; $i++) {
             $option = new Option();
             $option->text = $options_text[$i];
             $option->question_id = $question_id;
             $option->is_right = 0;
             $option->save();
             //store in array new-option in $created_options, to add is_right on which
             $created_options[$i] = $option;
             $messages['option[' . $i . ']'] = 'option-' . $option->id . ':saved';
         }
         if (Input::has('is_right')) {
             $right_option = Input::get('is_right');
             //get option from store-$created_options, which selected is_right
             $option = $created_options[$right_option];
             $option->is_right = 1;
             $option->save();
             $messages['option_is_right'] = 'option-' . $option->id . '-is_right:saved';
         }
         //send message-notification
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //as a fallback
     //send message-notification
     $this->messageController->send($messages, $this::MESSAGE_KEY);
     return Redirect::back();
 }
 public static function shareQuestionOnLinkedin($question_id)
 {
     $question = Question::find($question_id);
     $receiverDetail = User::find($question->user_id);
     $url = URL::to('/') . '/question/' . $question->id . '/' . $question->question_url;
     $comment = "I just posted a question on KarmaCircles.";
     $title = $question->subject;
     $description = $question->description;
     MessageHelper::shareOnLinkedin($receiverDetail->token, $url, $comment, $title, $description);
 }
Example #18
0
 /**
  * Delete the question
  *
  * @param $id
  */
 public function deleteAction($id)
 {
     $question = Question::find($id);
     if (is_null($question)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect question id');
     }
     $test = $question->test;
     /**
      * Check if we have results already
      */
     if (count(Result::where('test_id', $test->id)->get())) {
         return Redirect::route('tests.index')->with('error', 'Нельзя редактировать тест, на который есть ответы');
     }
     DB::table('answer')->where('question_id', $id)->delete();
     DB::table('question')->where('id', $id)->delete();
     return Redirect::route('tests.show', $test->id);
 }
Example #19
0
    });
    $app->get('/:id/questions', function ($id) use($app) {
        $ids = explode(';', $id);
        $questions = Question::whereIn('set_id', $ids)->get();
        $questions->load('answers');
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($questions);
    });
});
$app->group('/question(s)', function () use($app) {
    $app->get('/', function () use($app) {
        $questions = Question::with('answers')->get();
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($questions);
    });
    $app->get('/:id', function ($id) use($app) {
        $question = Question::with('answers')->find($id);
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($question);
    });
    $app->get('/:id/answers', function ($id) use($app) {
        $answers = Question::find($id)->answers;
        $res = $app->response();
        $res['Content-Type'] = 'application/json';
        $res->body($answers);
    });
});
$app->run();
 public function getDeletequestion()
 {
     Question::find($_GET['keyword'])->delete();
     Answer::where('question_id', $_GET['keyword'])->delete();
     return Redirect::to('backends/dashboard');
 }
Example #21
0
        return Redirect::to('/meetingRequests/groupOnly');
    }
});
Route::filter('QuestionGroupCheck', function ($route) {
    $Question_id = Route::input('id');
    $question_url = Route::input('question_url');
    $question_detail = Question::find($Question_id);
    if (empty($question_detail) || $question_detail->question_url != $question_url) {
        return Redirect::to('404');
    } elseif ($question_detail->access == 'private') {
        if (Auth::check()) {
            if ($question_detail->user_id != Auth::user()->id) {
                return;
            }
            $CurrentUser_group = Auth::User()->Groups;
            $QuestionGroup = Question::find($Question_id)->Groupquestion;
            foreach ($CurrentUser_group as $key => $valueUsers) {
                foreach ($QuestionGroup as $key => $valueQuestion) {
                    if ($valueUsers->id == $valueQuestion->group_id) {
                        return;
                    }
                }
            }
            return Redirect::to('404');
        } else {
            return Redirect::to('404');
        }
    } elseif ($question_detail->access == 'public') {
        return;
    }
});
Example #22
0
 /**
  * 查看题目信息
  * @param unknown $name
  * @throws Exception
  * @return boolean
  */
 public static function checkTKByName($name)
 {
     if (self::dataFormatCheck($name) != 1) {
         throw new Exception("input type is not available!");
     }
     $name = strtoupper(trim($name));
     try {
         $number = 0;
         switch ($name) {
             case 'SPM':
                 $number = 60;
                 break;
             case 'CPI':
                 $number = 230;
                 break;
             case 'EPQA':
                 $number = 88;
                 break;
             case 'EPPS':
                 $number = 225;
                 break;
             case '16PF':
                 $number = 187;
                 break;
             case 'SCL':
                 $number = 90;
                 break;
             default:
                 throw new Exception("no this Type data");
         }
         $paper_record = Paper::getListByName($name);
         if (isset($paper_record->id)) {
             $data = Question::find(array("paper_id = :paper_id:", 'bind' => array('paper_id' => intval($paper_record->id))));
             $data_count = count($data);
             if ($data_count == 0) {
                 echo "{$name} 数据为空";
                 return true;
             } else {
                 if ($data_count == $number) {
                     echo "<h1>" . $name . "题库</h1>";
                     foreach ($data as $record) {
                         echo "题目编号&nbsp;&nbsp;&nbsp;<span style='color:red'>" . $record->id;
                         echo "</span><br />";
                         echo "题目内容&nbsp;&nbsp;&nbsp;" . $record->topic;
                         echo "<br />";
                         echo "题目选项&nbsp;&nbsp;&nbsp;" . $record->options;
                         echo "<br />";
                         echo "题目所在试卷的题号&nbsp;&nbsp;&nbsp;<strong>" . $record->number;
                         echo "</strong><br />";
                         echo "题目所在的试卷好&nbsp;&nbsp;&nbsp;" . $record->paper_id;
                         echo "<hr />";
                     }
                 } else {
                     throw new Exception("Database Error or link error");
                 }
             }
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Example #23
0
 public static function getTopGroupQuery($CurrentUserId, $groupId, $start, $perpage)
 {
     $group_question = DB::table('users_groups')->join('questions', 'users_groups.user_id', '=', 'questions.user_id')->leftjoin('users', 'questions.user_id', '=', 'users.id')->select(array('questions.*', 'users_groups.group_id', 'users.karmascore'))->where('questions.user_id', '!=', $CurrentUserId)->where('users_groups.group_id', '=', $groupId)->where('questions.queryStatus', '=', 'open')->orderBy('users.karmascore', 'DESC')->skip($start)->take($perpage)->get();
     //echo '<pre>';print_r($group_question);die;
     $toppers = array();
     if (!empty($group_question)) {
         foreach ($group_question as $key => $value) {
             if (isset($value->user_id)) {
                 $value->user_id = User::find($value->user_id);
             }
             if (isset($value->id)) {
                 $value->giver_Info = Question::find($value->id)->GiversHelp;
                 $value->giver_Count = Question::find($value->id)->GiversHelp()->count();
             }
             $value->answered = 0;
             if (!$value->giver_Info->isEmpty()) {
                 foreach ($value->giver_Info as $key => $giver_Info) {
                     if (isset($giver_Info->user_id)) {
                         $toppers[] = $giver_Info->user_id;
                         if ($giver_Info->user_id == $CurrentUserId) {
                             $value->answered = 1;
                         } else {
                             if ($value->answered != '1') {
                                 $value->answered = 0;
                             }
                         }
                         $giver_Info->user_id = User::find($giver_Info->user_id);
                     }
                 }
             } else {
                 $value->answered = 0;
             }
             $value->skills = KarmaHelper::getSkillsname($value->skills);
         }
     }
     return $group_question;
 }
Example #24
0
 /**
  * Deletes the question
  **/
 public function getDelete($id)
 {
     //First, let's try to find the question:
     $question = Question::find($id);
     if ($question) {
         //We delete the question directly
         Question::delete();
         //We won't have to think about the tags and the answers, ,
         //because they are set as foreign key and we defined them cascading on deletion,
         //they will be automatically deleted
         //Let's return to the index page with a success message
         return Redirect::route('index')->with('success', 'Question deleted successfully!');
     } else {
         return Redirect::route('index')->with('error', 'Nothing to delete!');
     }
 }
 public function getdataByorder()
 {
     $currentTab = Input::get('currentTab');
     $setting = Input::get('setting');
     $groupId = Input::get('groupId');
     $group_question = "";
     $All_groups[] = array($groupId);
     $CurrentUserId = 0;
     $CurrentUser = "";
     if (Auth::check()) {
         $CurrentUser = Auth::User();
         $CurrentUserId = $CurrentUser->id;
         if ($CurrentUserId != "") {
             $CurrentUserId = $CurrentUserId;
         }
     }
     if ($currentTab == "topquery") {
         $group_question = DB::table('users_groups')->join('questions', 'users_groups.user_id', '=', 'questions.user_id')->select(array('questions.*', 'users_groups.group_id'))->where('questions.user_id', '!=', $CurrentUserId)->where('users_groups.group_id', '=', $groupId)->where('questions.queryStatus', '=', 'open')->orderBy('questions.created_at', 'DESC')->get();
         if ($setting == 'Recent') {
             if (!empty($group_question)) {
                 foreach ($group_question as $key => $value) {
                     if (isset($value->user_id)) {
                         $value->user_id = User::find($value->user_id);
                     }
                     if (isset($value->id)) {
                         $value->giver_Info = Question::find($value->id)->GiversHelp;
                         $value->giver_Count = Question::find($value->id)->GiversHelp()->count();
                     }
                     $value->answered = 0;
                     if (!$value->giver_Info->isEmpty()) {
                         foreach ($value->giver_Info as $key => $giver_Info) {
                             if (isset($giver_Info->user_id)) {
                                 $toppers[] = $giver_Info->user_id;
                                 if ($giver_Info->user_id == $CurrentUserId) {
                                     $value->answered = 1;
                                 } else {
                                     if ($value->answered != '1') {
                                         $value->answered = 0;
                                     }
                                 }
                                 $giver_Info->user_id = User::find($giver_Info->user_id);
                             }
                         }
                     } else {
                         $value->answered = 0;
                     }
                     $value->skills = KarmaHelper::getSkillsname($value->skills);
                 }
             }
         } elseif ($setting == 'Unanswered') {
             if (!empty($group_question)) {
                 foreach ($group_question as $key => $value) {
                     if (isset($value->user_id)) {
                         $value->user_id = User::find($value->user_id);
                     }
                     if (isset($value->id)) {
                         $value->giver_Info = Question::find($value->id)->GiversHelp;
                         $value->giver_Count = Question::find($value->id)->GiversHelp()->count();
                     }
                     $value->answered = 0;
                     if (!$value->giver_Info->isEmpty()) {
                         foreach ($value->giver_Info as $key => $giver_Info) {
                             if (isset($giver_Info->user_id)) {
                                 $toppers[] = $giver_Info->user_id;
                                 if ($giver_Info->user_id == $CurrentUserId) {
                                     $value->answered = 1;
                                 } else {
                                     if ($value->answered != '1') {
                                         $value->answered = 0;
                                     }
                                 }
                                 $giver_Info->user_id = User::find($giver_Info->user_id);
                             }
                         }
                     } else {
                         $value->answered = 0;
                     }
                     $value->skills = KarmaHelper::getSkillsname($value->skills);
                 }
                 $group_question = array_values(array_sort($group_question, function ($value) {
                     return $value->giver_Count;
                 }));
             }
         } elseif ($setting == 'Populer') {
             if (!empty($group_question)) {
                 foreach ($group_question as $key => $value) {
                     if (isset($value->user_id)) {
                         $value->user_id = User::find($value->user_id);
                     }
                     if (isset($value->id)) {
                         $value->giver_Info = Question::find($value->id)->GiversHelp;
                         $value->giver_Count = Question::find($value->id)->GiversHelp()->count();
                     }
                     $value->answered = 0;
                     if (!$value->giver_Info->isEmpty()) {
                         foreach ($value->giver_Info as $key => $giver_Info) {
                             if (isset($giver_Info->user_id)) {
                                 $toppers[] = $giver_Info->user_id;
                                 if ($giver_Info->user_id == $CurrentUserId) {
                                     $value->answered = 1;
                                 } else {
                                     if ($value->answered != '1') {
                                         $value->answered = 0;
                                     }
                                 }
                                 $giver_Info->user_id = User::find($giver_Info->user_id);
                             }
                         }
                     } else {
                         $value->answered = 0;
                     }
                     $value->skills = KarmaHelper::getSkillsname($value->skills);
                 }
                 $group_question = array_values(array_sort($group_question, function ($value) {
                     return $value->giver_Count;
                 }));
                 $group_question = array_reverse($group_question);
             }
         }
     }
     return View::make('group.ajax_group_queryOrder', array('group_question' => $group_question, 'coutTopQuery' => 0, 'CurrentUserId' => $CurrentUserId));
 }
Example #26
0
<?php

include '../../inc/init.inc';
if (isset($id) && is_numeric($id) && Question::exists($id)) {
    $res->question = Question::find($id);
    $res->responses = Question::find('all', array('conditions' => array('question_id' => $id), 'order' => 'created_at asc'));
    $res->useTemplate("Liste des Questions");
} else {
    echo "La question n'existe pas";
}
Example #27
0
 public function getAcceptanswer($aID, $qID, $uID)
 {
     //return $aID. ' '. $qID;
     $answerToAccept = Answer::find($aID);
     $answerToAccept->status = 'accepted';
     $answerToAccept->save();
     $questionToUpdate = Question::find($qID);
     $questionToUpdate->status = 'solved';
     $questionToUpdate->save();
     $userToUpdate = User::find($uID);
     $reputation = $userToUpdate->reputation;
     $userToUpdate->reputation = $reputation + 15;
     $userToUpdate->save();
     $answerReputation = new Areputation();
     $answerReputation->user_id = $uID;
     $answerReputation->answer_id = $aID;
     $answerReputation->points = "+15";
     $answerReputation->action = "accept";
     $answerReputation->save();
     $authReputation = new Areputation();
     $authReputation->user_id = Auth::user()->id;
     $authReputation->answer_id = $aID;
     $authReputation->points = "+2";
     $authReputation->action = "accept";
     $authReputation->save();
     $userReputation = User::find(Auth::user()->id);
     $rep = $userReputation->reputation;
     $userReputation->reputation = $rep + 2;
     $userReputation->save();
     return Redirect::back();
 }
Example #28
0
            }
            break;
    }
    $body .= '</tr>
				</tbody>
				</table>';
    echo $header . $body;
});
HTML::macro('survey', function ($survey, $questions) {
    $count = 1;
    $output = '<fieldset><legend><h2>' . $survey->title . '</h2></legend>';
    $output .= '<h3>' . $survey->slogan . '</h3><p> ' . $survey->description . ' </p>';
    $output .= Form::open();
    $output .= '<div class="col-xs-12 col-sm-12 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">';
    foreach ($questions as $question) {
        $answers = Question::find($question->id)->answers()->select(array('answers.id', 'text'))->get();
        if (count($answers)) {
            $output .= '<article class="question">';
            $output .= '<h4>' . $count++ . ' - ' . trim($question->text) . '</h4>';
            foreach ($answers as $answer) {
                $output .= '<div class="radio">';
                $output .= '<label>';
                $output .= '<input type="radio" name="' . trim($question->id) . '" value="' . trim($answer->id) . '">
				' . $answer->text . '';
                $output .= '</label>';
                $output .= '</div>';
            }
            $output .= '</article>';
        }
    }
    $output .= '<div class="clearfix">';
Example #29
0
 public function writeprojectdetailAction()
 {
     try {
         $manager = $this->session->get('Manager');
         $project_id = $manager->project_id;
         #添加项目判断,是否有被试答题,若有答题则不能更新配置的模块
         $result = $this->modelsManager->createBuilder()->columns(array('COUNT(Examinee.id) as count'))->from('Examinee')->join('QuestionAns', 'Examinee.id = QuestionAns.examinee_id AND Examinee.project_id = ' . $project_id)->getQuery()->execute();
         $result = $result->toArray();
         if ($result[0]['count'] > 0) {
             $this->dataReturn(array('error' => '已有被试答题,项目模块不可再修改!'));
             return;
         }
         if ($manager) {
             $module_names = array();
             $checkeds = $this->request->getpost('checkeds');
             $values = $this->request->getpost('values');
             $i = 0;
             foreach ($checkeds as $value) {
                 if ($value == 'true') {
                     $module_names[] = PmDB::getModuleName($values[$i]);
                 }
                 $i++;
             }
             #全选情况
             $project_detail_info = array();
             $index_names = array();
             if (count($module_names) == 10) {
                 $index = Index::find();
                 foreach ($index as $index_record) {
                     $index_names[] = $index_record->name;
                 }
                 $factor = Factor::find();
                 $factor_names = array();
                 foreach ($factor as $factor_record) {
                     $factor_names[] = $factor_record->name;
                 }
                 $question = Question::find();
                 $examination = array();
                 foreach ($question as $question_record) {
                     $paper_name = Paper::findFirst($question_record->paper_id)->name;
                     $examination[$paper_name][] = $question_record->number;
                 }
                 $project_detail_info['exam_json'] = json_encode($examination, JSON_UNESCAPED_UNICODE);
             } else {
                 #所有相关指标名数组
                 $index_names = PmDB::getIndexName($module_names);
                 #所有相关因子名数组
                 $factor_names = PmDB::getFactorName($index_names);
                 #所有相关试卷下题目的数组
                 $examination = PmDB::getQuestionName($factor_names);
                 $project_detail_info['exam_json'] = json_encode($examination, JSON_UNESCAPED_UNICODE);
             }
             #因子分类 以及寻找子因子
             $factors = PmDB::getAllDividedFactors($factor_names);
             $project_detail_info['factor_names'] = json_encode($factors, JSON_UNESCAPED_UNICODE);
             $project_detail_info['module_names'] = implode(',', $module_names);
             $project_detail_info['index_names'] = implode(',', $index_names);
             $project_detail_info['project_id'] = $project_id;
             #插入到project_detail 并更新状态
             PmDB::insertProjectDetail($project_detail_info);
             #模块配置的类型设为true
             #需求量表的上传设为false
             $this->dataReturn(array('success' => true));
             return;
         } else {
             $this->dataBack(array('error' => "您的身份验证出错!请重新登录!"));
             return;
         }
     } catch (Exception $e) {
         $this->dataReturn(array('error' => $e->getMessage()));
         return;
     }
 }
Example #30
0
            return Response::json(array("status" => "error", "errors" => $question->validator()->errors->all()));
        }
    }
    public function action_update()
    {
        $question = Config::get('question');
        $answer = trim(Input::get('answer'));
        if ($answer && $answer != "") {
            $question->answer = $answer;
            $question->answered_by = Auth::officer()->id;
            $question->save();
            return Response::json(array("status" => "success", "question" => $question->to_array(), "html" => View::make('projects.partials.question')->with('question', $question)->render()));
        } else {
            return Response::json(array("status" => "error", "errors" => array('No answer provided.')));
        }
    }
}
Route::filter('question_exists', function () {
    $id = Request::$route->parameters[0];
    $question = Question::find($id);
    if (!$question) {
        return Redirect::to('/');
    }
    Config::set('question', $question);
});
Route::filter('i_am_collaborator', function () {
    $question = Config::get('question');
    if (!$question->project->is_mine()) {
        return Redirect::to('/');
    }
});