Index: branches/RC/core/units/general/helpers/controls/edit_picker_helper.php =================================================================== diff -u -N -r10780 -r11271 --- branches/RC/core/units/general/helpers/controls/edit_picker_helper.php (.../edit_picker_helper.php) (revision 10780) +++ branches/RC/core/units/general/helpers/controls/edit_picker_helper.php (.../edit_picker_helper.php) (revision 11271) @@ -22,6 +22,10 @@ return ; } + if ($storage_field != $event->getEventParam('link_to_field')) { + return ; + } + $object =& $event->getObject(); /* @var $object kDBList */ @@ -38,6 +42,11 @@ $filter_clause = ($event->Special == 'selected') ? 'FALSE' : 'TRUE'; } + $constrain = $this->_getConstrain($main_object, $storage_field, 'filter'); + if ($constrain) { + $filter_clause .= ' AND (' . $constrain . ')'; + } + $object->addFilter('edit_picker_filter', $filter_clause); } @@ -60,6 +69,12 @@ $sql = 'SELECT '.$sub_prefix_field.' FROM '.$this->getTable($sub_prefix, $object->IsTempTable()).' WHERE '.$foreign_key.' = '.$object->GetID(); + + $constrain = $this->_getConstrain($object, $store_field, 'load'); + if ($constrain) { + $sql .= ' AND (' . $sub_prefix_field . ' IN (' . $constrain . '))'; + } + $selected_items = array_unique($this->Conn->GetCol($sql)); $object->SetDBField($store_field, $selected_items ? '|'.implode('|', $selected_items).'|' : ''); @@ -89,6 +104,12 @@ $sql = 'SELECT ' . $sub_prefix_field . ' FROM ' . $sub_table . ' WHERE '.$foreign_key.' = '.$main_object->GetID(); + + $constrain = $this->_getConstrain($main_object, $store_field, 'save'); + if ($constrain) { + $sql .= ' AND (' . $sub_prefix_field . ' IN (' . $constrain . '))'; + } + $old_values = $this->Conn->GetCol($sql); // 2. get new values from form @@ -126,6 +147,23 @@ } } } + + function _getConstrain(&$object, $store_field, $mode = 'filter') + { + $field_options = $object->GetFieldOptions($store_field); + $constrain = array_key_exists('option_constrain', $field_options) ? $field_options['option_constrain'] : false; + + if ($mode == 'filter') { + // filter on edit form + return $constrain; + } + elseif ($constrain) { + // load or save + return sprintf($field_options['options_sql'], $field_options['option_key_field']); + } + + return false; + } } ?> \ No newline at end of file