123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * @var $post \app\models\News
- * @var \yii\data\ActiveDataProvider $newsDataProvider
- * @var \app\models\base\NewsTopic | \app\models\base\Story $topic
- * @var \app\models\Design $design
- */
- use yii\helpers\Html;
- use app\models\Inquirer;
- use yii\widgets\ListView;
- use yii\web\View;
- //if( YII_ENV != 'dev' ) return;
- $id = $design->parent_id;
- $query = Inquirer::find()->where([ 'active'=>'Y', 'id'=>$id])->limit(1)->One();
- $model = $query;
- echo "<!-- 1 опроса широкий -->";
- if(!is_null($design->parent)){
- echo Html::tag('h2',Html::a($design->parent->title,[$design->parent->getUrl()]),['class'=>"widget-title mt-2 text-center"]);
- }
- echo Html::beginTag("div",["class"=>"partner-news row"]);
- $do = $model->getPart(); //уже голосовал если сделать обход кэша можно попробовать использовать
- ?>
- <div class="col-md-12">
- <div class="inquirer-item">
- <div class="meta">
- <div class="rubric">
- <a href="/inquirer">Опрос</a>
- </div>
- <div class="title">
- <a href="/inquirer/<?=$model->id?>">
- <?=$model->text?>
- </a>
- </div>
- </div>
- <div class="answer p-3 textcols" key="<?=$model->id?>">
- <?
- $answers = $model->getAnswers();
- if( $model->show == 'N' ){
- echo $this->render('_ask_item', ['answers'=>$answers]);
- }else{
- foreach($answers as $item){
- ?>
- <div class="form-check-main">
- <input class="form-check-input-col" type="radio" id="Radio<?=$item->id?>" name="ask_<?=$model->id?>" value="<?=$item->id?>">
- <label class="form-check-label-col" for="Radio<?=$item->id?>">
- <?=$item->text?>
- </label>
- </div>
- <?
- }
- $bghtml = str_replace(["\r", "\n", "'"], "", $this->render('_ask_item', ['answers'=>$answers]));
- ?>
- <script>
- window.bghtml || (window.bghtml = []);
- window.bghtml[<?=$model->id?>] = '<?=$bghtml?>';
- </script>
- <?
- $filterurl = \yii\helpers\Url::base('https')."/inquirer/ajax";
- $this->registerJs(
- <<<JS
- function sendask(idq){
- ask = $('input:checked[name=ask_'+idq+']').val()
- $.post( "$filterurl", { 'idq': idq, 'ask': ask }, function( data ) {
- if( data.status == 'ok' ){
- //document.location.reload();
- console.log(data.status);
- $(".answer[key='"+idq+"']").html(window.bghtml[idq]);
- }
- });
- }
- JS
- ,
- View::POS_END, 'sendask'
- );
- }
- ?>
- </div>
- <button class="btn btn-primary mt-3 mx-4" onclick="sendask(<?=$model->id?>)">Голосовать</button>
- </div>
- </div>
- <?
- echo \yii\helpers\Html::endTag("div");
|