_inquirer_item.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @var $model \app\models\News
  4. * @var $key
  5. * @var $index
  6. * @var $widget
  7. */
  8. use yii\web\View;
  9. $do = $model->getPart(); //уже голосовал если сделать обход кэша можно попробовать использовать
  10. ?>
  11. <div class="col-md-4">
  12. <div class="inquirer-item">
  13. <div class="meta">
  14. <div class="rubric">
  15. <a href="/inquirer">Опрос</a>
  16. </div>
  17. <div class="title">
  18. <a href="/inquirer/<?=$model->id?>">
  19. <?=$model->text?>
  20. </a>
  21. </div>
  22. </div>
  23. <div class="answer p-3" key="<?=$model->id?>">
  24. <?
  25. $answers = $model->getAnswers();
  26. if( $model->show == 'N' ){
  27. echo $this->render('_ask_item', ['answers'=>$answers]);
  28. }else{
  29. foreach($answers as $item){
  30. ?>
  31. <div class="form-check-main">
  32. <input class="form-check-input" type="radio" id="Radio<?=$item->id?>" name="ask_<?=$model->id?>" value="<?=$item->id?>">
  33. <label class="form-check-label" for="Radio<?=$item->id?>">
  34. <?=$item->text?>
  35. </label>
  36. </div>
  37. <?
  38. }
  39. ?>
  40. <button class="btn btn-primary mt-4" onclick="sendask(<?=$model->id?>)">Голосовать</button>
  41. <?
  42. $bghtml = str_replace(["\r", "\n", "'"], "", $this->render('_ask_item', ['answers'=>$answers]));
  43. ?>
  44. <script>
  45. window.bghtml || (window.bghtml = []);
  46. window.bghtml[<?=$model->id?>] = '<?=$bghtml?>';
  47. </script>
  48. <?
  49. $filterurl = \yii\helpers\Url::base('https')."/inquirer/ajax";
  50. $this->registerJs(
  51. <<<JS
  52. function sendask(idq){
  53. ask = $('input:checked[name=ask_'+idq+']').val()
  54. $.post( "$filterurl", { 'idq': idq, 'ask': ask }, function( data ) {
  55. if( data.status == 'ok' ){
  56. //document.location.reload();
  57. console.log(data.status);
  58. $(".answer[key='"+idq+"']").html(window.bghtml[idq]);
  59. }
  60. });
  61. }
  62. JS
  63. ,
  64. View::POS_END, 'sendask'
  65. );
  66. }
  67. ?>
  68. </div>
  69. </div>
  70. </div>