Exemple #1
0
 public static function printTimelineQuestion($community, $post, $proprietario, $idCommunity, $automatico)
 {
     global $CFG, $OUTPUT;
     $images = self::imageById($community->userid);
     $now = time();
     if ($post->enabled == 1 && $now >= $post->startdate) {
         $resposta = "";
         $resposta .= "<div class='conteudo_post'>\n        <div class='titulo_post'>\n          <span class='icone_user'>";
         foreach ($images as $img) {
             $resposta .= $OUTPUT->user_picture($img, array('size' => 30, 'alttext' => false, 'link' => false));
         }
         $resposta .= "</span><span class='nome_post'>";
         if ($proprietario || self::isAdmin()) {
             $resposta .= "<span class='botao_excluir' style='cursor:pointer'><img src='" . $CFG->wwwroot . ImageResources::EXCLUIR . "' onclick=location.href='" . $CFG->wwwroot . "/blocks/webgd_community/menus/question/delete.php?question={$post->post}&community={$idCommunity}' ></span>";
             if ($post->startdate > $now) {
                 $resposta .= "<span class='botao_edicao' style='cursor:pointer'><img src='" . $CFG->wwwroot . ImageResources::EDITAR . "' onclick=location.href='" . $CFG->wwwroot . "/blocks/webgd_community/menus/question/question.php?question={$post->post}&community={$idCommunity}'></span>";
             }
         }
         $resposta .= "<span class='nome_criador'>" . html_writer::tag('a', $community->username, array('href' => $CFG->wwwroot . '/user/profile.php?id=' . $community->userid)) . "</span>\n              " . get_string('publicouEnq', 'block_webgd_community') . "\n              <div class='data'>" . strftime('%d de %B de %Y às %H %M %S ', $community->time) . "</div>\n            </span>\n                    </div>\n          <div class='informacoes_post'>\n            <span>" . Commons::make_links_blank($post->message) . "</span>";
         if ($post->attachmentquestion != '' && $post->attachmentquestion != "0") {
             $resposta .= "<div><video controls preload='none'>\n              <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $post->post . "&q=1' type='video/webm'>\n              <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $post->post . "&q=1' type='video/mpeg'>\n              <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $post->post . "&q=1' type='video/mp4'>\n              <source src='" . $CFG->wwwroot . '/blocks/webgd_community/menus/question/showMovieQuestion.php?file=' . $post->post . "&q=1' type='video/ogg'>\n            </video></div>";
         }
         $resposta .= " <span><img src='" . $CFG->wwwroot . ImageResources::VOTAR . "' onclick=location.href='" . $CFG->wwwroot . "/blocks/webgd_community/menus/question/index.php?question={$post->post}&community={$idCommunity}'></span>\n          </div>";
         $webgdCommunity = new WebgdCommunityDao();
         $postLike = $webgdCommunity->searchPostByID($post->post);
         $resposta .= "<div class='div_like'>\n                          <img src='" . $CFG->wwwroot . ImageResources::LIKE . "' class='like' rel='1_" . $post->post . "'>\n                          <span id='likes_" . $post->post . "' class='like_dislike'>" . $postLike->total_votos_sim . "</span>\n                          <img src='" . $CFG->wwwroot . ImageResources::DISLIKE . "' class='like' rel='0_" . $post->post . "'>\n                          <span id='dislikes_" . $post->post . "' class='like_dislike'>" . $postLike->total_votos_nao . "</span>\n                        </div>";
         echo "\n                 </div>\n                 <div class='separador_lista'></div>";
     }
     if ($automatico) {
         return $resposta;
     } else {
         echo $resposta;
     }
 }
$voto = optional_param('votacao', 0, PARAM_INT);
if ($voto == 0) {
    $voto = -1;
}
$webgdCommunityDao = new WebgdCommunityDao();
$votoAnterior = 0;
if ($likedislike = $webgdCommunityDao->searchLikeDislikeUserVotation($idPost, $USER->id)) {
    $votoAnterior = $likedislike->voto;
    $DB->delete_records(TableResouces::$TABLE_PAGE_COMMUNITY_LIKEDISLIKE, array('id' => $likedislike->id));
}
$likedislike_user_votation = new stdClass();
$likedislike_user_votation->userid = $USER->id;
$likedislike_user_votation->postid = $idPost;
$likedislike_user_votation->voto = $voto;
$DB->insert_record(TableResouces::$TABLE_PAGE_COMMUNITY_LIKEDISLIKE, $likedislike_user_votation);
$post = $webgdCommunityDao->searchPostByID($idPost);
if ($votoAnterior != 0) {
    if ($votoAnterior > 0) {
        $post->total_votos_sim = $post->total_votos_sim - 1;
    } else {
        $post->total_votos_nao = $post->total_votos_nao - 1;
    }
}
if ($voto > 0) {
    $post->total_votos_sim = $post->total_votos_sim + 1;
} else {
    $post->total_votos_nao = $post->total_votos_nao + 1;
}
$DB->update_record(TableResouces::$TABLE_PAGE_COMMUNITY_POST, $post);
$nivel = $post->total_votos_sim . "_" . $post->total_votos_nao;
echo $nivel;