簡體   English   中英

yii中的用戶觀看次數

[英]User view count in yii

我創建了一個按鈕以生成一個顯示一些事件的彈出窗口。過去幾天,我試圖顯示訪問該事件的用戶數量。
我也嘗試了一些擴展...

  1. 計數器
  2. pcviewcounter等,

但是我需要在數據庫中存儲IP地址,事件ID和時間。
誰能幫我這個忙嗎???

查看按鈕

  <div class="modal fade" id="detailsOffeEve" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
</div> 


<script>

        function showdetails(id)
        {   // alert(id); 
        $('#detailsOffeEve').load('<?php echo Yii::app()->baseUrl; ?>/offerEvents/popup/'+id);
        }

</script>

動作彈出

 public function actionPopup($id)
{   

     //$this->render('/offerEvents/Details',array( 
    //'model'=>OfferEvents::model()->findByAttributes(array('id'=>$id)), )); 
$OfferEventsList = OfferEvents::model()->findAllByAttributes(array('id' => $id));
foreach($OfferEventsList as $Listdata)
{    $titnw=$Listdata['title'];  $details=$Listdata['description']; 
     $discountper=$Listdata['discountper'];   $discountperamt=$Listdata['discountperamt'];  
     $strdaate=$Listdata['startdate']; $enddaate=$Listdata['enddate'];   $evoftype=$Listdata['type'];   }
     $cmuserid=$Listdata['createdby'];       
     if($Listdata['createdby']==0){ $createdbyname="Admin";  }  else { $createdbyname=$Listdata->company->companyname; }
     $locationnw=$Listdata->location;   
     $offrimage=$Listdata->image;    

        if($offrimage!=""){ $imgUrls=$offrimage;  } else { $imgUrls='image-not-available.png'; }
        $infowinimgpaths='theme/images/OfferEvents/orginal/'.$imgUrls;
        if (file_exists($infowinimgpaths)) {  $infowinimgpathSrcs=Yii::app()->baseUrl.'/'.$infowinimgpaths;   } else 
        {  $infowinimgpathSrcs=Yii::app()->baseUrl.'/theme/images/OfferEvents/image-not-available.png';   }  

if (Yii::app()->user->id!='' && Yii::app()->user->id!=1){ 
$subcribeemailid=Yii::app()->user->email;  $logsts=1;
$countsubscribe = Newsfeeds::model()->countByAttributes(array('emailid' => $subcribeemailid,'cuserid' => $cmuserid)); 
} else { $subcribeemailid=''; $countsubscribe=0;  $logsts=0; }  

     $PopupdetailText='<div class="modal-dialog-1">
    <div class="modal-content">
        <div class="modal-header login_modal_header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h2 class="modal-title" id="myModalLabel">'.$titnw.' </h2>
        </div>
        <div class="container-1">
        <div class="row">

        <div class="col-sm-7 detail-text">
        <h2 class="title"> ';
        if($evoftype==0){ $PopupdetailText.='Offer Price: '.$discountperamt.'
        <font style="font-size: 15px;">[ Up To '.$discountper.'% Discount ]</font>';   }
        $PopupdetailText.='</h2><p>Details: </p>
        <p><a href="#">'.$details.'</a></p>
        <p>Location: <a href="#">'.$locationnw.'</a></p>
        <p>Expires in: <a href="#">'.$enddaate.'</a></p>';


        if($countsubscribe==0){
        $PopupdetailText.='<p>Shared by: <a href="#" style="font-weight: bold;">'.$createdbyname.'</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-success btn-xs" Onclick="subcribefeed('.$logsts.','.$cmuserid.')" >Subscribe NewsFeed</button></p>';
        } else {
        $PopupdetailText.='<p>Shared by: <a href="#" style="font-weight: bold;">'.$createdbyname.'</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-success disabled btn-xs"   >Already Subscribed NewsFeed</button></p>';
        }

        $PopupdetailText.='<div class="form-group" id="subcribefrm" style="display:none;background-color: #eee; padding: 12px; width: 82%;">
         <input type="text" id="subemailid" placeholder="Enter EmailID here" value="'.$subcribeemailid.'" style="width: 100%;" class="form-control login-field">
         <br/>
         <a href="#" Onclick="subcribefeedAdd('.$cmuserid.')" class="btn-new btn-login  btn-sm" style="  padding: 6px 18px !important;">Subscribe Feeds</a> </div> ';

      //  if($evoftype==0){ $PopupdetailText.='<p>Offer Price:<b> $'.$discountperamt.'</b></p>';  }

        $PopupdetailText.='<p>';
        $PopupdetailText .= $this->renderPartial('/comments/share', array('postid' => $id),TRUE);       
        $PopupdetailText.='<a href="#"><img src="'.Yii::app()->baseUrl.'/theme/site/images/comments.png"/>Comments</a>
        <a href="#"><img src="'.Yii::app()->baseUrl.'/theme/site/images/share.png"/>Share</a></p>
        <br/>';
                $userComment = new Comments; 

                $PopupdetailText .= $this->renderPartial('//comments/_form', array('model' => $userComment,'id'=>$id),TRUE,TRUE);
                // $PopupdetailText .= $this->renderPartial('//comments/view', array('model' => $userComment,'id'=>$id),TRUE);

                $PopupdetailText.='</div>



        <div class="col-sm-5">
        <img src="'.$infowinimgpathSrcs.'" width="100%"/>
        </div>
        </div>
        </div>

        <div class="clearfix"></div>
        <div class="modal-footer login_modal_footer">
        </div>
    </div>
</div> 
<script> 
    function subcribefeed(staus,cid)
    {   
    if(staus==0){ 
      $("#subcribefrm").toggle();  }
      else {    subcribefeedAdd(cid);     }
    }

    function subcribefeedAdd(cid)
    {    
    subusremail=$("#subemailid").val();   

var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm;
if (subusremail == "" || !re.test(subusremail))
{   alert("Invalid EmailID .");   } 
else { 
        postData ={
        "email" :subusremail,  
        "cid" :cid  
        }
        $.ajax({
        type: "POST",
        data: postData ,
        url: "'.Yii::app()->baseUrl.'/newsfeeds/create",
        success: function(msg){    
          if(msg=="Success"){ showdetails('.$id.');  alert("news feed subscribe successfully.");  }  
          else if(msg=="available"){ alert("Already subscribe News Feed for this Commercial user."); }
          else { alert("Error ."); }             
        }
        });
}

    } 
</script> '; 

    echo $PopupdetailText;  
} 

我剛剛得到答案。我不知道答案是否正確。
我在執行操作后才添加了foolwiong代碼。
**

$view =  new Viewcount;
        $viewip = Yii::app()->request->getUserHostAddress();
        $viewdate = date('Y-m-d');
        $view->ipadd = $viewip;
        $view->ofrevntid = $id;
        $view->visitdate = $viewdate;
        $viewlist = Viewcount::model()->findByAttributes(array('ipadd'=>$viewip,'ofrevntid'=>$id,'visitdate'=>$viewdate));
        $viewcount = count($viewlist);
        if ($viewcount == 0){
        $view->save();
        }

**

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM