123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- use app\models\ReactionButtons;
- if( isset($id) && isset($type) ){
- $filterurl = \yii\helpers\Url::base('https')."/reactionbuttons/ajax";
- $getrurl = \yii\helpers\Url::base('https')."/reactionbuttons/get";
- $model = ReactionButtons::findOne(['id'=>$id, 'type'=>$type]);
- if( ( !$model instanceof ReactionButtons ) ){
- $counters=[0,0,0,0,0,0];
- }else{
- $counters =json_decode( $model->counter, true );
- }
- ?>
- <div class="btn-group reactionb">
- <?
- foreach( $counters as $key=>$val ){
- ?>
- <i><img src="/img/reactionbutton/<?=$key+1?>.svg" width="32" height="32" class="reationbutton<?=$val?' active':''?>" onclick="reaction(<?=$key?>)" id="rbki_<?=$key?>"><p id="rbk_<?=$key?>"><?=$val?></p></i>
- <?
- $key++;
- }
- ?>
- </div>
- <?
- $this->registerJs(
- <<<JS
- function reaction(vote){
- $.post( "$filterurl", { 'id': $id, 'type': '$type', 'vote':vote}, function( data ) {
- console.log(data);
- if( data.status == 'ok' ){
- if( Array.isArray(data.ret) ){
- data.ret.forEach((item, key) => {
- $('#rbk_'+key).text(item);
- if( item > 0 ) $('#rbki_'+key).addClass('active');
- });
- }
- }
- });
- }
- JS
- ,
- yii\web\View::POS_END,
- 'reaction'
- );
- $this->registerJs(
- <<<JS
- setTimeout(() => {
- $.post( "$getrurl", { 'id': $id, 'type': '$type'}, function( data ) {
- if( data.status == 'ok' ){
- if( Array.isArray(data.ret) ){
- data.ret.forEach((item, key) => {
- $('#rbk_'+key).text(item);
- if( item > 0 ) $('#rbki_'+key).addClass('active');
- });
- }
- }
- });
- }, 5000 );
- JS
- ,
- yii\web\View::POS_END,
- 'reaction2'
- );
- }
|