Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1949890
zones_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, 8:42 AM
Size
6 KB
Mime Type
text/x-php
Expires
Sat, Oct 31, 8:42 AM (16 h, 46 m)
Engine
blob
Format
Raw Data
Handle
962291
Attached To
rMINC Modules.In-Commerce
zones_event_handler.php
View Options
<?php
class
ZonesEventHandler
extends
kDBEventHandler
{
/**
* Allows to override standart permission mapping
*
*/
function
mapPermissions
()
{
parent
::
mapPermissions
();
$permissions
=
Array
(
'OnTypeChange'
=>
Array
(
'subitem'
=>
'add|edit'
),
'OnCountryChange'
=>
Array
(
'subitem'
=>
'add|edit'
),
'OnLoadZoneForm'
=>
Array
(
'subitem'
=>
'add|edit'
),
);
$this
->
permMapping
=
array_merge
(
$this
->
permMapping
,
$permissions
);
}
function
mapEvents
()
{
parent
::
mapEvents
();
// ensure auto-adding of approve/decine and so on events
$zones_events
=
Array
(
'OnAddLocation'
=>
'DestinationAction'
,
'OnRemoveLocation'
=>
'DestinationAction'
,
'OnLoadZoneForm'
=>
'DestinationAction'
,
/*'OnCountryChange' => 'DestinationAction',*/
);
$this
->
eventMethods
=
array_merge
(
$this
->
eventMethods
,
$zones_events
);
}
function
customProcessing
(&
$event
,
$type
)
{
$zone_object
=&
$event
->
GetObject
();
switch
(
$type
)
{
case
'before'
:
if
(
$event
->
Name
==
'OnCreate'
)
{
$zone_object
->
SetDBField
(
'ShippingTypeID'
,
$this
->
Application
->
GetVar
(
's_id'
));
}
break
;
case
'after'
:
$items_info
=
$this
->
Application
->
GetVar
(
$event
->
getPrefixSpecial
(
true
)
);
$dst_object
=&
$this
->
Application
->
RecallObject
(
'dst'
);
if
(
$event
->
Name
==
'OnUpdate'
)
{
$sql
=
'DELETE FROM '
.
$dst_object
->
TableName
.
' WHERE ShippingZoneId='
.
$zone_object
->
GetID
();
$this
->
Conn
->
Query
(
$sql
);
}
else
{
$temp
=
$this
->
Application
->
GetVar
(
'dst'
);
foreach
(
$temp
as
$key
=>
$value
)
{
$temp
[
$key
][
'ShippingZoneId'
]
=
$zone_object
->
GetID
();
}
$this
->
Application
->
SetVar
(
'dst'
,
$temp
);
}
$dst_event
=
new
kEvent
();
$dst_event
->
Init
(
'dst'
);
$dst_event
->
Name
=
'OnCreate'
;
$this
->
Application
->
HandleEvent
(
$dst_event
);
break
;
default
:
}
}
/* function OnItemBuild(&$event)
{
parent::OnItemBuild($event);
$object = $event->GetObject();
$object->SetDBField('ZoneID', $this->Application->GetVar('zone_id') );
$object->ID = $this->Application->GetVar('zone_id');
}*/
/**
* Enter description here...
*
* @param kEvent $event
*/
function
OnTypeChange
(&
$event
)
{
$this
->
Application
->
DeleteVar
(
'dst'
);
$event
->
CallSubEvent
(
$this
->
Application
->
GetVar
(
'z_OriginalSaveEvent'
));
$event
->
redirect
=
false
;
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function
DestinationAction
(&
$event
)
{
$event
->
redirect
=
false
;
$items_info
=
$this
->
Application
->
GetVar
(
$event
->
getPrefixSpecial
(
true
)
);
if
(
$items_info
)
{
foreach
(
$items_info
as
$item_id
=>
$field_values
)
{
// this is to receive $item_id
}
}
$object
=&
$event
->
getObject
(
Array
(
'skip_autoload'
=>
true
)
);
$object
->
Load
(
$item_id
);
$object
->
SetFieldsFromHash
(
$field_values
);
$object
->
SetDBField
(
'ZoneID'
,
$item_id
);
$destination
=&
$this
->
Application
->
recallObject
(
'dst'
);
switch
(
$event
->
Name
)
{
case
'OnAddLocation'
:
$new_id
=
(
int
)
$this
->
Conn
->
GetOne
(
'SELECT MIN('
.
$destination
->
IDField
.
') FROM '
.
$destination
->
TableName
);
if
(
$new_id
>
0
)
$new_id
=
0
;
do
{
$new_id
--;
}
while
(
$this
->
check_array
(
$this
->
Application
->
GetVar
(
'dst'
),
'ZoneDestId'
,
$new_id
));
switch
(
$object
->
GetDBField
(
'Type'
))
{
case
1
:
$location_id
=
$this
->
Application
->
GetVar
(
'country'
);
break
;
case
2
:
$location_id
=
$this
->
Application
->
GetVar
(
'state'
);
break
;
default
:
$location_id
=
''
;
}
$temp
=
$this
->
Application
->
GetVar
(
'dst'
);
$zip
=
$this
->
Application
->
GetVar
(
'zip_input'
)
?
$this
->
Application
->
GetVar
(
'zip_input'
)
:
$this
->
Application
->
GetVar
(
'zip_dropdown'
);
if
(
(
$location_id
&&
!
$this
->
check_array
(
$temp
,
'StdDestId'
,
$location_id
))
||
(
$zip
&&
!
$this
->
check_array
(
$temp
,
'DestValue'
,
$zip
))
)
{
$temp
[
$new_id
][
'ZoneDestId'
]
=
$new_id
;
$temp
[
$new_id
][
'StdDestId'
]
=
$location_id
;
$temp
[
$new_id
][
'DestValue'
]
=
$zip
?
$zip
:
''
;
$this
->
Application
->
SetVar
(
'dst'
,
$temp
);
}
break
;
case
'OnRemoveLocation'
:
$temp
=
$this
->
Application
->
GetVar
(
'dst'
);
$selected_destinations
=
explode
(
','
,
$this
->
Application
->
GetVar
(
'selected_destinations'
));
foreach
(
$selected_destinations
as
$dest
)
{
unset
(
$temp
[
$dest
]
);
}
$this
->
Application
->
SetVar
(
'dst'
,
$temp
);
break
;
case
'OnLoadZoneForm'
:
$sql
=
'SELECT * FROM '
.
$destination
->
TableName
.
' WHERE ShippingZoneId='
.
$item_id
;
$res
=
$this
->
Conn
->
Query
(
$sql
);
$temp
=
Array
();
foreach
(
$res
as
$dest_record
)
{
$temp
[
$dest_record
[
'ZoneDestId'
]][
'ZoneDestId'
]
=
$dest_record
[
'ZoneDestId'
];
$temp
[
$dest_record
[
'ZoneDestId'
]][
'StdDestId'
]
=
$dest_record
[
'StdDestId'
];
$temp
[
$dest_record
[
'ZoneDestId'
]][
'DestValue'
]
=
$dest_record
[
'DestValue'
];
}
$this
->
Application
->
SetVar
(
'dst'
,
$temp
);
$object
=&
$event
->
getObject
();
$object
->
SetDBField
(
'ShippingTypeID'
,
$this
->
Application
->
GetVar
(
's_id'
));
$this
->
Application
->
StoreVar
(
'zone_mode'
.
$this
->
Application
->
GetVar
(
'm_wid'
),
'edit'
);
break
;
/*case 'OnNew':
$object =& $event->getObject();
$object->SetDBField('ShippingTypeID', $this->Application->GetVar('s_id'));
break;*/
case
'OnCountryChange'
:
$this
->
Application
->
DeleteVar
(
'dst'
);
break
;
default
:
}
// if($this->Application->GetVar('z_OriginalSaveEvent'))
// {
// $this->Application->SetVar($event->Prefix_Special.'_SaveEvent', $this->Application->GetVar('z_OriginalSaveEvent'));
// }
}
function
OnMassDelete
(&
$event
)
{
$ids
=
$this
->
StoreSelectedIDs
(
$event
);
$event
->
setEventParam
(
'ids'
,
$ids
);
$this
->
customProcessing
(
$event
,
'before'
);
$ids
=
$event
->
getEventParam
(
'ids'
);
$ids
=
implode
(
','
,
$ids
);
$dst
=&
$this
->
Application
->
recallObject
(
'dst'
);
$sql
=
'DELETE FROM '
.
$dst
->
TableName
.
' WHERE ShippingZoneId IN ('
.
$ids
.
')'
;
$this
->
Conn
->
Query
(
$sql
);
parent
::
OnMassDelete
(
$event
);
}
function
OnCountryChange
(&
$event
)
{
$destinations
=
&
$this
->
Application
->
recallObject
(
'dst'
);
$queryDel
=
"DELETE FROM "
.
$destinations
->
TableName
.
" WHERE ShippingZoneId="
.
$this
->
Application
->
GetVar
(
$event
->
Prefix
.
'_id'
);
$this
->
Conn
->
Query
(
$queryDel
);
$this
->
Application
->
DeleteVar
(
'dst'
);
$event
->
CallSubEvent
(
$this
->
Application
->
GetVar
(
'z_OriginalSaveEvent'
));
$event
->
redirect
=
false
;
}
function
OnCancel
(&
$event
){
parent
::
OnCancel
(
$event
);
$dst_object
=
&
$this
->
Application
->
recallObject
(
'dst'
);
$delete_zones_sql
=
'DELETE FROM '
.
$dst_object
->
TableName
.
' WHERE ShippingZoneId = 0'
;
$this
->
Conn
->
Query
(
$delete_zones_sql
);
// if cancelling after create
if
(
$this
->
Application
->
RecallVar
(
'zone_mode'
.
$this
->
Application
->
GetVar
(
'm_wid'
))
==
'create'
)
{
$zone
=&
$event
->
getObject
();
$zone
->
Delete
();
}
}
function
OnNew
(&
$event
)
{
parent
::
OnNew
(
$event
);
$this
->
Application
->
StoreVar
(
'zone_mode'
.
$this
->
Application
->
GetVar
(
'm_wid'
),
'create'
);
}
}
?>
Event Timeline
Log In to Comment