Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1161427
affiliate_payments_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
Sat, Sep 20, 6:22 AM
Size
3 KB
Mime Type
text/x-php
Expires
Mon, Sep 22, 6:22 AM (6 h, 22 m)
Engine
blob
Format
Raw Data
Handle
751299
Attached To
rMINC Modules.In-Commerce
affiliate_payments_event_handler.php
View Options
<?php
/**
* @version $Id: affiliate_payments_event_handler.php 14625 2011-10-04 09:34:12Z alex $
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
AffiliatePaymentsEventHandler
extends
kDBEventHandler
{
/**
* 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
,
&
$event
)
{
if
(
$event
->
Special
==
'log'
)
{
return
;
}
$parent_info
=
$object
->
getLinkedInfo
();
$parent_object
=&
$this
->
Application
->
recallObject
(
$parent_info
[
'ParentPrefix'
]);
/* @var $parent_object kDBItem */
$options
=
$object
->
getFieldOptions
(
'PaymentTypeId'
);
if
(
$parent_object
->
isLoaded
()
)
{
$options
[
'default'
]
=
$parent_object
->
GetDBField
(
'PaymentTypeId'
);
$object
->
SetDBField
(
'PaymentTypeId'
,
$parent_object
->
GetDBField
(
'PaymentTypeId'
));
}
if
(
$this
->
Application
->
GetVar
(
$event
->
getPrefixSpecial
()
.
'_event'
)
!=
'OnNew'
&&
$this
->
Application
->
GetVar
(
$event
->
getPrefixSpecial
()
.
'_event'
)
!=
'OnCreate'
)
{
$options
[
'options'
][
0
]
=
''
;
}
$object
->
setFieldOptions
(
'PaymentTypeId'
,
$options
);
}
/**
* Set's fields based on affiliate currently beeing edited
*
* @param kEvent $event
*/
function
OnNew
(&
$event
)
{
parent
::
OnNew
(
$event
);
$affiliate
=&
$this
->
Application
->
recallObject
(
'affil'
);
$object
=&
$event
->
getObject
(
Array
(
'skip_autoload'
=>
true
)
);
$object
->
SetDBField
(
'Amount'
,
$affiliate
->
GetDBField
(
'AmountToPay'
)
);
$object
->
SetDBField
(
'AffiliateId'
,
$affiliate
->
GetID
()
);
}
/**
* Updates Affiliate Record On Successfully payment creation
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnAfterItemCreate
(&
$event
)
{
parent
::
OnAfterItemCreate
(
$event
);
$object
=&
$event
->
getObject
();
/* @var $object kDBItem */
$parent_info
=
$object
->
getLinkedInfo
();
$sql
=
'SELECT MAX(PaymentDate)
FROM '
.
$object
->
TableName
.
'
WHERE '
.
$parent_info
[
'ParentTableKey'
]
.
' = '
.
$parent_info
[
'ParentId'
];
$payment_date
=
$this
->
Conn
->
GetOne
(
$sql
);
$affiliate
=&
$this
->
Application
->
recallObject
(
'affil'
);
/* @var $affiliate kDBItem */
$affiliate
->
SetDBField
(
'AmountToPay'
,
$affiliate
->
GetDBField
(
'AmountToPay'
)
-
$object
->
GetDBField
(
'Amount'
));
$affiliate
->
SetDBField
(
'LastPaymentDate_date'
,
$payment_date
);
$affiliate
->
SetDBField
(
'LastPaymentDate_time'
,
$payment_date
);
$affiliate
->
Update
();
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected
function
SetCustomQuery
(&
$event
)
{
$object
=&
$event
->
getObject
();
if
(
$event
->
Special
==
'log'
)
{
$object
->
removeFilter
(
'parent_filter'
);
}
$types
=
$event
->
getEventParam
(
'types'
);
if
(
$types
==
'my_payments'
)
{
$user_id
=
$this
->
Application
->
RecallVar
(
'user_id'
);
$object
->
removeFilter
(
'parent_filter'
);
$object
->
addFilter
(
'my_payments'
,
'au.PortalUserId = '
.
$user_id
);
}
if
(
$types
==
'myvisitororders'
)
{
$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'
);
}
}
}
Event Timeline
Log In to Comment