I created a button to generate a popup which shows some events.And past few days I was trying to show the count of users which visted the events.
I tried some of the extensions too...Like
But I need to store the ip address ,eventid and time in my database.
Can anyone please help me with this???
View for button
<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>
And action popup
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">×</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>
<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>
<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;
}
I just got the answer.I dont know whether the answer is in right method.
I just added the foolwiong code after my action.
**
$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();
}
**
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.