Index: branches/5.3.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r15677 -r15698 --- branches/5.3.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 15677) +++ branches/5.3.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 15698) @@ -1,6 +1,6 @@ Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $config = $event->getUnitConfig(); + $id_field = $config->getIDField(); + $table_name = $config->getTableName(); if ($event->Name == 'OnSave') { $table_name = $this->Application->GetTempName($table_name, 'prefix:' . $event->Prefix); @@ -360,6 +361,8 @@ $except_types = $event->getEventParam('except'); $except_types = $except_types ? explode(',', $except_types) : Array (); + $config = $event->getUnitConfig(); + if (in_array('related', $types) || in_array('related', $except_types)) { $related_to = $event->getEventParam('related_to'); if (!$related_to) { @@ -372,8 +375,8 @@ $related_prefix = $this->Conn->GetOne($sql); } - $rel_table = $this->Application->getUnitOption('rel', 'TableName'); - $item_type = (int)$this->Application->getUnitOption($event->Prefix, 'ItemType'); + $rel_table = $this->Application->getUnitConfig('rel')->getTableName(); + $item_type = (int)$config->getItemType(); if ($item_type == 0) { trigger_error('ItemType not defined for prefix ' . $event->Prefix . '', E_USER_WARNING); @@ -451,7 +454,7 @@ if (in_array('category_related', $type_clauses)) { $object->removeFilter('parent_filter'); $resource_id = $this->Conn->GetOne(' - SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' + SELECT ResourceId FROM '.$config->getTableName().' WHERE CategoryId = '.$parent_cat_id ); @@ -482,18 +485,24 @@ $object->removeFilter('parent_filter'); $product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id'); - $resource_id = $this->Conn->GetOne(' - SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').' - WHERE ProductId = '.$product_id - ); - $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'CatalogRelationships + $sql = 'SELECT ResourceId + FROM ' . $this->Application->getUnitConfig('p')->getTableName() . ' + WHERE ProductId = ' . $product_id; + $resource_id = $this->Conn->GetOne($sql); + + $sql = 'SELECT DISTINCT(TargetId) + FROM ' . TABLE_PREFIX . 'CatalogRelationships WHERE SourceId = '.$resource_id.' AND TargetType = 1'; $related_cats = $this->Conn->GetCol($sql); + $related_cats = is_array($related_cats) ? $related_cats : Array(); - $sql = 'SELECT DISTINCT(SourceId) FROM '.TABLE_PREFIX.'CatalogRelationships + + $sql = 'SELECT DISTINCT(SourceId) + FROM ' . TABLE_PREFIX . 'CatalogRelationships WHERE TargetId = '.$resource_id.' AND SourceType = 1 AND Type = 1'; $related_cats2 = $this->Conn->GetCol($sql); + $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array(); $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) ); @@ -617,10 +626,11 @@ // bug: when template contains "-" symbols (or others, that stripDisallowed will replace) it's not found if ( !array_key_exists($template, $page_by_template) ) { + $config = $event->getUnitConfig(); $template_crc = kUtil::crc32(mb_strtolower($template)); - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE ( (NamedParentPathHash = ' . $template_crc . ') OR @@ -907,12 +917,14 @@ */ function _getCategoryStatus($category_ids) { - $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $config = $this->getUnitConfig(); + $id_field = $config->getIDField(); + $table_name = $config->getTableName(); $sql = 'SELECT Status, ' . $id_field . ' FROM ' . $table_name . ' WHERE ' . $id_field . ' IN (' . implode(',', $category_ids) . ')'; + return $this->Conn->GetCol($sql, $id_field); } @@ -1194,8 +1206,9 @@ // 1. get ParentId of moved category(-es) before it gets updated!!!) $source_category_id = 0; - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $config = $event->getUnitConfig(); + $id_field = $config->getIDField(); + $table_name = $config->getTableName(); if ( $clipboard_data['cut'] ) { $sql = 'SELECT ParentId @@ -1290,12 +1303,14 @@ if($inp_clipboard[0] == 'COPY') { - $saved_cat_id = $this->Application->GetVar('m_cat_id'); + $config = $event->getUnitConfig(); $cat_ids = $event->getEventParam('cat_ids'); + $saved_cat_id = $this->Application->GetVar('m_cat_id'); - $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $ids_sql = 'SELECT '.$id_field.' FROM '.$table.' WHERE ResourceId IN (%s)'; + $ids_sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' + WHERE ResourceId IN (%s)'; + $resource_ids_sql = 'SELECT ItemResourceId FROM '.TABLE_PREFIX.'CategoryItems WHERE CategoryId = %s AND PrimaryCat = 1'; $object = $this->Application->recallObject($event->Prefix.'.item', $event->Prefix, Array('skip_autoload' => true)); @@ -1447,7 +1462,7 @@ $event->SetRedirectParam('opener', 's'); // send email events - $perm_prefix = $this->Application->getUnitOption($event->Prefix, 'PermItemPrefix'); + $perm_prefix = $event->getUnitConfig()->getPermItemPrefix(); $event_suffix = $is_active ? 'ADD' : 'ADD.PENDING'; $this->Application->emailAdmin($perm_prefix . '.' . $event_suffix); @@ -1527,8 +1542,8 @@ $ids = $this->StoreSelectedIDs($event); if ( $ids ) { - $status_field = $object->getStatusField(); $propagate_category_status = $this->Application->GetVar('propagate_category_status'); + $status_field = $event->getUnitConfig()->getStatusField(true); foreach ($ids as $id) { $object->Load($id); @@ -1644,14 +1659,13 @@ */ protected function _removeForcedSortings(kEvent $event) { - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); - /* @var $list_sortings Array */ + $config = $event->getUnitConfig(); - foreach ($list_sortings as $special => $sortings) { - unset($list_sortings[$special]['ForcedSorting']); + foreach ($config->getListSortingSpecials() as $special) { + $list_sortings = $config->getListSortingsBySpecial($special); + unset($list_sortings['ForcedSorting']); + $config->setListSortingsBySpecial('', $list_sortings); } - - $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); } /** @@ -2059,8 +2073,9 @@ static $themes = null; if (!isset($themes)) { - $id_field = $this->Application->getUnitOption('theme', 'IDField'); - $table_name = $this->Application->getUnitOption('theme', 'TableName'); + $theme_config = $this->Application->getUnitConfig('theme'); + $id_field = $theme_config->getIDField(); + $table_name = $theme_config->getTableName(); $sql = 'SELECT Name, ' . $id_field . ' FROM ' . $table_name . ' @@ -2130,26 +2145,25 @@ $root_category = $this->Application->getBaseCategory(); - // set root category - $section_adjustments = $this->Application->getUnitOption($event->Prefix, 'SectionAdjustments'); + $config = $event->getUnitConfig(); - $section_adjustments['in-portal:browse'] = Array ( + // set root category + $config->addSectionAdjustments(Array ( + 'in-portal:browse' => Array ( 'url' => Array ('m_cat_id' => $root_category), 'late_load' => Array ('m_cat_id' => $root_category), 'onclick' => 'checkCatalog(' . $root_category . ')', - ); - - $section_adjustments['in-portal:browse_site'] = Array ( + ), + 'in-portal:browse_site' => Array ( 'url' => Array ('editing_mode' => $settings['default_editing_mode']), - ); + ) + )); - $this->Application->setUnitOption($event->Prefix, 'SectionAdjustments', $section_adjustments); - // prepare structure dropdown $category_helper = $this->Application->recallObject('CategoryHelper'); /* @var $category_helper CategoryHelper */ - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); + $fields = $config->getFields(); $fields['ParentId']['default'] = (int)$this->Application->GetVar('m_cat_id'); $fields['ParentId']['options'] = $category_helper->getStructureTreeAsOptions(); @@ -2163,33 +2177,32 @@ // adds "Inherit From Parent" option to "Template" field $fields['Template']['options'] = Array (CATEGORY_TEMPLATE_INHERIT => $this->Application->Phrase('la_opt_InheritFromParent')); - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); + $config->setFields($fields); if ($this->Application->isAdmin) { // don't sort by Front-End sorting fields - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + $config_mapping = $config->getConfigMapping(); $remove_keys = Array ('DefaultSorting1Field', 'DefaultSorting2Field', 'DefaultSorting1Dir', 'DefaultSorting2Dir'); + foreach ($remove_keys as $remove_key) { unset($config_mapping[$remove_key]); } - $this->Application->setUnitOption($event->Prefix, 'ConfigMapping', $config_mapping); + + $config->setConfigMapping($config_mapping); } else { // sort by parent path on Front-End only - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); - $list_sortings['']['ForcedSorting'] = Array ("CurrentSort" => 'asc'); - $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); + $config->setListSortingsBySpecial('', Array ( + 'ForcedSorting' => Array ('CurrentSort' => 'asc'), + )); } // add grids for advanced view (with primary category column) - $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); - $process_grids = Array ('Default', 'Radio'); - foreach ($process_grids as $process_grid) { - $grid_data = $grids[$process_grid]; + foreach (Array ('Default', 'Radio') as $process_grid) { + $grid_data = $config->getGridByName($process_grid); $grid_data['Fields']['CachedNavbar'] = Array ('title' => 'la_col_Path', 'data_block' => 'grid_parent_category_td', 'filter_block' => 'grid_like_filter'); - $grids[$process_grid . 'ShowAll'] = $grid_data; + $config->addGrids($grid_data, $process_grid . 'ShowAll'); } - $this->Application->setUnitOption($this->Prefix, 'Grids', $grids); } /** @@ -2230,14 +2243,16 @@ // remove this category & it's children from dropdown $sql = 'SELECT ' . $object->IDField . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + FROM ' . $event->getUnitConfig()->getTableName() . ' WHERE ParentPath LIKE "' . $object->GetDBField('ParentPath') . '%"'; $remove_categories = $this->Conn->GetCol($sql); $options = $object->GetFieldOption('ParentId', 'options'); + foreach ($remove_categories as $remove_category) { unset($options[$remove_category]); } + $object->SetFieldOption('ParentId', 'options', $options); } @@ -2402,13 +2417,15 @@ $object = $event->getObject(); /* @var $object kDBList */ + $config = $event->getUnitConfig(); + $this->Application->SetVar($event->getPrefixSpecial().'_Page', 1); $lang = $this->Application->GetVar('m_lang'); - $items_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $items_table = $config->getTableName(); $module_name = 'In-Portal'; $sql = 'SELECT * - FROM ' . $this->Application->getUnitOption('confs', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('confs')->getTableName() . ' WHERE ModuleName = ' . $this->Conn->qstr($module_name) . ' AND SimpleSearch = 1'; $search_config = $this->Conn->Query($sql, 'FieldName'); @@ -2421,9 +2438,9 @@ $alias_counter = 0; - $custom_fields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); + $custom_fields = $config->getCustomFields(); if ($custom_fields) { - $custom_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); + $custom_table = $this->Application->getUnitConfig($event->Prefix . '-cdata')->getTableName(); $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$items_table.'.ResourceId = custom_data.ResourceId'; } @@ -2590,7 +2607,7 @@ $revelance_parts = array_unique($revelance_parts); - $conf_postfix = $this->Application->getUnitOption($event->Prefix, 'SearchConfigPostfix'); + $conf_postfix = $config->getSearchConfigPostfix(); $rel_keywords = $this->Application->ConfigValue('SearchRel_Keyword_'.$conf_postfix) / 100; $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_'.$conf_postfix) / 100; $rel_rating = $this->Application->ConfigValue('SearchRel_Rating_'.$conf_postfix) / 100; @@ -2616,17 +2633,17 @@ $select_intro = 'CREATE TABLE '.$search_table.' AS '; } - $edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0'; + $edpick_clause = $config->getFieldByName('EditorsPick') ? $items_table.'.EditorsPick' : '0'; $sql = $select_intro.' SELECT '.$relevance_clause.' AS Relevance, - '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' AS ItemId, + '.$items_table.'.'.$config->getIDField().' AS ItemId, '.$items_table.'.ResourceId, - '.$this->Application->getUnitOption($event->Prefix, 'ItemType').' AS ItemType, + '.$config->getItemType().' AS ItemType, '.$edpick_clause.' AS EdPick FROM '.$object->TableName.' '.implode(' ', $join_clauses).' WHERE '.$where_clause.' - GROUP BY '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' ORDER BY Relevance DESC'; + GROUP BY '.$items_table.'.'.$config->getIDField().' ORDER BY Relevance DESC'; $this->Conn->Query($sql); @@ -2653,7 +2670,7 @@ $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; if ( $this->Conn->Query($sql) ) { - $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); + $item_type = $event->getUnitConfig()->getItemType(); // 1. get ids to be used as search bounds $sql = 'SELECT DISTINCT ResourceId