Example #1
0
require_once dirname(__FILE__) . '/../../config.php';
require_once $CFG->dirroot . '/blocks/webgd_community/lib/class/dao/WebgdCommunityDao.php';
require_once $CFG->dirroot . '/blocks/webgd_community/commons/TableResouces.php';
require_once $CFG->dirroot . '/blocks/webgd_community/menus/Commons.php';
require_login(1);
global $USER, $DB;
$idCommunity = optional_param('community', 0, PARAM_INT);
$message = optional_param('message', '', PARAM_TEXT);
$webgbDao = new WebgdCommunityDao();
try {
    $transaction = $DB->start_delegated_transaction();
    $post = new stdClass();
    $post->community = $idCommunity;
    $post->userid = $USER->id;
    $post->time = time();
    $post->type = 'text';
    $idPost = $webgbDao->insertRecordInTableCommunityPost($post);
    $postText = new stdClass();
    $postText->post = $idPost;
    $postText->message = $message;
    $webgbDao->insertRecordInTableCommunityText($postText);
    $transaction->allow_commit();
    if ($communities = $webgbDao->getAllCommunityPost($idCommunity)) {
        foreach ($communities as $community) {
            Commons::printListPost($community);
        }
    }
} catch (Exception $e) {
    $transaction->rollback($e);
}
require_once dirname(__FILE__) . '/../../config.php';
global $USER, $CFG;
require_once $CFG->dirroot . '/blocks/webgd_community/lib/class/dao/WebgdCommunityDao.php';
require_once $CFG->dirroot . '/blocks/webgd_community/menus/Commons.php';
$ultimo_post = optional_param('ultimo_post', 0, PARAM_INT);
$id_comunidade = optional_param('id_comunidade', 0, PARAM_INT);
require_login(1);
$retorno = array('ultimo_post' => $ultimo_post, 'mensagem' => '', 'atualizar' => '0');
$novo_ultimo = $ultimo_post;
$webgbDao = new WebgdCommunityDao();
if ($communities = $webgbDao->getAllCommunityPostSince($id_comunidade, $ultimo_post)) {
    foreach ($communities as $community) {
        if ($USER->id == $community->userid) {
            $retorno['mensagem'] .= Commons::printListPost($community, 1, $id_comunidade, 1);
            //$retorno['mensagem'] .= "userid: ".$community->userid." id:".$community->id." ";
        } else {
            $retorno['mensagem'] .= Commons::printListPost($community, 0, $id_comunidade, 1);
            //$retorno['mensagem'] .= "userid: ".$community->userid." id:".$community->id." ";
        }
        if ($novo_ultimo == $ultimo_post) {
            $novo_ultimo = $community->id;
        }
    }
}
if ($novo_ultimo != $ultimo_post) {
    $retorno['atualizar'] = '1';
}
$retorno['ultimo_post'] = $novo_ultimo;
$retorno = json_encode($retorno);
echo $retorno;
Example #3
0
function homePage($webgbDao, $idCommunity, $cam)
{
    global $CFG, $USER, $OUTPUT;
    if ($cam) {
        include_once $CFG->dirroot . '/blocks/webgd_community/lib/camera/index.php';
    }
    $linkCam = $CFG->wwwroot . "/blocks/webgd_community/view.php?community={$idCommunity}&cam=1";
    echo '<div id="camera"></div>
    <form id="form" method="post" role="form" enctype="multipart/form-data" class="facebook-share-box">
        <input type="hidden" name="community" value="' . $idCommunity . '">
        <div class="arrow"></div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-file"></i> ' . get_string('atualizarStatus', 'block_webgd_community') . '
            </div>
            <div class="panel-body">
                <div class="">
                    <textarea name="message" cols="30" rows="10" id="status_message"
                              class="form-control message"
                              style="height: 62px; width: 95%; overflow: hidden;"
                              placeholder="' . get_string('escrevaSeuPost', 'block_webgd_community') . '"></textarea>
                </div>
            </div>
            <div class="panel-footer">
                <div class="row">
                    <div class="col-md-5">
                        <input type="button" name="submit" value="' . get_string('enviar', 'block_webgd_community') . '"
                              style="margin-left: 50px"
                               class="btn btn-primary" onclick="salvar()">
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div id="posts">';
    $ultimo_post = 0;
    if ($communities = $webgbDao->getAllCommunityPost($idCommunity)) {
        $images = Commons::imageById($USER->id);
        foreach ($communities as $community) {
            if ($USER->id == $community->userid) {
                Commons::printListPost($community, 1, $idCommunity);
            } else {
                Commons::printListPost($community, 0, $idCommunity);
            }
            echo '&nbsp;<span style="color:#41627F;">' . get_string('responder', 'block_webgd_community') . '</span><div class="comentarios">';
            Commons::printTimelineComments($community->id);
            echo '<form method="post" enctype="multipart/form-data" id="form-comment-' . $community->id . '" class="form-comment" onsubmit="enviaComentario(' . $community->id . '); return false;">
                    <input type="hidden" name="post_id_comment" value="' . $community->id . '">
                    <div style="line-height:25px;">';
            foreach ($images as $img) {
                echo $OUTPUT->user_picture($img, array('size' => 25, 'alttext' => false, 'link' => false));
            }
            echo '<input style="margin:4px 0 0 5px; width:75%;" type="text" name="comment" class="comment" placeholder="">
                    </div>
                    </form></div>';
            if ($ultimo_post == 0) {
                $ultimo_post = $community->id;
            }
        }
    } else {
        echo get_string('nenhumComentario', 'block_webgd_community');
    }
    echo "<input type='hidden' id='ultimo_post' value='" . $ultimo_post . "'>";
    echo "<input type='hidden' id='comunidade_id' value='" . $idCommunity . "'>";
    echo '</div>';
}