Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1167950
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
Wed, Sep 24, 6:16 AM
Size
4 KB
Mime Type
text/x-php
Expires
Fri, Sep 26, 6:16 AM (1 d, 1 h)
Engine
blob
Format
Raw Data
Handle
756580
Attached To
rINP In-Portal
visits_event_handler.php
View Options
<?php
/**
* @version $Id: visits_event_handler.php 16513 2017-01-20 14:10:53Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
VisitsEventHandler
extends
kDBEventHandler
{
/**
* Allows to override standard permission mapping
*
* @return void
* @access protected
* @see kEventHandler::$permMapping
*/
protected
function
mapPermissions
()
{
parent
::
mapPermissions
();
$permissions
=
Array
(
'OnItemBuild'
=>
Array
(
'self'
=>
true
),
);
$this
->
permMapping
=
array_merge
(
$this
->
permMapping
,
$permissions
);
}
/**
* Registers user visit to site
*
* @param kEvent $event
*
* @return void
* @access protected
*/
protected
function
OnRegisterVisit
(
$event
)
{
if
(
$this
->
Application
->
isAdmin
||
!
$this
->
Application
->
ConfigValue
(
'UseVisitorTracking'
)
||
$this
->
Application
->
RecallVar
(
'visit_id'
)
)
{
// admin logins are not registered in visits list
return
;
}
/** @var kDBItem $object */
$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'
,
$this
->
Application
->
getClientIp
());
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
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected
function
SetCustomQuery
(
kEvent
$event
)
{
parent
::
SetCustomQuery
(
$event
);
/** @var kDBList $object */
$object
=
$event
->
getObject
();
$types
=
$event
->
getEventParam
(
'types'
);
if
(
$types
==
'myvisitors'
)
{
$user_id
=
$this
->
Application
->
RecallVar
(
'user_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
->
RecallVar
(
'user_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 being
* recalled before using it in other events that
* call prepareObject
*
* @param kDBItem|kDBList $object
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
prepareObject
(&
$object
,
kEvent
$event
)
{
$types
=
$event
->
getEventParam
(
'types'
);
if
(
method_exists
(
$object
,
'AddGroupByField'
)
)
{
if
(
(!
$types
||
$types
==
'myvisitors'
)
&&
$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'
);
}
}
}
/**
* [HOOK] Updates user_id in current visit
*
* @param kEvent $event
*/
function
OnUserLogin
(
$event
)
{
if
(
$event
->
MasterEvent
->
status
==
kEvent
::
erSUCCESS
)
{
$user_id
=
$this
->
Application
->
RecallVar
(
'user_id'
);
if
(
$user_id
>
0
)
{
// for real users only, not root,guest
$this
->
Application
->
setVisitField
(
'PortalUserId'
,
$user_id
);
}
}
}
}
Event Timeline
Log In to Comment