public function actionPools()
    {
        $pool = Pools::model()->with('answers')->findByPk($_POST['poolId']);
        if(!PoolsIp::model()->count('ip = :ip AND pool_id = :id', array(':ip'=>$_SERVER['REMOTE_ADDR'], ':id'=>$pool->id)))
        {
            if(isset($_POST['value']))
            {
                $pool->hits++;
                $poolsIp = new PoolsIp();
                $poolsIp->answer_id = $_POST['value'];
                $poolsIp->pool_id = $pool->id;
                $poolsIp->ip = $_SERVER['REMOTE_ADDR'];

                $answer = Answers::model()->findByPk($_POST['value']);
                $answer->hits++;

                $answer->save();
                $poolsIp->save();
                $pool->save();

                $refreshedPools = Pools::model()->with('answers')->findByPk($_POST['poolId']);

                $this->renderPartial('pool', array('pool'=>$refreshedPools), false, false);
            }
        }
    }
Beispiel #2
0
<?php
/* @var $model Pools */
?>
<?php foreach($model as $pool): ?>
    <h4><?= $pool->name; ?></h4>
    <div class="pools-res">
        <?php if(!PoolsIp::model()->count('ip = :ip AND pool_id = :id', array(':ip'=>$_SERVER['REMOTE_ADDR'], ':id'=>$pool->id))): ?>
            <form method="POST" id="formx" action="javascript:void(null);" onsubmit="call()">
                <?php foreach($pool->answers as $answer): ?>

                    <div class="radio">
                        <label>
                            <?= CHtml::ajaxLink('<input name="" type="radio">'.$answer->name,
                                array('/ajax/pools'),
                                array(
                                    'type' => 'POST',// method
                                    'data'=>array('update'=>TRUE, 'YII_CSRF_TOKEN' => Yii::app()->request->csrfToken, 'value'=>$answer->id, 'poolId'=>$pool->id),// DATA
                                    'update' => '.pools-res',
                                    'complete' => 'function(){
                                        $(".line").each(
                                            function()
                                            {
                                                var percentage = $(this).data("wid");
                                                $(this).css({width: percentage}).animate({width: percentage}, "slow");
                                            });
                                    }',

                                    'success'=> 'function(html){
                                        jQuery(".pools-res").html(html);
                                    }
                                    ')