Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/country_states/country_state_eh.php
Show All 40 Lines | |||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
* @see kDBEventHandler::OnListBuild() | * @see kDBEventHandler::OnListBuild() | ||||
*/ | */ | ||||
protected function SetCustomQuery(kEvent $event) | protected function SetCustomQuery(kEvent $event) | ||||
{ | { | ||||
parent::SetCustomQuery($event); | parent::SetCustomQuery($event); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
if ( ($event->Special == 'selected') || ($event->Special == 'available') ) { | if ( ($event->Special == 'selected') || ($event->Special == 'available') ) { | ||||
/** @var EditPickerHelper $edit_picker_helper */ | |||||
$edit_picker_helper = $this->Application->recallObject('EditPickerHelper'); | $edit_picker_helper = $this->Application->recallObject('EditPickerHelper'); | ||||
/* @var $edit_picker_helper EditPickerHelper */ | |||||
$edit_picker_helper->applyFilter($event, 'Countries'); | $edit_picker_helper->applyFilter($event, 'Countries'); | ||||
// only countries | // only countries | ||||
$object->addFilter('type_filter', '%1$s.Type = ' . DESTINATION_TYPE_COUNTRY); | $object->addFilter('type_filter', '%1$s.Type = ' . DESTINATION_TYPE_COUNTRY); | ||||
} | } | ||||
} | } | ||||
Show All 27 Lines | |||||
/** | /** | ||||
* Makes sure, that state country is always specified | * Makes sure, that state country is always specified | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function _setRequired($event) | function _setRequired($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$field_options = $object->GetFieldOptions('IsoCode'); | $field_options = $object->GetFieldOptions('IsoCode'); | ||||
if ($object->GetDBField('Type') == DESTINATION_TYPE_STATE) { | if ($object->GetDBField('Type') == DESTINATION_TYPE_STATE) { | ||||
$object->setRequired('StateCountryId'); | $object->setRequired('StateCountryId'); | ||||
$field_options['unique'] = Array ('Type', 'StateCountryId'); | $field_options['unique'] = Array ('Type', 'StateCountryId'); | ||||
} | } | ||||
else { | else { | ||||
Show All 10 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemDelete(kEvent $event) | protected function OnBeforeItemDelete(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemDelete($event); | parent::OnBeforeItemDelete($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
if ( $cs_helper->CountryHasStates($object->GetDBField('IsoCode')) ) { | if ( $cs_helper->CountryHasStates($object->GetDBField('IsoCode')) ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Returns given country states in JSON format | * Returns given country states in JSON format | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnGetStatesJSON(kEvent $event) | protected function OnGetStatesJSON(kEvent $event) | ||||
{ | { | ||||
$event->status = kEvent::erSTOP; | $event->status = kEvent::erSTOP; | ||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
$states = $cs_helper->getStates( (string)$this->Application->GetVar('country_iso') ); | $states = $cs_helper->getStates( (string)$this->Application->GetVar('country_iso') ); | ||||
echo json_encode($states); | echo json_encode($states); | ||||
} | } | ||||
} | } |