Index: branches/5.2.x/units/listings/listings_event_handler.php =================================================================== diff -u -N -r14254 -r14626 --- branches/5.2.x/units/listings/listings_event_handler.php (.../listings_event_handler.php) (revision 14254) +++ branches/5.2.x/units/listings/listings_event_handler.php (.../listings_event_handler.php) (revision 14626) @@ -1,6 +1,6 @@ getObject(); - if ($object->IgnoreValidation) { + /* @var $object kDBItem */ + + if ( $object->IgnoreValidation ) { $object->UpdateFormattersMasterFields(); } } - function OnBeforeItemCreate(&$event) + /** + * Occurs before creating item + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $object =& $event->getObject(); - if ($object->IgnoreValidation) { + /* @var $object kDBItem */ + + if ( $object->IgnoreValidation ) { $object->UpdateFormattersMasterFields(); } } /** - * Enter description here... + * Occurs before an item is deleted from live table when copying from temp + * (temp handler deleted all items from live and then copy over all items from temp) + * Id of item being deleted is passed as event' 'id' param * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeDeleteFromLive(&$event) + protected function OnBeforeDeleteFromLive(&$event) { + parent::OnBeforeDeleteFromLive($event); + $object =& $event->getObject(); - $sql = 'SELECT * FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' - WHERE ListingId = '.$object->GetId(); + /* @var $object kDBItem */ + + $sql = 'SELECT * + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE ListingId = ' . $object->GetId(); $original_values = $this->Conn->GetRow($sql); $type_modified = ($object->GetDBField('ListingTypeId') != $original_values['ListingTypeId']); $link_modified = ($object->GetDBField('ItemResourceId') != $original_values['ItemResourceId']); $status_modified = ($object->GetDBField('Status') != $original_values['Status']); - if ($status_modified) { + if ( $status_modified ) { $email_event = $object->GetDBField('Status') ? 'LINK.ENHANCE.APPROVE' : 'LINK.ENHANCE.DENY'; - $sql = 'SELECT CreatedById FROM '.$this->Application->getUnitOption('l', 'TableName').' - WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); + $sql = 'SELECT CreatedById + FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); + $user_id = $this->Conn->GetOne($sql); - $email_event_user =& $this->Application->EmailEventUser($email_event, $this->Conn->GetOne($sql)); - $email_event_admin =& $this->Application->EmailEventAdmin($email_event); + $this->Application->EmailEventUser($email_event, $user_id); + $this->Application->EmailEventAdmin($email_event); } if ( $type_modified || $link_modified ) { @@ -492,36 +523,40 @@ } /** - * Enter description here... + * Apply same processing to each item being selected in grid * * @param kEvent $event + * @return void + * @access protected */ - function iterateItems(&$event) + protected function iterateItems(&$event) { - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ + $ids = $this->StoreSelectedIDs($event); - if ($event->Name == 'OnMassApprove') { + if ( $event->Name == 'OnMassApprove' ) { foreach ($ids as $id) { $object->Load($id); - if ($object->GetDBField('Status') != STATUS_ACTIVE) { + if ( $object->GetDBField('Status') != STATUS_ACTIVE ) { $original_values = $object->GetFieldValues(); $object->SetDBField('Status', STATUS_ACTIVE); $this->EnhanceLink($object, $original_values); } } } - if ($event->Name == 'OnMassDecline') { + if ( $event->Name == 'OnMassDecline' ) { foreach ($ids as $id) { $object->Load($id); - if ($object->GetDBField('Status') == STATUS_ACTIVE) { + if ( $object->GetDBField('Status') == STATUS_ACTIVE ) { $original_values = $object->GetFieldValues(); $this->ResetLink($original_values); $sql = 'SELECT CreatedById - FROM '.$this->Application->getUnitOption('l', 'TableName').' - WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); + FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.DENY', $this->Conn->GetOne($sql)); $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.DENY'); } @@ -531,30 +566,28 @@ parent::iterateItems($event); // extend period for pending/renewal links (if owner has agreed) - if ($event->Name == 'OnMassApprove') { - $lst_object =& $this->Application->recallObject('lst', null, Array('skip_autoload' => true)); + if ( $event->Name == 'OnMassApprove' ) { + $lst_object =& $this->Application->recallObject('lst', null, Array ('skip_autoload' => true)); + /* @var $lst_object kDBItem */ foreach ($ids as $id) { $object->Load($id); + $sql = 'SELECT CreatedById - FROM '.$this->Application->getUnitOption('l', 'TableName').' - WHERE ResourceId = '.$object->GetDBField('ItemResourceId'); + FROM ' . $this->Application->getUnitOption('l', 'TableName') . ' + WHERE ResourceId = ' . $object->GetDBField('ItemResourceId'); $owner_id = $this->Conn->GetOne($sql); - if ($object->GetDBField('PendingRenewal') == 1) { + if ( $object->GetDBField('PendingRenewal') == 1 ) { $lst_object->Load( $object->GetDBField('ListingTypeId') ); - $dur_type_mapping = Array( 1 => 1, - 2 => 60, - 3 => 3600, - 4 => 3600*24, - 5 => 3600*24*7, - 6 => 3600*24*365/12, - 7 => 3600*24*365 - ); + $dur_type_mapping = Array ( + 1 => 1, 2 => 60, 3 => 3600, 4 => 3600 * 24, 5 => 3600 * 24 * 7, + 6 => 3600 * 24 * 365 / 12, 7 => 3600 * 24 * 365 + ); $duration = $lst_object->GetDBField('Duration'); $duration_type = $lst_object->GetDBField('DurationType'); $expiration_interval = $duration * $dur_type_mapping[$duration_type]; - $renewal_begins = max( adodb_mktime(), $object->GetDBField('ExpiresOn') ); + $renewal_begins = max(adodb_mktime(), $object->GetDBField('ExpiresOn')); $expiration_date = $renewal_begins + $expiration_interval; $object->SetDBField('ExpiresOn_date', $expiration_date); @@ -563,21 +596,21 @@ $object->SetDBField('RenewalReminderSent', 0); $object->SetDBField('PendingRenewal', 0); - if ($object->Update()) { + if ( $object->Update() ) { $event->status = kEvent::erSUCCESS; - $event->setRedirectParams(Array('opener' => 's'), true); - $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.RENEW', $owner_id); - $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.RENEW'); + $event->setRedirectParams(Array ('opener' => 's'), true); + $this->Application->EmailEventUser('LINK.ENHANCE.RENEW', $owner_id); + $this->Application->EmailEventAdmin('LINK.ENHANCE.RENEW'); } else { - $event->status=kEvent::erFAIL; - $event->redirect=false; + $event->status = kEvent::erFAIL; + $event->redirect = false; break; } } else { - $email_event_user =& $this->Application->EmailEventUser('LINK.ENHANCE.APPROVE', $owner_id); - $email_event_admin =& $this->Application->EmailEventAdmin('LINK.ENHANCE.APPROVE'); + $this->Application->EmailEventUser('LINK.ENHANCE.APPROVE', $owner_id); + $this->Application->EmailEventAdmin('LINK.ENHANCE.APPROVE'); } } } @@ -587,12 +620,14 @@ * Redirects to cancel template on front-end * * @param kEvent $event + * @return void + * @access protected */ - function OnCancel(&$event) + protected function OnCancel(&$event) { parent::OnCancel($event); - if (!$this->Application->isAdmin) { + if ( !$this->Application->isAdmin ) { $event->SetRedirectParam('opener', 's'); $event->redirect = $this->Application->GetVar('cancel_template'); } @@ -732,21 +767,24 @@ * Removes enhancements on listing delete * * @param kEvent $event + * @return void + * @access protected */ - function OnMassDelete(&$event) + protected function OnMassDelete(&$event) { - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject( Array ('skip_autoload' => true) ); + /*@var $object kDBItem */ + $ids = $this->StoreSelectedIDs($event); - foreach($ids as $id) - { + foreach ($ids as $id) { $object->Load($id); - if($object->GetDBField('Status') == 1) - { - $original_values = $object->GetFieldValues(); - $this->ResetLink($original_values); + + if ( $object->GetDBField('Status') == STATUS_ACTIVE ) { + $this->ResetLink( $object->GetFieldValues() ); } } + parent::OnMassDelete($event); }