Index: branches/5.2.x/core/units/config_search/config_search_event_handler.php =================================================================== diff -u -N -r14244 -r14628 --- branches/5.2.x/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar('module'); $main_prefix = $this->Application->findModule('Name', $module, 'Var'); $section = $this->Application->getUnitOption($main_prefix.'.search', 'PermSection'); $event->setEventParam('PermSection', $section); + return parent::CheckPermission($event); } /** * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void * @access protected - * @see OnListBuild + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); - + /* @var $object kDBList */ + // show only items that belong to selected module $module = $this->Application->GetVar('module'); $object->addFilter('module_filter', '%1$s.ModuleName = '.$this->Conn->qstr($module)); @@ -75,33 +80,46 @@ $event->SetRedirectParam('section', $this->Application->GetVar('section')); } + /** + * Cancels kDBItem Editing/Creation + * + * @param kEvent $event + * @return void + * @access protected + */ function OnCancel(&$event) { parent::OnCancel($event); + $event->SetRedirectParam('opener', 's'); } /** - * [HOOK] Enter description here... + * [HOOK] Creates search config record corresponding to custom field, that was just created * * @param kEvent $event + * @return void + * @access protected */ - function OnCreateCustomField(&$event) + protected function OnCreateCustomField(&$event) { $custom_field =& $event->MasterEvent->getObject(); - if ($custom_field->GetDBField('Type') == 6 || $custom_field->GetDBField('IsSystem') == 1) { + /* @var $custom_field kDBItem */ + + if ( $custom_field->GetDBField('Type') == 6 || $custom_field->GetDBField('IsSystem') == 1 ) { // user & system custom fields are not searchable - return false; + return ; } - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ $custom_id = $custom_field->GetID(); - if (!$object->isLoaded() || ($object->GetDBField('CustomFieldId') != $custom_id)) { + if ( !$object->isLoaded() || ($object->GetDBField('CustomFieldId') != $custom_id) ) { $object->Load($custom_id, 'CustomFieldId'); } - $cf_search = Array(); + $cf_search = Array (); $element_type = $custom_field->GetDBField('ElementType'); $cf_search['DisplayOrder'] = $custom_field->GetDBField('DisplayOrder'); @@ -114,14 +132,19 @@ $cf_search['TableName'] = 'CustomField'; $sql = 'SELECT Module - FROM '.TABLE_PREFIX.'ItemTypes - WHERE ItemType = '.$custom_field->GetDBField('Type'); + FROM ' . TABLE_PREFIX . 'ItemTypes + WHERE ItemType = ' . $custom_field->GetDBField('Type'); - $cf_search['ModuleName'] = $this->Conn->GetOne($sql); + $cf_search['ModuleName'] = $this->Conn->GetOne($sql); $object->SetFieldsFromHash($cf_search); $object->SetDBField('CustomFieldId', $custom_id); - $result = $object->isLoaded() ? $object->Update() : $object->Create(); + if ( $object->isLoaded() ) { + $object->Update(); + } + else { + $object->Create(); + } } } \ No newline at end of file