Index: branches/5.3.x/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r15677 -r15698 --- branches/5.3.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 15677) +++ branches/5.3.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 15698) @@ -1,6 +1,6 @@ Application->recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $parent_prefix = $event->getUnitConfig()->getParentPrefix(); + $main_object = $this->Application->recallObject($parent_prefix); /* @var $main_object kCatDBItem */ @@ -142,15 +143,17 @@ $resource_id = $this->Conn->GetOne($sql); // 2. set main item id (for permission checks) - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - $sql = 'SELECT ' . $this->Application->getUnitOption($parent_prefix, 'IDField') .' - FROM ' . $this->Application->getUnitOption($parent_prefix, 'TableName') .' + $parent_prefix = $event->getUnitConfig()->getParentPrefix(); + $parent_config = $this->Application->getUnitConfig($parent_prefix); + + $sql = 'SELECT ' . $parent_config->getIDField() .' + FROM ' . $parent_config->getTableName() .' WHERE ResourceId = ' . $resource_id; $this->Application->SetVar($parent_prefix . '_id', $this->Conn->GetOne($sql)); // 3. get main item category $sql = 'SELECT CategoryId - FROM ' . $this->Application->getUnitOption('ci', 'TableName') .' + FROM ' . $this->Application->getUnitConfig('ci')->getTableName() .' WHERE ItemResourceId = ' . $resource_id .' AND PrimaryCat = 1'; return $this->Conn->GetOne($sql); } @@ -165,7 +168,7 @@ $main_prefix = $this->Application->GetTopmostPrefix($event->Prefix, true); // this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p - return $this->Application->getUnitOption($main_prefix, 'PermItemPrefix'); + return $this->Application->getUnitConfig($main_prefix)->getPermItemPrefix(); } /** @@ -209,7 +212,7 @@ if ( preg_match('/(.*)-rev/', $event->Prefix, $regs) ) { // "Structure & Data" -> "Reviews" (section in K4) - $item_type = $this->Application->getUnitOption($regs[1], 'ItemType'); + $item_type = $this->Application->getUnitConfig($regs[1])->getItemType(); $object->addFilter('itemtype_filter', '%1$s.ItemType = ' . $item_type); if ( $this->Application->isAdmin ) { @@ -242,7 +245,8 @@ */ function getReviewStatus($event) { - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $parent_prefix = $event->getUnitConfig()->getParentPrefix(); + $main_object = $this->Application->recallObject($parent_prefix); /* @var $main_object kCatDBItem */ @@ -273,7 +277,7 @@ /* @var $object kDBItem */ $parent_info = $object->getLinkedInfo(); - $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); + $item_type = $this->Application->getUnitConfig($parent_info['ParentPrefix'])->getItemType(); $object->SetDBField('IPAddress', $this->Application->getClientIp()); $object->SetDBField('ItemType', $item_type); @@ -350,7 +354,7 @@ $parent_info = $object->getLinkedInfo(); - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + $config_mapping = $event->getUnitConfig()->getConfigMapping(); $review_settings = $config_mapping['ReviewDelayValue'] . ':' . $config_mapping['ReviewDelayInterval']; $spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings); @@ -407,14 +411,13 @@ $object = $event->getObject(); /* @var $object kDBItem */ - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - $parent_table_key = $this->Application->getUnitOption($event->Prefix, 'ParentTableKey'); - $foreign_key = $this->Application->getUnitOption($event->Prefix, 'ForeignKey'); + $config = $event->getUnitConfig(); + $parent_prefix = $config->getParentPrefix(); $main_object = $this->Application->recallObject($parent_prefix, null, Array ('skip_autoload' => true)); /* @var $main_object kDBItem */ - $main_object->Load($object->GetDBField($foreign_key), $parent_table_key); + $main_object->Load($object->GetDBField($config->getForeignKey()), $config->getParentTableKey()); } /** @@ -432,8 +435,8 @@ $object = $event->getObject(); /* @var $object kDBItem */ - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - $parent_table = $this->Application->getUnitOption($parent_prefix, 'TableName'); + $parent_prefix = $event->getUnitConfig()->getParentPrefix(); + $parent_table = $this->Application->getUnitConfig($parent_prefix)->getTableName(); if ( $object->IsTempTable() ) { $parent_table = $this->Application->GetTempName($parent_table, 'prefix:' . $object->Prefix); @@ -560,7 +563,7 @@ $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template'; $event->redirect = $this->Application->GetVar($next_template); - $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $parent_prefix = $event->getUnitConfig()->getParentPrefix(); $event->SetRedirectParam('pass', 'm,'.$parent_prefix); } } @@ -579,21 +582,24 @@ if (preg_match('/(.*)-rev/', $event->Prefix, $regs) && $this->Application->prefixRegistred($regs[1])) { // "Structure & Data" -> "Reviews" (section in K4) + $config = $event->getUnitConfig(); + $item_config = $this->Application->getUnitConfig($regs[1]); + // 1. add join to items table (for "Structure & Data" -> "Reviews" section) - $item_table = $this->Application->getUnitOption($regs[1], 'TableName'); - $ci_table = $this->Application->getUnitOption('ci', 'TableName'); + $item_table = $item_config->getTableName(); + $ci_table = $this->Application->getUnitConfig('ci')->getTableName(); - $list_sqls = $this->Application->getUnitOption($event->Prefix, 'ListSQLs'); - $list_sqls[''] .= ' LEFT JOIN '.$item_table.' item_table ON item_table.ResourceId = %1$s.ItemId'; - $list_sqls[''] .= ' LEFT JOIN '.$ci_table.' ci ON item_table.ResourceId = ci.ItemResourceId AND ci.PrimaryCat = 1'; - $this->Application->setUnitOption($event->Prefix, 'ListSQLs', $list_sqls); + $list_sql = $config->getListSQLsBySpecial(''); + $list_sql .= ' LEFT JOIN '.$item_table.' item_table ON item_table.ResourceId = %1$s.ItemId'; + $list_sql .= ' LEFT JOIN '.$ci_table.' ci ON item_table.ResourceId = ci.ItemResourceId AND ci.PrimaryCat = 1'; + $config->setListSQLsBySpecial('', $list_sql); // 2. add calculated field - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $calculated_fields['']['CatalogItemName'] = 'item_table.' . $this->getTitleField($regs[1]); - $calculated_fields['']['CatalogItemId'] = 'item_table.' . $this->Application->getUnitOption($regs[1], 'IDField'); - $calculated_fields['']['CatalogItemCategory'] = 'ci.CategoryId'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $config->addCalculatedFieldsBySpecial('', Array ( + 'CatalogItemName' => 'item_table.' . $this->getTitleField($regs[1]), + 'CatalogItemId' => 'item_table.' . $item_config->getIDField(), + 'CatalogItemCategory' => 'ci.CategoryId', + )); } } @@ -605,15 +611,18 @@ */ function getTitleField($prefix) { + $config = $this->Application->getUnitConfig($prefix); $lang_prefix = 'l'.$this->Application->GetVar('m_lang').'_'; - $title_field = $this->Application->getUnitOption($prefix, 'TitleField'); - $field_options = $this->Application->getUnitOption($prefix.'.'.$title_field, 'Fields'); + $title_field = $config->getTitleField(); + $field_options = $config->getFieldByName($title_field); $formatter_class = isset($field_options['formatter']) ? $field_options['formatter'] : ''; + if ($formatter_class == 'kMultiLanguage' && !isset($field_options['master_field'])) { $title_field = $lang_prefix.$title_field; } + return $title_field; } @@ -628,7 +637,7 @@ { parent::OnSetPerPage($event); - $parent_prefix = $event->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $parent_prefix = $event->getUnitConfig()->getParentPrefix(); $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial() . ',' . $parent_prefix); } } \ No newline at end of file