Index: branches/RC/core/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -N -r11178 -r11685 --- branches/RC/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 11178) +++ branches/RC/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 11685) @@ -28,6 +28,7 @@ function SetCustomQuery(&$event) { $object =& $event->getObject(); + /* @var $object kDBList */ $item_type = $this->Application->GetVar('cf_type'); if (!$item_type) { @@ -40,6 +41,12 @@ } if ($item_type) { + $hidden_fields = array_map(Array(&$this->Conn, 'qstr'), $this->_getHiddenFiels($event)); + + if ($hidden_fields) { + $object->addFilter('hidden_filter', '%1$s.FieldName NOT IN (' . implode(',', $hidden_fields) . ')'); + } + $object->addFilter('itemtype_filter', '%1$s.Type = '.$item_type); } @@ -49,6 +56,51 @@ } /** + * Returns prefix, that custom fields are printed for + * + * @param kEvent $event + * @return string + */ + function _getSourcePrefix(&$event) + { + $prefix = $event->getEventParam('SourcePrefix'); + if (!$prefix) { + $sql = 'SELECT Prefix + FROM ' . TABLE_PREFIX . 'ItemTypes + WHERE ItemType = ' . $this->Application->GetVar('cf_type'); + $prefix = $this->Conn->GetOne($sql); + } + + return $prefix; + } + + /** + * Get custom fields, that should no be shown anywhere + * + * @param kEvent $event + * @return Array + */ + function _getHiddenFiels(&$event) + { + $prefix = $this->_getSourcePrefix($event); + + $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields'); + $custom_fields = $this->Application->getUnitOption($prefix, 'CustomFields'); + + $hidden_fields = Array (); + foreach ($custom_fields as $custom_field) { + $check_field = 'cust_' . $custom_field; + $show_mode = array_key_exists('show_mode', $virtual_fields[$check_field]) ? $virtual_fields[$check_field]['show_mode'] : true; + + if (($show_mode === false) || (($show_mode === smDEBUG) && !(defined('DEBUG_MODE') && DEBUG_MODE))) { + $hidden_fields[] = $custom_field; + } + } + + return $hidden_fields; + } + + /** * Prevents from duplicate item creation * * @param kEvent $event