Index: branches/5.3.x/units/listings/listings_tag_processor.php =================================================================== diff -u -N -r15486 -r15696 --- branches/5.3.x/units/listings/listings_tag_processor.php (.../listings_tag_processor.php) (revision 15486) +++ branches/5.3.x/units/listings/listings_tag_processor.php (.../listings_tag_processor.php) (revision 15696) @@ -1,6 +1,6 @@ getObject($params); /* @var $object kDBItem */ - $sql = 'SELECT '.$this->Application->getUnitOption('l', 'IDField').' - FROM '.$this->Application->getUnitOption('l', 'TableName').' + $links_config = $this->Application->getUnitConfig('l'); + + $sql = 'SELECT '.$links_config->getIDField().' + FROM '.$links_config->getTableName().' WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); return $this->Application->HREF($params['edit_template'],'', Array( Index: branches/5.3.x/units/l-visits/l-visit_eh.php =================================================================== diff -u -N -r15486 -r15696 --- branches/5.3.x/units/l-visits/l-visit_eh.php (.../l-visit_eh.php) (revision 15486) +++ branches/5.3.x/units/l-visits/l-visit_eh.php (.../l-visit_eh.php) (revision 15696) @@ -1,6 +1,6 @@ MasterEvent->Prefix == 'u' ? 'PortalUserId' : 'ResourceId'; - $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); + $table_name = $this->getUnitConfig()->getTableName(); $object = $event->MasterEvent->getObject(); + /* @var $object kDBItem */ - $sql = 'DELETE FROM '.$table_name.' - WHERE '.$key_field.' = '.$object->GetDBField($key_field); + $sql = 'DELETE FROM ' . $table_name . ' + WHERE ' . $key_field . ' = ' . $object->GetDBField($key_field); $this->Conn->Query($sql); } } \ No newline at end of file Index: branches/5.3.x/units/link_validation/link_validation_eh.php =================================================================== diff -u -N -r15672 -r15696 --- branches/5.3.x/units/link_validation/link_validation_eh.php (.../link_validation_eh.php) (revision 15672) +++ branches/5.3.x/units/link_validation/link_validation_eh.php (.../link_validation_eh.php) (revision 15696) @@ -1,6 +1,6 @@ getUnitConfig(); + // 1. delete previous validation results - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName'); + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName(); $ids = $this->Conn->GetCol($sql); - if ($ids) { - $temp_handler = $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + if ( $ids ) { + $temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); /* @var $temp_handler kTempTablesHandler */ $temp_handler->DeleteItems($event->Prefix, $event->Special, $ids); @@ -270,18 +272,21 @@ function _getRecycleBinCategories() { $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); - if (!is_numeric($recycle_bin)) { + + if ( !is_numeric($recycle_bin) ) { return Array (); } $recycle_categories = $this->Application->RecallVar('recycle_categories'); - if ($recycle_categories === false) { + + if ( $recycle_categories === false ) { + $categories_config = $this->Application->getUnitConfig('c'); $tree_indexes = $this->Application->getTreeIndex($recycle_bin); - $sql = 'SELECT ' . $this->Application->getUnitOption('c', 'IDField') . ' - FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' + $sql = 'SELECT ' . $categories_config->getIDField() . ' + FROM ' . $categories_config->getTableName() . ' WHERE TreeLeft BETWEEN ' . $tree_indexes['TreeLeft'] . ' AND ' . $tree_indexes['TreeRight']; - $recycle_categories = serialize( $this->Conn->GetCol($sql) ); + $recycle_categories = serialize($this->Conn->GetCol($sql)); // store recycle bin categories in session to prevent query below happening on each link validation step $this->Application->StoreVar('recycle_categories', $recycle_categories); @@ -301,40 +306,42 @@ { static $recycle_bin = null; - if (!isset($recycle_bin)) { + if ( !isset($recycle_bin) ) { $recycle_bin = $this->_getRecycleBinCategories(); } - if (!$recycle_bin) { + if ( !$recycle_bin ) { // Recycle Bin not used in system -> link is 100% not there return false; } $sql = 'SELECT CategoryId - FROM ' . $this->Application->getUnitOption('l-ci', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('l-ci')->getTableName() . ' WHERE ItemResourceId = ' . $resource_id . ' AND PrimaryCat = 1'; - return in_array( $this->Conn->GetOne($sql), $recycle_bin); + return in_array($this->Conn->GetOne($sql), $recycle_bin); } function _validateLink($link_id) { $curl_helper = $this->Application->recallObject('CurlHelper'); /* @var $curl_helper kCurlHelper */ + $link_config = $this->Application->getUnitConfig('l'); + $sql = 'SELECT Url, ResourceId - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' - WHERE ' . $this->Application->getUnitOption('l', 'IDField') . ' = ' . $link_id; + FROM ' . $link_config->getTableName() . ' + WHERE ' . $link_config->getIDField() . ' = ' . $link_id; $link_data = $this->Conn->GetRow($sql); - if (!preg_match('/^(http|https):\/\/(.*)/U', $link_data['Url']) || $this->_inRecycleBin($link_data['ResourceId'])) { - return ; + if ( !preg_match('/^(http|https):\/\/(.*)/U', $link_data['Url']) || $this->_inRecycleBin($link_data['ResourceId']) ) { + return; } $curl_helper->timeout = LINK_VALIDATION_TIMEOUT; $result = $curl_helper->Send($link_data['Url']); - if ($result === false || $curl_helper->lastErrorMsg != '') { + if ( $result === false || $curl_helper->lastErrorMsg != '' ) { $curl_helper->lastErrorCode = 500; } @@ -352,6 +359,7 @@ 'ValidationCode' => $curl_helper->lastHTTPCode, 'ValidationStatus' => $curl_helper->lastHTTPCode < 400 ? LINK_VALIDATION_VALID : LINK_VALIDATION_INVALID, ); + $link_validation->SetDBFieldsFromHash($fields_hash); return $link_validation->isLoaded() ? $link_validation->Update() : $link_validation->Create(); @@ -394,10 +402,11 @@ */ function _getSelectedIds($event, $transform = false) { - $ids = Array(); + $ids = Array (); - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if ($items_info) { + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + + if ( $items_info ) { foreach ($items_info as $id => $field_values) { if ( getArrayValue($field_values, 'ForeignLinkId') ) { // we are not gathering ids by unit idfield here! @@ -406,9 +415,11 @@ } } - if ($transform && $ids) { - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + if ( $transform && $ids ) { + $config = $event->getUnitConfig(); + + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE LinkId IN (' . implode(',', $ids) . ')'; $ids = $this->Conn->GetCol($sql); } @@ -491,14 +502,14 @@ function OnPrepareLinkEditing($event) { // hook to OnAfterConfigRead instead of OnEdit, because fake ids should be available in CheckPermission - if ($this->Application->GetVar('l_event') != 'OnEdit') { - return ; + if ( $this->Application->GetVar('l_event') != 'OnEdit' ) { + return; } + $items_info = Array (); $ids = $this->_getSelectedIds($event); - $id_field = $this->Application->getUnitOption('l', 'IDField'); + $id_field = $this->Application->getUnitConfig('l')->getIDField(); - $items_info = Array (); foreach ($ids as $id) { $items_info[$id][$id_field] = 'on'; } @@ -516,19 +527,22 @@ function _prepareValidation($event) { // 2. get ids of all links and put them into validation queue - $id_field = $this->Application->getUnitOption('l', 'IDField'); - $sql = 'SELECT ' . $id_field . ' - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' - WHERE LinkId NOT IN (SELECT LinkId FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ')'; + $links_config = $this->Application->getUnitConfig('l'); + + $sql = 'SELECT ' . $links_config->getIDField() . ' + FROM ' . $links_config->getTableName() . ' + WHERE LinkId NOT IN (SELECT LinkId FROM ' . $event->getUnitConfig()->getTableName() . ')'; $link_ids = $this->Conn->GetCol($sql); - if ($link_ids) { + if ( $link_ids ) { $validation_data = Array ( 'processed' => 0, 'total' => count($link_ids), 'items' => $link_ids, ); + $this->Application->StoreVar($event->Prefix . '_status', serialize($validation_data)); // 4K links will be 78KB serialized + return true; } @@ -563,9 +577,9 @@ { parent::OnAfterConfigRead($event); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $calculated_fields['']['LinkName'] = 'l.l' . $this->Application->GetVar('m_lang') . '_Name'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'LinkName' => 'l.l' . $this->Application->GetVar('m_lang') . '_Name', + )); } } \ No newline at end of file Index: branches/5.3.x/units/listings/listings_event_handler.php =================================================================== diff -u -N -r15672 -r15696 --- branches/5.3.x/units/listings/listings_event_handler.php (.../listings_event_handler.php) (revision 15672) +++ branches/5.3.x/units/listings/listings_event_handler.php (.../listings_event_handler.php) (revision 15696) @@ -1,6 +1,6 @@ getObject(); + $object =& $event->getObject(); + /* @var $object kDBItem */ $selected_ids = $this->Application->GetVar('selected_ids'); - if ($selected_ids['l']) { + + if ( $selected_ids['l'] ) { $link_id = $selected_ids['l']; + $config = $this->Application->getUnitConfig('l'); + $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption('l', 'TableName').' - WHERE '.$this->Application->getUnitOption('l', 'IDField').' = '.$link_id; + FROM ' . $config->getTableName() . ' + WHERE ' . $config->getIDField() . ' = ' . $link_id; $object->SetDBField($this->Application->RecallVar('dst_field'), $this->Conn->GetOne($sql)); $object->IgnoreValidation = true; - // $this->RemoveRequiredFields($object); +// $this->RemoveRequiredFields($object); $object->Update(); } @@ -126,7 +130,7 @@ /* @var $object kDBItem */ $sql = 'SELECT * - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + FROM ' . $event->getUnitConfig()->getTableName() . ' WHERE ListingId = ' . $object->GetId(); $original_values = $this->Conn->GetRow($sql); @@ -137,7 +141,7 @@ if ( $status_modified ) { $email_event = $object->GetDBField('Status') ? 'LINK.ENHANCE.APPROVE' : 'LINK.ENHANCE.DENY'; $sql = 'SELECT CreatedById - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + FROM ' . $this->Application->getUnitConfig('l')->getTableName() . ' WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); $user_id = $this->Conn->GetOne($sql); @@ -158,59 +162,74 @@ } } + /** + * Enhances link + * + * @param kDBItem $object + * @param Array $original_values + * @return bool + */ function EnhanceLink(&$object, $original_values) { - if ($object->GetDBField('Status') != STATUS_ACTIVE) { + if ( $object->GetDBField('Status') != STATUS_ACTIVE ) { return false; } - if ($object->GetDBField('ExpiresOn') < adodb_mktime()) { + if ( $object->GetDBField('ExpiresOn') < adodb_mktime() ) { $object->SetDBField('Status', STATUS_PENDING); $object->Update(); $this->ResetLink($original_values); + return false; } $this->UpdateLink('OnPurchase', $object->GetDBField('ItemResourceId'), $object->GetDBField('ListingTypeId')); - $listtype_object = $this->Application->recallObject('lst'); - if ( $listtype_object->GetDBField('OnPurchaseAddToCatEnabled') ) - { + $listing_type_object = $this->Application->recallObject('lst'); + /* @var $listing_type_object kDBItem */ + + if ( $listing_type_object->GetDBField('OnPurchaseAddToCatEnabled') ) { $link_object = $this->Application->recallObject('l'); - $add_to_cat = (int)$listtype_object->GetDBField('OnPurchaseAddToCat'); - $sql = 'DELETE FROM '.$this->Application->getUnitOption('l-ci', 'TableName').' - WHERE CategoryId = '.$add_to_cat.' - AND ItemResourceId = '.$link_object->GetDBField('ResourceId').' + /* @var $link_object kDBItem */ + + $add_to_cat = (int)$listing_type_object->GetDBField('OnPurchaseAddToCat'); + + $category_item_config = $this->Application->getUnitConfig('l-ci'); + + $sql = 'DELETE FROM ' . $category_item_config->getTableName() . ' + WHERE CategoryId = ' . $add_to_cat . ' + AND ItemResourceId = ' . $link_object->GetDBField('ResourceId') . ' AND PrimaryCat = 0'; $this->Conn->Query($sql); - $sql = 'INSERT INTO '.$this->Application->getUnitOption('l-ci', 'TableName').' + + $sql = 'INSERT INTO ' . $category_item_config->getTableName() . ' (CategoryId, ItemResourceId, PrimaryCat) - VALUES ('.$add_to_cat.', '.$link_object->GetDBField('ResourceId').', 0)'; + VALUES (' . $add_to_cat . ', ' . $link_object->GetDBField('ResourceId') . ', 0)'; $this->Conn->Query($sql); } } function ResetLink($original_values) { - static $has_been_reset = Array(); + static $has_been_reset = Array (); - if( $original_values['Status'] != STATUS_ACTIVE || - getArrayValue($has_been_reset, $original_values['ListingId']) ) - { + if ( $original_values['Status'] != STATUS_ACTIVE || getArrayValue($has_been_reset, $original_values['ListingId']) ) { return; } $has_been_reset[$original_values['ListingId']] = 1; $this->UpdateLink('OnExpire', $original_values['ItemResourceId'], $original_values['ListingTypeId']); - $listtype_object = $this->Application->recallObject('lst'); - if( $listtype_object->GetDBField('OnExpireRemoveFromCatEnabled') ) - { - $remove_from_cat = $listtype_object->GetDBField('OnExpireRemoveFromCat'); - $sql = 'DELETE FROM '.$this->Application->getUnitOption('l-ci', 'TableName').' - WHERE ItemResourceId = '.$original_values['ItemResourceId'].' - AND CategoryId = '.$remove_from_cat.' + $listing_type_object = $this->Application->recallObject('lst'); + /* @var $listing_type_object kDBItem */ + + if ( $listing_type_object->GetDBField('OnExpireRemoveFromCatEnabled') ) { + $remove_from_cat = $listing_type_object->GetDBField('OnExpireRemoveFromCat'); + + $sql = 'DELETE FROM ' . $this->Application->getUnitConfig('l-ci')->getTableName() . ' + WHERE ItemResourceId = ' . $original_values['ItemResourceId'] . ' + AND CategoryId = ' . $remove_from_cat . ' AND PrimaryCat = 0'; $this->Conn->Query($sql); } @@ -341,9 +360,11 @@ return false; } - // get resource_id of link beeing enhanced + $links_config = $this->Application->getUnitConfig('l'); + + // get resource_id of link being enhanced $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption('l', 'TableName').' + FROM '.$links_config->getTableName().' WHERE LinkId = '.$link_id; $resource_id = $this->Conn->GetOne($sql); @@ -376,6 +397,8 @@ // set expiration time for listing $listing_type = $this->Application->recallObject('lst', null, Array('skip_autoload' => true)); + /* @var $listing_type kDBItem */ + $listing_type->Load($listing_type_id); $dur_type_mapping = Array( 1 => 1, @@ -412,7 +435,7 @@ // when requesting enhancement from front (and not via in-commerce) $event->redirect = $this->Application->GetVar('success_template'); - $sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').' + $sql = 'SELECT CreatedById FROM '.$links_config->getTableName().' WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); $this->Application->emailUser('LINK.ENHANCE', $this->Conn->GetOne($sql)); $this->Application->emailAdmin('LINK.ENHANCE'); @@ -445,8 +468,9 @@ unset($item_data['ListingTypeId']); $item_data['ListingId'] = $object->GetID(); - $orditems_idfield = $this->Application->getUnitOption('orditems', 'IDField'); - $orditems_table = $this->Application->getUnitOption('orditems', 'TableName'); + $order_items_config = $this->Application->getUnitConfig('orditems'); + $orditems_idfield = $order_items_config->getIDField(); + $orditems_table = $order_items_config->getTableName(); $this->Conn->doUpdate( Array('ItemData' => serialize($item_data)), $orditems_table, $orditems_idfield.' = '.$fields['OrderItemId'] ); } @@ -517,7 +541,7 @@ $fields = $event->getEventParam('field_values'); $item_data = unserialize($fields['ItemData']); - $sql = 'SELECT ListingId FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $sql = 'SELECT ListingId FROM ' . $event->getUnitConfig()->getTableName() . ' WHERE ItemResourceId = ' . $item_data['LinkId']; $listing_id = $this->Conn->GetOne($sql); @@ -547,6 +571,7 @@ /* @var $object kDBItem */ $ids = $this->StoreSelectedIDs($event); + $links_config = $this->Application->getUnitConfig('l'); if ( $event->Name == 'OnMassApprove' ) { foreach ($ids as $id) { @@ -567,7 +592,7 @@ $this->ResetLink($original_values); $sql = 'SELECT CreatedById - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + FROM ' . $links_config->getTableName() . ' WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); $this->Application->emailUser('LINK.ENHANCE.DENY', $this->Conn->GetOne($sql)); $this->Application->emailAdmin('LINK.ENHANCE.DENY'); @@ -586,7 +611,7 @@ $object->Load($id); $sql = 'SELECT CreatedById - FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + FROM ' . $links_config->getTableName() . ' WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); $owner_id = $this->Conn->GetOne($sql); @@ -656,7 +681,7 @@ $link_id = $this->Application->GetVar('l_id'); $user_id = $this->Application->RecallVar('user_id'); $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption('l', 'TableName').' + FROM '.$this->Application->getUnitConfig('l')->getTableName().' WHERE (LinkId = '.$link_id.') AND (CreatedById = '.$user_id.')'; $resource_id = $this->Conn->GetOne($sql); @@ -666,7 +691,7 @@ } $sql = 'SELECT ListingId - FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' + FROM '.$event->getUnitConfig()->getTableName().' WHERE ItemResourceId = '.$resource_id; return $this->Conn->GetOne($sql); @@ -686,7 +711,7 @@ $object->Update(); $event->redirect = $this->Application->GetVar('success_template'); - $sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').' + $sql = 'SELECT CreatedById FROM '.$this->Application->getUnitConfig('l')->getTableName().' WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); $this->Application->emailUser('LINK.ENHANCE.EXTEND', $this->Conn->GetOne($sql)); $this->Application->emailAdmin('LINK.ENHANCE.EXTEND'); @@ -713,7 +738,7 @@ $original_values['Status'] = 1; $this->ResetLink($original_values); - $sql = 'SELECT CreatedById FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + $sql = 'SELECT CreatedById FROM ' . $this->Application->getUnitConfig('l')->getTableName() . ' WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); $this->Application->emailUser('LINK.ENHANCE.CANCEL', $this->Conn->GetOne($sql)); $this->Application->emailAdmin('LINK.ENHANCE.CANCEL'); @@ -729,7 +754,10 @@ */ function OnCheckExpiredPaidListings($event) { - $sql = 'SELECT ListingId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' + $config = $event->getUnitConfig(); + $links_config = $this->Application->getUnitConfig('l'); + + $sql = 'SELECT ListingId FROM '.$config->getTableName().' WHERE ExpiresOn < '.adodb_mktime().' AND Status = 1'; $expired_listings = $this->Conn->GetCol($sql); if(is_array($expired_listings) && count($expired_listings) > 0) @@ -745,17 +773,17 @@ $object->SetDBField('Status', 2); $object->Update(); - $sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').' + $sql = 'SELECT CreatedById FROM '.$links_config->getTableName().' WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); $this->Application->emailUser('LINK.ENHANCE.EXPIRE', $this->Conn->GetOne($sql)); $this->Application->emailAdmin('LINK.ENHANCE.EXPIRE'); } } - $sql = 'SELECT ls.ListingId, l.CreatedById FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' ls - LEFT JOIN '.$this->Application->getUnitOption('lst', 'TableName').' lst + $sql = 'SELECT ls.ListingId, l.CreatedById FROM '.$config->getTableName().' ls + LEFT JOIN '.$this->Application->getUnitConfig('lst')->getTableName().' lst ON ls.ListingTypeId = lst.ListingTypeId - LEFT JOIN '.$this->Application->getUnitOption('l', 'TableName').' l + LEFT JOIN '.$links_config->getTableName().' l ON ls.ItemResourceId = l.ResourceId WHERE ls.Status = 1 AND ls.ExpiresOn < '.adodb_mktime().' + lst.RenewalReminder * 3600 *24 @@ -770,7 +798,7 @@ $this->Application->emailAdmin('LINK.ENHANCE.RENEWAL.NOTICE'); $listing_ids[] = $record['ListingId']; } - $sql = 'UPDATE '.$this->Application->getUnitOption($event->Prefix, 'TableName').' + $sql = 'UPDATE '.$config->getTableName().' SET RenewalReminderSent = 1 WHERE ListingId IN ('.implode(',', $listing_ids).')'; $this->Conn->Query($sql); @@ -809,8 +837,9 @@ */ function OnMoveEnhancement($event) { - $id_field = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'IDField'); - $item_table_name = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TableName'); + $master_config = $event->MasterEvent->getUnitConfig(); + $id_field = $master_config->getIDField(); + $item_table_name = $master_config->getTableName(); $pending_id = $event->MasterEvent->getEventParam('id'); $original_id = $event->MasterEvent->getEventParam('original_id'); @@ -820,7 +849,7 @@ WHERE '.$id_field.' IN ('.$pending_id.','.$original_id.')'; $resource_ids = $this->Conn->GetCol($sql, $id_field); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $table_name = $event->getUnitConfig()->getTableName(); $sql = 'UPDATE '.$table_name.' SET ItemResourceId = '.$resource_ids[$pending_id].' WHERE ItemResourceId = '.$resource_ids[$original_id]; @@ -839,8 +868,9 @@ parent::OnAfterConfigRead($event); $language_id = $this->Application->GetVar('m_lang'); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - $calculated_fields['']['LinkName'] = 'CONCAT(item_table.l' . $language_id . '_Name, " (", item_table.Url, ")")'; - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); + + $event->getUnitConfig()->addCalculatedFieldsBySpecial('', Array ( + 'LinkName' => 'CONCAT(item_table.l' . $language_id . '_Name, " (", item_table.Url, ")")', + )); } } \ No newline at end of file Index: branches/5.3.x/install/upgrades.php =================================================================== diff -u -N -r15672 -r15696 --- branches/5.3.x/install/upgrades.php (.../upgrades.php) (revision 15672) +++ branches/5.3.x/install/upgrades.php (.../upgrades.php) (revision 15696) @@ -1,6 +1,6 @@ Application->getUnitConfig('c'); $root_category = $this->Application->findModule('Name', 'In-Link', 'RootCat'); - $sql = 'UPDATE ' . $this->Application->getUnitOption('c', 'TableName') . ' + $sql = 'UPDATE ' . $categories_config->getTableName() . ' SET UseMenuIconUrl = 1, MenuIconUrl = "in-link/img/menu_links.gif" - WHERE ' . $this->Application->getUnitOption('c', 'IDField') . ' = ' . $root_category; + WHERE ' . $categories_config->getIDField() . ' = ' . $root_category; $this->Conn->Query($sql); $this->_updateDetailTemplate('l', 'inlink/detail', 'in-link/designs/detail'); Index: branches/5.3.x/units/links/links_event_handler.php =================================================================== diff -u -N -r15672 -r15696 --- branches/5.3.x/units/links/links_event_handler.php (.../links_event_handler.php) (revision 15672) +++ branches/5.3.x/units/links/links_event_handler.php (.../links_event_handler.php) (revision 15696) @@ -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(); + $sql = 'SELECT * FROM ' . $table_name . ' WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ')'; @@ -245,13 +247,14 @@ { parent::OnAfterConfigRead($event); - if (defined('IS_INSTALL') && IS_INSTALL) { - return ; + if ( defined('IS_INSTALL') && IS_INSTALL ) { + return; } + $config = $event->getUnitConfig(); $free_listings = $this->Application->ConfigValue('Link_AllowFreeListings'); - $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields'); + $virtual_fields = $config->getVirtualFields(); $virtual_fields['ListingTypeId']['options'] = $free_listings ? Array (0 => 'lu_free_listing') : Array (); $language_id = $this->Application->GetVar('m_lang'); @@ -261,11 +264,11 @@ $default = $virtual_fields['DuplicateCheckFields']['default']; $virtual_fields['DuplicateCheckFields']['default'] = str_replace('|Name|', '|l' . $language_id . '_Name|', $default); - $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields); + $config->setVirtualFields($virtual_fields); - if (!$this->Application->isAdminUser) { + if ( !$this->Application->isAdminUser ) { // for now only on Front-End - $this->Application->setUnitOption($event->Prefix, 'PopulateMlFields', true); + $event->getUnitConfig()->setPopulateMlFields(true); } } @@ -425,8 +428,9 @@ $link_helper = $this->Application->recallObject('LinkHelper'); /* @var $link_helper LinkHelper */ - $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(); // 1. verify all links, that were not verified previously $sql = 'SELECT ' . $id_field . ' @@ -493,8 +497,10 @@ $load_keys[$field] = $field . ' = ' . $this->Conn->qstr($value); } - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + $config = $event->getUnitConfig(); + + $sql = 'SELECT ' . $config->getIDField() . ' + FROM ' . $config->getTableName() . ' WHERE (' . implode(') AND (', $load_keys) . ')'; $id = $this->Conn->GetOne($sql); } @@ -527,22 +533,24 @@ parent::OnCloneSubItem($event); if ( $event->MasterEvent->Prefix == 'rev' ) { - $clones = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Clones'); - $subitem_prefix = $event->Prefix . '-' . $event->MasterEvent->Prefix; + $master_config = $event->MasterEvent->getUnitConfig(); + $sub_item_prefix = $event->Prefix . '-' . $event->MasterEvent->Prefix; - $clones[$subitem_prefix]['ConfigMapping'] = Array ( - 'PerPage' => 'Perpage_LinkReviews', - 'ShortListPerPage' => 'Perpage_LinkReviews_Short', - 'DefaultSorting1Field' => 'Link_ReviewsSort', - 'DefaultSorting2Field' => 'Link_ReviewsSort2', - 'DefaultSorting1Dir' => 'Link_ReviewsOrder', - 'DefaultSorting2Dir' => 'Link_ReviewsOrder2', + $master_config->addClones(Array ( + $sub_item_prefix => Array ( + 'ConfigMapping' => Array ( + 'PerPage' => 'Perpage_LinkReviews', + 'ShortListPerPage' => 'Perpage_LinkReviews_Short', + 'DefaultSorting1Field' => 'Link_ReviewsSort', + 'DefaultSorting2Field' => 'Link_ReviewsSort2', + 'DefaultSorting1Dir' => 'Link_ReviewsOrder', + 'DefaultSorting2Dir' => 'Link_ReviewsOrder2', - 'ReviewDelayInterval' => 'link_ReviewDelay_Interval', - 'ReviewDelayValue' => 'link_ReviewDelay_Value', - ); - - $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Clones', $clones); + 'ReviewDelayInterval' => 'link_ReviewDelay_Interval', + 'ReviewDelayValue' => 'link_ReviewDelay_Value', + ) + ) + )); } } @@ -562,10 +570,11 @@ $link_id = $event->getEventParam('original_id'); $new_resource_id = $object->GetDBField('ResourceId'); + $config = $event->getUnitConfig(); $sql = 'SELECT ResourceId - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' - WHERE ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . '=' . $link_id; + FROM ' . $config->getTableName() . ' + WHERE ' . $config->getIDField() . '=' . $link_id; $old_resource_id = $this->Conn->GetOne($sql); $this->Application->SetVar('original_resource_id', $old_resource_id); @@ -605,7 +614,7 @@ protected function changeResourceId($prefix, $field, $old_resource_id, $new_resource_id) { $fields_hash = Array ($field => $new_resource_id); - $table_name = $this->Application->getUnitOption($prefix, 'TableName'); + $table_name = $this->Application->getUnitConfig($prefix)->getTableName(); $this->Conn->doUpdate($fields_hash, $table_name, $field . ' = ' . $old_resource_id); } Index: branches/5.3.x/units/links/link_tag_processor.php =================================================================== diff -u -N -r15486 -r15696 --- branches/5.3.x/units/links/link_tag_processor.php (.../link_tag_processor.php) (revision 15486) +++ branches/5.3.x/units/links/link_tag_processor.php (.../link_tag_processor.php) (revision 15696) @@ -1,6 +1,6 @@ Application->getUnitOption('ls', 'TableName').' - WHERE ItemResourceId = '.$resource_id; + FROM ' . $this->Application->getUnitConfig('ls')->getTableName() . ' + WHERE ItemResourceId = ' . $resource_id; $listing_info = $this->Conn->GetRow($sql); + return isset($field) ? $listing_info[$field] : $listing_info; } @@ -119,8 +120,8 @@ $listing_info = $this->getListingInfo($object->GetDBField('ResourceId')); $sql = 'SELECT RenewalReminder - FROM '.$this->Application->getUnitOption('lst', 'TableName').' - WHERE ListingTypeId = '.$listing_info['ListingTypeId']; + FROM ' . $this->Application->getUnitConfig('lst')->getTableName() . ' + WHERE ListingTypeId = ' . $listing_info['ListingTypeId']; $renewal_interval = $this->Conn->GetOne($sql) * 3600 * 24; return ($listing_info['ExpiresOn'] - adodb_mktime() < $renewal_interval) ? 1 : 0; @@ -282,7 +283,7 @@ */ function LastVisited($params) { - if (!$this->Application->LoggedIn()) { + if ( !$this->Application->LoggedIn() ) { // we don't gather link visit statistics for Guests return ''; } @@ -292,30 +293,31 @@ $object = $this->getObject($params); /* @var $object kDBList */ - if (!isset($link_visited[$this->Special])) { + if ( !isset($link_visited[$this->Special]) ) { $resource_ids = $object->GetCol('ResourceId'); $user_id = $this->Application->RecallVar('user_id'); - $table_name = $this->Application->getUnitOption('l-visit', 'TableName'); + $table_name = $this->Application->getUnitConfig('l-visit')->getTableName(); $sql = 'SELECT VisitTimestamp, ResourceId - FROM '.$table_name.' - WHERE (PortalUserId = '.$user_id.') AND (ResourceId IN ('.implode(',', $resource_ids).'))'; + FROM ' . $table_name . ' + WHERE (PortalUserId = ' . $user_id . ') AND (ResourceId IN (' . implode(',', $resource_ids) . '))'; $link_visited[$this->Special] = $this->Conn->GetCol($sql, 'ResourceId'); } - if (!isset($link_visited[$this->Special][$object->GetDBField('ResourceId')])) { + if ( !isset($link_visited[$this->Special][$object->GetDBField('ResourceId')]) ) { // link has no visit information for current user return ''; } $link_visit = $link_visited[$this->Special][$object->GetDBField('ResourceId')]; - if (isset($params['formatted']) && $params['formatted']) { + if ( isset($params['formatted']) && $params['formatted'] ) { // format the date $lang = $this->Application->recallObject('lang.current'); + /* @var $lang LanguagesItem */ - if (isset($params['display_time']) && $params['display_time']) { - $display_format = $lang->GetDBField('DateFormat').' @ '.$lang->GetDBField('TimeFormat'); + if ( isset($params['display_time']) && $params['display_time'] ) { + $display_format = $lang->GetDBField('DateFormat') . ' @ ' . $lang->GetDBField('TimeFormat'); } else { $display_format = $lang->GetDBField('DateFormat'); @@ -409,19 +411,21 @@ // 1. get current grouping $grouping = $link_helper->getGrouping( $this->getPrefixSpecial() ); + $config = $this->getUnitConfig(); + // 2. replace field names in grouping with their corresponding column titles - $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); + $grids = $config->getGrids(); + foreach ($grouping as $index => $group_field) { $group_field = preg_replace('/^l[\d]+_/', '', $group_field); // remove ml prefix $grouping[$index] = $this->Application->Phrase($grids[$grid]['Fields'][$group_field]['title']); } // 3. patch resulting title preset $concat_with = "' " . $this->Application->Phrase('la_and') . " '"; - $title_presets = $this->Application->getUnitOption($this->Prefix, 'TitlePresets'); - $title_presets['duplicate_links'] = str_replace('%s', "'" . implode($concat_with, $grouping) . "'", $title_presets['duplicate_links']); - - $this->Application->setUnitOption($this->Prefix, 'TitlePresets', $title_presets); + $title_preset = $config->getTitlePresetByName('duplicate_links'); + $title_preset = str_replace('%s', "'" . implode($concat_with, $grouping) . "'", $title_preset); + $config->addTitlePresets($title_preset, 'duplicate_links'); } /**