public function definition() { global $CFG; $question = null; $mform = $this->_form; // Don't forget the underscore! $this->dateIntervalScript(); $this->questionScript(); $namePage = 'Cadastrar Enquete'; if ($this->_customdata['question']) { $namePage = 'Editar Enquete'; $webgdCommunityDao = new WebgdCommunityDao(); $question = $webgdCommunityDao->searchQuestionByCommunityById($this->_customdata['question']); } $mform->addElement('hidden', 'path_arquivos', $CFG->dataroot . '/blocks/webgd_community' . '/', array('id' => 'path_arquivos')); $mform->addElement('hidden', 'community', $this->_customdata['community']); $mform->addElement('text', 'nome', "Pergunta"); $mform->addRule('nome', get_string('labelValidacaoNome', 'block_webgd_community'), 'required', null, 'client'); $mform->addElement('text', 'from', 'Data Inicio', array("id" => "from")); $mform->addRule('from', null, 'required', null, 'client'); $mform->addElement('text', 'to', 'Data Fim', array("id" => "to")); $mform->addRule('to', null, 'required', null, 'client'); $options = array('1' => 'Sim', '0' => 'Não'); $mform->addElement('select', 'enable', 'Habilitado', $options); $mform->addElement('filepicker', 'attachmentQuestion', 'Pergunta em Libras', null, array('accepted_types' => '*')); $nameButton = 'Salvar'; $mform->addElement("html", "<div style='background: #f5f5f5; margin-bottom:-30px;'>"); $mform->addElement('file', 'attachmentAnswer', 'Respostas em Libras', null, array('accepted_types' => '*')); $mform->addElement('hidden', 'video', array("id" => "video_hidden")); $mform->addElement("html", "</div>"); $buttonarray = array(); $buttonarray[] =& $mform->createElement('text', 'pergunta', 'Adicionar Resposta', array("id" => "nome_pergunta")); $buttonarray[] =& $mform->createElement('button', 'bt_pergunta', 'Adicionar', array("id" => "bt_pergunta")); $mform->addGroup($buttonarray, 'buttonar', 'Adicionar Resposta', array(' '), false); if (!empty($question)) { $nameButton = 'Salvar'; $mform->setDefault("nome", $question->name); $mform->setDefault("from", date("d/m/Y", $question->startdate)); $mform->setDefault("to", date("d/m/Y", $question->enddate)); $mform->setDefault("enable", $question->enabled); $mform->addElement('hidden', 'question', $this->_customdata['question']); $answers = $webgdCommunityDao->searchAskQuestionByCommunityById($question->id); $mform->addElement("html", "<div id='perfuntas'>"); foreach ($answers as $dataAnswer) { $rand = rand(); $mform->addElement("html", "<div id=" . $rand . " >Resposta: " . $dataAnswer->name_question . " <a href='#' onclick=\"remover('" . $rand . "')\"><input type=\"hidden\" value='" . $dataAnswer->name_question . "' name=\"pergunta[]\"><input type=\"hidden\" value='" . $dataAnswer->video . "' name=\"video[]\"> remover</a><br></div>"); } $mform->addElement("html", "</div>"); } else { $mform->addElement("html", "<div id='perfuntas'></div>"); } $buttonarray = array(); $buttonarray[] =& $mform->createElement('submit', 'submitbutton', $nameButton); //$buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert')); $buttonarray[] =& $mform->createElement('button', 'cancelar', 'Cancelar', 'onclick=location.href="' . $CFG->wwwroot . '/blocks/webgd_community/view.php?community=' . $this->_customdata['community'] . '"'); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); }
$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); echo "{$question->name} <br>"; if ($question->attachmentquestion != '' && $question->attachmentquestion != '0') { echo "<div><video controls preload='none'>\n <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $idQuestion . "&q=1' type='video/webm'>\n <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $idQuestion . "&q=1' type='video/mpeg'>\n <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $idQuestion . "&q=1' type='video/mp4'>\n <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $idQuestion . "&q=1' type='video/ogg'>\n </video></div>"; } echo '<form method="POST" action="">'; $totalRespondidas = $webgdCommunityDao->getTotalRespondidasEnquete($question->id); foreach ($perguntas as $pergunta) { $nrRespondidas = $webgdCommunityDao->getTotalRespondidasEnqueteByPergunta($pergunta->id); if ($totalRespondidas == 0) { //evitando divisão por zero $porcentagem = 0; } else { $porcentagem = $nrRespondidas * 100 / $totalRespondidas; } echo '<hr><input type="radio" name="resposta" value="' . $pergunta->id . '"> <progress max="100" value="' . $porcentagem . '"></progress> ' . $pergunta->name_question . '<br>';