Index: branches/5.3.x/units/listings/listings_event_handler.php =================================================================== diff -u -N -r15926 -r15937 --- branches/5.3.x/units/listings/listings_event_handler.php (.../listings_event_handler.php) (revision 15926) +++ branches/5.3.x/units/listings/listings_event_handler.php (.../listings_event_handler.php) (revision 15937) @@ -1,6 +1,6 @@ GetDBField('Status') != $original_values['Status']); if ( $status_modified ) { - $email_event = $object->GetDBField('Status') ? 'LINK.ENHANCE.APPROVE' : 'LINK.ENHANCE.DENY'; - $sql = 'SELECT CreatedById - FROM ' . $this->Application->getUnitConfig('l')->getTableName() . ' - WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); - $user_id = $this->Conn->GetOne($sql); - - $this->Application->emailUser($email_event, $user_id); - $this->Application->emailAdmin($email_event); + $email_template = $object->GetDBField('Status') ? 'LINK.ENHANCE.APPROVE' : 'LINK.ENHANCE.DENY'; + $this->notifyOwner($email_template, $object); } if ( $type_modified || $link_modified ) { @@ -434,11 +428,7 @@ case 'OnListingCreate': // when requesting enhancement from front (and not via in-commerce) $event->redirect = $this->Application->GetVar('success_template'); - - $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'); + $this->notifyOwner('LINK.ENHANCE', $object); break; } @@ -592,12 +582,7 @@ if ( $object->GetDBField('Status') == STATUS_ACTIVE ) { $original_values = $object->GetFieldValues(); $this->ResetLink($original_values); - - $sql = 'SELECT CreatedById - 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'); + $this->notifyOwner('LINK.ENHANCE.DENY', $object); } } } @@ -612,11 +597,6 @@ foreach ($ids as $id) { $object->Load($id); - $sql = 'SELECT CreatedById - FROM ' . $links_config->getTableName() . ' - WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); - $owner_id = $this->Conn->GetOne($sql); - if ( $object->GetDBField('PendingRenewal') == 1 ) { $lst_object->Load( $object->GetDBField('ListingTypeId') ); $dur_type_mapping = Array ( @@ -638,8 +618,7 @@ if ( $object->Update() ) { $event->status = kEvent::erSUCCESS; $event->SetRedirectParam('opener', 's'); - $this->Application->emailUser('LINK.ENHANCE.RENEW', $owner_id); - $this->Application->emailAdmin('LINK.ENHANCE.RENEW'); + $this->notifyOwner('LINK.ENHANCE.RENEW', $object); } else { $event->status = kEvent::erFAIL; @@ -648,8 +627,7 @@ } } else { - $this->Application->emailUser('LINK.ENHANCE.APPROVE', $owner_id); - $this->Application->emailAdmin('LINK.ENHANCE.APPROVE'); + $this->notifyOwner('LINK.ENHANCE.APPROVE', $object); } } } @@ -699,24 +677,22 @@ return $this->Conn->GetOne($sql); } - function OnExtendEnhancement($event) + protected function OnExtendEnhancement(kEvent $event) { $listing_id = $this->verifyListingOwner($event); if (!$listing_id) { return ; } $object = $event->getObject( Array('skip_autoload' => true) ); + /* @var $object kDBItem */ + $object->Load($listing_id); $object->SetDBField('PendingRenewal', 1); $object->Update(); $event->redirect = $this->Application->GetVar('success_template'); - - $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'); + $this->notifyOwner('LINK.ENHANCE.EXTEND', $object); } /** @@ -739,12 +715,8 @@ $original_values = $object->GetFieldValues(); $original_values['Status'] = 1; $this->ResetLink($original_values); + $this->notifyOwner('LINK.ENHANCE.CANCEL', $object); - $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'); - $object->Delete(); $event->redirect = $this->Application->GetVar('success_template'); } @@ -774,30 +746,33 @@ $this->ResetLink($original_values); $object->SetDBField('Status', 2); $object->Update(); - - $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'); + $this->notifyOwner('LINK.ENHANCE.EXPIRE', $object); } } - $sql = 'SELECT ls.ListingId, l.CreatedById FROM '.$config->getTableName().' ls - LEFT JOIN '.$this->Application->getUnitConfig('lst')->getTableName().' lst + $link_id_field = $this->Application->getUnitConfig('l')->getIDField(); + $sql = 'SELECT ls.ListingId, l.CreatedById, l.' . $link_id_field . ' FROM ' . $config->getTableName() . ' ls + LEFT JOIN ' . $this->Application->getUnitConfig('lst')->getTableName() . ' lst ON ls.ListingTypeId = lst.ListingTypeId - LEFT JOIN '.$links_config->getTableName().' l + LEFT JOIN ' . $links_config->getTableName() . ' l ON ls.ItemResourceId = l.ResourceId WHERE ls.Status = 1 - AND ls.ExpiresOn < '.time().' + lst.RenewalReminder * 3600 *24 + AND ls.ExpiresOn < ' . time() . ' + lst.RenewalReminder * 3600 *24 AND ls.RenewalReminderSent = 0'; $res = $this->Conn->Query($sql); + if(is_array($res) && count($res) > 0) { $listing_ids = Array(); foreach($res as $record) { - $this->Application->emailUser('LINK.ENHANCE.RENEWAL.NOTICE', $record['CreatedById']); - $this->Application->emailAdmin('LINK.ENHANCE.RENEWAL.NOTICE'); + $send_params = Array ( + 'PrefixSpecial' => 'l', + 'item_id' => $record[$link_id_field] + ); + + $this->Application->emailUser('LINK.ENHANCE.RENEWAL.NOTICE', $record['CreatedById'], $send_params); + $this->Application->emailAdmin('LINK.ENHANCE.RENEWAL.NOTICE', null, $send_params); $listing_ids[] = $record['ListingId']; } $sql = 'UPDATE '.$config->getTableName().' @@ -859,6 +834,33 @@ } /** + * Notifies link owner about listing related action. + * + * @param string $email_template E-mail template. + * @param kDBItem $listing Listing. + * + * @return void + */ + protected function notifyOwner($email_template, kDBItem $listing) + { + $unit_config = $this->Application->getUnitConfig('l'); + $id_field = $unit_config->getIDField(); + + $sql = 'SELECT CreatedById, ' . $id_field . ' + FROM ' . $unit_config->getTableName() . ' + WHERE ResourceId = ' . $listing->GetDBField('ItemResourceId'); + $link_data = $this->Conn->GetRow($sql); + + $send_params = array( + 'PrefixSpecial' => 'l', + 'item_id' => $link_data[$id_field], + ); + + $this->Application->emailUser($email_template, $link_data['CreatedById'], $send_params); + $this->Application->emailAdmin($email_template, null, $send_params); + } + + /** * Makes calculated fields to go to multilingual link fields * * @param kEvent $event Index: branches/5.3.x/units/links/links_event_handler.php =================================================================== diff -u -N -r15926 -r15937 --- branches/5.3.x/units/links/links_event_handler.php (.../links_event_handler.php) (revision 15926) +++ branches/5.3.x/units/links/links_event_handler.php (.../links_event_handler.php) (revision 15937) @@ -1,6 +1,6 @@ getObject(); // get link object /* @var $object kDBItem */ - $send_params = Array( + $send_params = $object->getEmailParams(Array( 'from_name' => $this->Application->GetVar('ContactFormFullName'), 'from_email' => $this->Application->GetVar('ContactFormEmail'), 'from_subject' => $this->Application->GetVar('ContactFormSubject'), 'message' => $this->Application->GetVar('ContactFormBody'), 'to_linkname' => $object->GetField('Name'), - ); + )); $email_sent = $this->Application->emailUser('LINK.CONTACTFORM', $object->GetDBField('CreatedById'), $send_params); @@ -406,7 +406,7 @@ $object->SetDBField('ReciprocalLinkFound', $link_checked ? LINK_IS_RECIPROCAL : LINK_IS_NOT_RECIPROCAL); if (!$link_checked) { - $this->Application->emailAdmin('LINK.RECIPROCAL.CHECK.FAILED'); + $this->Application->emailAdmin('LINK.RECIPROCAL.CHECK.FAILED', null, $object->getEmailParams()); } } } @@ -451,7 +451,7 @@ } else { $object->DeclineChanges(); - $this->Application->emailAdmin('LINK.RECIPROCAL.CHECK.FAILED'); + $this->Application->emailAdmin('LINK.RECIPROCAL.CHECK.FAILED', null, $object->getEmailParams()); } }