inquirer_wide.php 2.5 KB

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