Index: branches/unlabeled/unlabeled-1.6.2/core/units/relationship/relationship_event_handler.php =================================================================== diff -u -r5573 -r5757 --- branches/unlabeled/unlabeled-1.6.2/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 5573) +++ branches/unlabeled/unlabeled-1.6.2/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 5757) @@ -1,6 +1,6 @@ permMapping = array_merge($this->permMapping, $permissions); } - + /** * Add new relation * @@ -23,19 +23,19 @@ function OnAddRelation(&$event) { $object =& $event->getObject( Array('skip_autoload' => true) ); - + $table_info = $object->getLinkedInfo(); $main_item_type = $this->Application->getUnitOption($table_info['ParentPrefix'],'ItemType'); - + $target['id'] = $this->Application->GetVar('TargetId'); $target['type'] = $this->Application->GetVar('TargetType'); - - + + $object->SetDBField($table_info['ForeignKey'], $table_info['ParentId']); $object->SetDBField('SourceType', $main_item_type); $object->SetDBField('TargetId', $target['id']); $object->SetDBField('TargetType', $target['type']); - + // 1. get item info used in relation $configs = $this->extractModulesInfo(); foreach($configs as $prefix => $config_data) @@ -45,35 +45,35 @@ break; } } - + // this forces prepareOptions of kMultiLanguge formatter to substiture title field (if multilingual) of target item // BUT this is not the solution, find out another way to get correct title field here - + $target_object =& $this->Application->recallObject($prefix, null, Array('skip_autoload' => true)); $title_field = $this->Application->getUnitOption($prefix, 'TitleField'); - + $item['name'] = $this->Conn->GetOne('SELECT '.$title_field.' FROM '.$config_data['TableName'].' WHERE ResourceId = '.$target['id']); - $item['type'] = $this->Application->Phrase($config_data['TitlePhrase']); + $item['type'] = $this->Application->Phrase($config_data['TitlePhrase']); $object->SetDBField('ItemName', $item['name']); $object->SetDBField('ItemType', $item['type']); - + $object->setID(0); - + $event->redirect = false; - + // 2. substitute opener $opener_stack = $this->Application->RecallVar('opener_stack'); $opener_stack = $opener_stack ? unserialize($opener_stack) : Array(); array_pop($opener_stack); - + $return_template = $this->Application->RecallVar('return_template'); $new_level = 'index.php|'.ltrim($this->Application->BuildEnv($return_template, Array('m_opener'=>'u'),'all'),ENV_VAR_NAME.'='); array_push($opener_stack,$new_level); $this->Application->StoreVar('opener_stack',serialize($opener_stack)); - + $this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate'); } - + /** * Creates needed sql query to load list, * if no query is defined in config for @@ -87,7 +87,7 @@ { return $this->BaseQuery($event,'ListSQLs'); } - + /** * Creates needed sql query to load item, * if no query is defined in config for @@ -99,10 +99,10 @@ */ function ItemPrepareQuery(&$event) { - return $this->BaseQuery($event,'ItemSQLs'); + return $this->BaseQuery($event,'ItemSQLs'); } - - + + /** * Get item name & type based on relation type & modules installed * @@ -113,9 +113,9 @@ { $sqls = $this->Application->getUnitOption($event->Prefix,$sql_field); $sql = isset($sqls[$event->Special]) ? $sqls[$event->Special] : $sqls['']; - + $configs = $this->extractModulesInfo(); - + // 2. build sql based on information queried $sql_templates['ItemName'] = 'IFNULL(%s.%s,\' \')'; $sql_templates['TableJoin'] = 'LEFT JOIN %1$s ON %1$s.ResourceId = rel.TargetId'; @@ -132,35 +132,35 @@ $title_field = $ml_formatter->LangFieldName($title_field); } // convert TitleField field of kMultiLanguage formatter used for it: end - + $sql_parts['ItemName'][] = sprintf($sql_templates['ItemName'], $config_data['TableName'], $title_field); $sql_parts['TableJoin'][] = sprintf($sql_templates['TableJoin'], $config_data['TableName']); - + $sql_parts['TargetName'] = sprintf( $sql_templates['TargetName'], $config_data['ItemType'], '!'.$config_data['TitlePhrase'].'!', $sql_parts['TargetName']); $sql_parts['TargetName'] = str_replace('rel','%1$s',$sql_parts['TargetName']); } - + $object =& $event->getObject(); - + $vars = Array('#ITEM_NAMES#', '#ITEM_TYPES#'); $replacements = Array( implode(', ',$sql_parts['ItemName']), $sql_parts['TargetName'] ); - + $calculated_fields =& $object->getProperty('CalculatedFields'); foreach ($calculated_fields as $field_name => $field_expression) { $calculated_fields[$field_name] = str_replace($vars, $replacements, $field_expression); } - + $object->setProperty('CalculatedFields', $calculated_fields); - + $sql = str_replace('#ITEM_JOIN#', implode(' ',$sql_parts['TableJoin']), $sql); $sql = str_replace('rel.','%1$s.',$sql); - + return $sql; } - + /** * Get configs from modules installed * @@ -176,11 +176,12 @@ $prefix = $module_data['Var']; $configs[$prefix] = $this->Application->getUnitOptions($prefix); if($configs[$prefix] === false) unset($configs[$prefix]); + if(!isset($configs[$prefix]['CatalogItem']) || !$configs[$prefix]['CatalogItem']) unset($configs[$prefix]); } return $configs; } - - + + /** * Deletes relations to hooked item from other items * @@ -190,13 +191,13 @@ { $main_object =& $event->MasterEvent->getObject(); $resource_id = $main_object->GetDBField('ResourceId'); - + $table = $this->Application->getUnitOption($event->Prefix,'TableName'); $sql = 'DELETE FROM '.$table.' WHERE TargetId = '.$resource_id; $this->Conn->Query($sql); } - - + + }