Esempio n. 1
0
$PAGE->set_pagelayout('standard');
$webgdDao = new WebgdCommunityDao();
$idCommunity = optional_param('community', 0, PARAM_INTEGER);
$idQuestion = optional_param('question', 0, PARAM_INTEGER);
$community = $webgdDao->findCommunityById($idCommunity);
$url = $CFG->wwwroot . '/blocks/webgd_community/view.php?community=' . $idCommunity;
echo $OUTPUT->header('themeselector');
echo '<span class="titulo_list">' . '<a href="' . $url . '" >' . $OUTPUT->heading($community->name, 2, 'titulo_comunidade') . '</a>' . '</span><div style="clear:both"></div>';
if ($idQuestion) {
    $webgdCommunityDao = new WebgdCommunityDao();
    if ($question = $webgdCommunityDao->searchQuestionByCommunityById($idQuestion)) {
        if (isset($_POST['resposta'])) {
            global $DB;
            $msg = "Ocorreu um erro ao responder a enquete";
            //Se o usuário já respondeu, apaga a resposta dele para depois inserir a nova
            $webgdCommunityDao->deleteAskedQuestionByUserById($question->id, $USER->id);
            try {
                $transaction = $DB->start_delegated_transaction();
                $object = new stdClass();
                $object->userid = $USER->id;
                $object->answer_question = optional_param('resposta', 0, PARAM_INT);
                $object->time = time();
                $DB->insert_record(TableResouces::$TABLE_PAGE_COMMUNITY_ANSWER_QUESTION_USER, $object);
                $transaction->allow_commit();
                $msg = "Enquete Respondida com sucesso";
            } catch (Exception $e) {
                $transaction->rollback($e);
            }
            redirect($CFG->wwwroot . "/blocks/webgd_community/view.php?&community={$idCommunity}", $msg, 10);
        } else {
            $perguntas = $webgdCommunityDao->searchAskQuestionByCommunityById($question->id);