Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1050781
visits_event_handler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 3, 3:30 PM
Size
2 KB
Mime Type
text/x-php
Expires
Sat, Jul 5, 3:30 PM (1 d, 3 h)
Engine
blob
Format
Raw Data
Handle
678971
Attached To
rINP In-Portal
visits_event_handler.php
View Options
<?php
class
VisitsEventHandler
extends
InpDBEventHandler
{
/**
* Registers user visit to site
*
* @param kEvent $event
*/
function
OnRegisterVisit
(&
$event
)
{
$object
=&
$event
->
getObject
(
Array
(
'skip_autoload'
=>
true
)
);
$object
->
SetDBField
(
'VisitDate_date'
,
adodb_mktime
()
);
$object
->
SetDBField
(
'VisitDate_time'
,
adodb_mktime
()
);
$object
->
SetDBField
(
'Referer'
,
getArrayValue
(
$_SERVER
,
'HTTP_REFERER'
)
);
$object
->
SetDBField
(
'IPAddress'
,
$_SERVER
[
'REMOTE_ADDR'
]
);
if
(
$object
->
Create
()
)
{
$this
->
Application
->
StoreVar
(
'visit_id'
,
$object
->
GetID
()
);
$this
->
Application
->
SetVar
(
'visits_id'
,
$object
->
GetID
()
);
}
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @access protected
* @see OnListBuild
*/
function
SetCustomQuery
(&
$event
)
{
$object
=&
$event
->
getObject
();
$types
=
$event
->
getEventParam
(
'types'
);
if
(
$types
==
'myvisitors'
)
{
$user_id
=
$this
->
Application
->
GetVar
(
'u_id'
);
$object
->
addFilter
(
'myitems_user1'
,
'au.PortalUserId = '
.
$user_id
);
$object
->
addFilter
(
'myitems_user2'
,
'au.PortalUserId >0'
);
//$object->AddGroupByField('VisitDate');
$object
->
AddGroupByField
(
'%1$s.VisitId'
);
}
if
(
$types
==
'myvisitororders'
&&
$event
->
Special
==
'incommerce'
)
{
$user_id
=
$this
->
Application
->
GetVar
(
'u_id'
);
$object
->
addFilter
(
'myitems_orders'
,
'ord.OrderId IS NOT NULL'
);
$object
->
addFilter
(
'myitems_user1'
,
'au.PortalUserId = '
.
$user_id
);
$object
->
addFilter
(
'myitems_user2'
,
'au.PortalUserId >0'
);
$object
->
addFilter
(
'myitems_orders_processed'
,
'ord.Status = 4'
);
}
}
/**
* Apply some special processing to
* object beeing recalled before using
* it in other events that call prepareObject
*
* @param kBase $object
* @param kEvent $event
* @access protected
*/
function
prepareObject
(&
$object
,
&
$event
)
{
$types
=
$event
->
getEventParam
(
'types'
);
if
(
method_exists
(
$object
,
'AddGroupByField'
))
{
if
(
(
$types
==
'myvisitors'
||
!
$types
)
&&
$object
->
Special
==
'incommerce'
)
{
$object
->
addCalculatedField
(
'OrderTotalAmountSum'
,
'SUM(IF(ord.Status = 4, ord.SubTotal+ord.ShippingCost+ord.VAT, 0))'
);
$object
->
addCalculatedField
(
'OrderAffiliateCommissionSum'
,
'SUM( IF(ord.Status = 4,ord.AffiliateCommission,0))'
);
$object
->
addCalculatedField
(
'OrderCountByVisit'
,
'SUM( IF(ord.Status = 4, 1, 0) )'
);
}
if
(!
$types
){
$object
->
AddGroupByField
(
'%1$s.VisitId'
);
}
}
}
}
?>
Event Timeline
Log In to Comment