Index: branches/5.2.x/core/units/relationship/relationship_event_handler.php =================================================================== diff -u -N -r14244 -r14628 --- branches/5.2.x/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ + $table_info = $object->getLinkedInfo(); $object->SetDBField('SourceId', $table_info['ParentId']); @@ -59,73 +61,81 @@ function OnProcessSelected(&$event) { $dst_field = $this->Application->RecallVar('dst_field'); - if ($dst_field == 'TargetId') { + + if ( $dst_field == 'TargetId' ) { // prepare target_id & target_type - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); - $selected_ids = $this->Application->GetVar('selected_ids'); + $target_id = 0; $target_prefix = false; + $selected_ids = $this->Application->GetVar('selected_ids'); + foreach ($selected_ids as $selected_prefix => $target_id) { - if ($target_id > 0) { + if ( $target_id > 0 ) { $target_prefix = $selected_prefix; break; } } - if (!$target_prefix) { - $this->finalizePopup($event); + if ( !$target_prefix ) { + $event->SetRedirectParam('opener', 'u'); return; } $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption($target_prefix, 'TableName').' - WHERE '.$this->Application->getUnitOption($target_prefix, 'IDField').' IN ('.$target_id.')'; + FROM ' . $this->Application->getUnitOption($target_prefix, 'TableName') . ' + WHERE ' . $this->Application->getUnitOption($target_prefix, 'IDField') . ' IN (' . $target_id . ')'; $target_id = $this->Conn->GetOne($sql); $target_type = $this->Application->getUnitOption($target_prefix, 'ItemType'); // don't add same relation twice $table_info = $object->getLinkedInfo(); $sql = 'SELECT TargetId - FROM '.$object->TableName.' - WHERE (SourceId = '.$table_info['ParentId'].') AND (TargetId = '.$target_id.')'; + FROM ' . $object->TableName . ' + WHERE (SourceId = ' . $table_info['ParentId'] . ') AND (TargetId = ' . $target_id . ')'; $duplicate_relation = $this->Conn->GetOne($sql) == $target_id; - $this->finalizePopup($event); + $event->SetRedirectParam('opener', 'u'); - if (!$duplicate_relation) { + if ( !$duplicate_relation ) { // place correct template in opener stack $source_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - $template = $this->Application->getUnitOption($source_prefix, 'AdminTemplatePath').'/relations_edit'; + $template = $this->Application->getUnitOption($source_prefix, 'AdminTemplatePath') . '/relations_edit'; - $redirect_params = Array($event->Prefix.'_event' => 'OnNew', 'target_id' => $target_id, 'm_opener' => 's', 'target_type' => $target_type); - $this->Application->EventManager->openerStackPush($template, $redirect_params, 'all,'.$event->Prefix); + $redirect_params = Array ($event->Prefix . '_event' => 'OnNew', 'target_id' => $target_id, 'm_opener' => 's', 'target_type' => $target_type); + $this->Application->EventManager->openerStackPush($template, $redirect_params, 'all,' . $event->Prefix); } } else { - $this->finalizePopup($event); + $event->SetRedirectParam('opener', 'u'); } } /** * Set ItemName & ItemType virtual fields based on loaded item data * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { + parent::OnAfterItemLoad($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ $sql = 'SELECT Prefix - FROM '.TABLE_PREFIX.'ItemTypes - WHERE ItemType = '.$object->GetDBField('TargetType'); + FROM ' . TABLE_PREFIX . 'ItemTypes + WHERE ItemType = ' . $object->GetDBField('TargetType'); $target_prefix = $this->Conn->GetOne($sql); $title_field = $this->getTitleField($target_prefix); $title_phrase = $this->Application->getUnitOption($target_prefix, 'TitlePhrase'); - $sql = 'SELECT '.$title_field.' - FROM '.$this->Application->getUnitOption($target_prefix, 'TableName').' - WHERE ResourceId = '.$object->GetDBField('TargetId'); + $sql = 'SELECT ' . $title_field . ' + FROM ' . $this->Application->getUnitOption($target_prefix, 'TableName') . ' + WHERE ResourceId = ' . $object->GetDBField('TargetId'); $object->SetDBField('ItemName', $this->Conn->GetOne($sql)); $object->SetDBField('ItemType', $this->Application->Phrase($title_phrase));