Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1949533
affiliate_plans_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, Oct 29, 6:34 AM
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Oct 31, 6:34 AM (4 h, 53 m)
Engine
blob
Format
Raw Data
Handle
962282
Attached To
rMINC Modules.In-Commerce
affiliate_plans_event_handler.php
View Options
<?php
class
AffiliatePlansEventHandler
extends
kDBEventHandler
{
function
SetCustomQuery
(&
$event
)
{
if
(
$event
->
Special
==
'active'
)
{
$object
=&
$event
->
getObject
();
$object
->
addFilter
(
'active'
,
'%1$s.Enabled = 1'
);
}
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function
OnSetPrimary
(&
$event
)
{
$object
=&
$event
->
getObject
();
$object
->
SetDBField
(
'IsPrimary'
,
1
);
$object
->
Update
();
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function
OnBeforeItemUpdate
(&
$event
)
{
$object
=&
$event
->
getObject
();
$live_table
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'TableName'
);
$plans_count
=
$this
->
Conn
->
GetOne
(
'SELECT COUNT(*) FROM '
.
$live_table
);
if
(!
$plans_count
)
$object
->
SetDBField
(
'IsPrimary'
,
1
);
if
(
$object
->
GetDBField
(
'IsPrimary'
)
&&
$object
->
Validate
()
)
{
$sql
=
'UPDATE '
.
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'TableName'
).
'
SET IsPrimary = 0'
;
$this
->
Conn
->
Query
(
$sql
);
$status_field
=
array_shift
(
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'StatusField'
)
);
$object
->
SetDBField
(
$status_field
,
1
);
}
}
function
OnBeforeItemCreate
(&
$event
)
{
$this
->
OnBeforeItemUpdate
(
$event
);
}
function
OnMassDelete
(
$event
)
{
if
(
$this
->
Application
->
CheckPermission
(
'SYSTEM_ACCESS.READONLY'
,
1
))
{
return
;
}
$event
->
status
=
erSUCCESS
;
$ids
=
$this
->
StoreSelectedIDs
(
$event
);
$event
->
setEventParam
(
'ids'
,
$ids
);
$ids
=
$event
->
getEventParam
(
'ids'
);
$temp
=&
$this
->
Application
->
recallObject
(
$event
->
getPrefixSpecial
().
'_TempHandler'
,
'kTempTablesHandler'
);
$sql
=
'SELECT AffiliatePlanId FROM '
.
$this
->
Application
->
getUnitOption
(
'ap'
,
'TableName'
).
'
WHERE IsPrimary = 1'
;
$primary_id
=
$this
->
Conn
->
GetOne
(
$sql
);
$ids
=
array_diff
(
$ids
,
Array
(
$primary_id
));
if
(
$ids
)
{
$temp
->
DeleteItems
(
$event
->
Prefix
,
$event
->
Special
,
$ids
);
}
$this
->
clearSelectedIDs
(
$event
);
}
}
?>
Event Timeline
Log In to Comment