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