Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/controls/edit_picker_helper.php
Show All 34 Lines | |||||
if ($event->Special != 'selected' && $event->Special != 'available') { | if ($event->Special != 'selected' && $event->Special != 'available') { | ||||
return ; | return ; | ||||
} | } | ||||
if ($storage_field != $event->getEventParam('link_to_field')) { | if ($storage_field != $event->getEventParam('link_to_field')) { | ||||
return ; | return ; | ||||
} | } | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
/** @var kDBItem $main_object */ | |||||
$main_object = $this->Application->recallObject($event->getEventParam('link_to_prefix')); | $main_object = $this->Application->recallObject($event->getEventParam('link_to_prefix')); | ||||
/* @var $main_object kDBItem */ | |||||
$selected_items = $main_object->GetDBField($storage_field); | $selected_items = $main_object->GetDBField($storage_field); | ||||
if ($selected_items) { | if ($selected_items) { | ||||
$filter_type = $event->Special == 'selected' ? 'IN' : 'NOT IN'; | $filter_type = $event->Special == 'selected' ? 'IN' : 'NOT IN'; | ||||
$selected_items = explode('|', substr($selected_items, 1, -1)); | $selected_items = explode('|', substr($selected_items, 1, -1)); | ||||
$filter_clause = '%1$s.' . $object->IDField.' '.$filter_type.' ('.implode(',', $selected_items).')'; | $filter_clause = '%1$s.' . $object->IDField.' '.$filter_type.' ('.implode(',', $selected_items).')'; | ||||
} | } | ||||
else { | else { | ||||
Show All 13 Lines | |||||
* Called from OnAfterItemLoad of main prefix. | * Called from OnAfterItemLoad of main prefix. | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @param string $store_field main item's field name, to store values into | * @param string $store_field main item's field name, to store values into | ||||
* @param string $source_field prefix and it's field used to store info about selected items (format: prefix.field) | * @param string $source_field prefix and it's field used to store info about selected items (format: prefix.field) | ||||
*/ | */ | ||||
function LoadValues($event, $store_field, $source_field) | function LoadValues($event, $store_field, $source_field) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
list ($sub_prefix, $sub_prefix_field) = explode('.', $source_field); | list ($sub_prefix, $sub_prefix_field) = explode('.', $source_field); | ||||
$foreign_key = $this->Application->getUnitOption($sub_prefix, 'ForeignKey'); | $foreign_key = $this->Application->getUnitOption($sub_prefix, 'ForeignKey'); | ||||
$sql = 'SELECT '.$sub_prefix_field.' | $sql = 'SELECT '.$sub_prefix_field.' | ||||
FROM '.$this->getTable($sub_prefix, $object->IsTempTable()).' | FROM '.$this->getTable($sub_prefix, $object->IsTempTable()).' | ||||
WHERE '.$foreign_key.' = '.$object->GetID(); | WHERE '.$foreign_key.' = '.$object->GetID(); | ||||
Show All 11 Lines | |||||
* Saves value to sub-item's table | * Saves value to sub-item's table | ||||
* | * | ||||
* @param kEvent $sub_event | * @param kEvent $sub_event | ||||
* @param string $store_field main item's field name, to get values from | * @param string $store_field main item's field name, to get values from | ||||
* @param string $sub_prefix_field check already existing records by this field | * @param string $sub_prefix_field check already existing records by this field | ||||
*/ | */ | ||||
function SaveValues(&$sub_event, $store_field, $sub_prefix_field) | function SaveValues(&$sub_event, $store_field, $sub_prefix_field) | ||||
{ | { | ||||
/** @var kDBItem $main_object */ | |||||
$main_object = $sub_event->MasterEvent->getObject(); | $main_object = $sub_event->MasterEvent->getObject(); | ||||
/* @var $main_object kDBItem */ | |||||
$affected_field = $main_object->GetDBField($store_field); | $affected_field = $main_object->GetDBField($store_field); | ||||
/** @var kDBItem $object */ | |||||
$object = $this->Application->recallObject($sub_event->getPrefixSpecial(), null, Array('skip_autoload' => true)); | $object = $this->Application->recallObject($sub_event->getPrefixSpecial(), null, Array('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | |||||
$sub_table = $object->TableName; | $sub_table = $object->TableName; | ||||
$foreign_key = $this->Application->getUnitOption($sub_event->Prefix, 'ForeignKey'); | $foreign_key = $this->Application->getUnitOption($sub_event->Prefix, 'ForeignKey'); | ||||
// 1. get previous values from db | // 1. get previous values from db | ||||
$sql = 'SELECT ' . $sub_prefix_field . ' | $sql = 'SELECT ' . $sub_prefix_field . ' | ||||
FROM ' . $sub_table . ' | FROM ' . $sub_table . ' | ||||
WHERE '.$foreign_key.' = '.$main_object->GetID(); | WHERE '.$foreign_key.' = '.$main_object->GetID(); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
elseif ( $constrain ) { | elseif ( $constrain ) { | ||||
// load or save | // load or save | ||||
return sprintf($field_options['options_sql'], $field_options['option_key_field']); | return sprintf($field_options['options_sql'], $field_options['option_key_field']); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |