Index: branches/5.2.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php =================================================================== diff -u -N -r14258 -r14625 --- branches/5.2.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php (.../affiliate_payment_types_event_handler.php) (revision 14258) +++ branches/5.2.x/units/affiliate_payment_types/affiliate_payment_types_event_handler.php (.../affiliate_payment_types_event_handler.php) (revision 14625) @@ -1,6 +1,6 @@ Special == 'active') - { + if ( !$this->Application->isAdmin ) { $object =& $event->getObject(); - $object->addFilter('active', '%1$s.Status = 1'); + /* @var $object kDBList */ + + $object->addFilter('active', '%1$s.Status = ' . STATUS_ACTIVE); } } @@ -38,51 +47,74 @@ /** - * Enter description here... + * Ensures, that user have only one "use as billing" / "use as shipping" address * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + + $this->itemChanged($event); + } + + /** + * Occurs before creating item + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemCreate(&$event) + { + parent::OnBeforeItemCreate($event); + + $this->itemChanged($event); + } + + /** + * Occurs before item is changed + * + * @param kEvent $event + */ + function itemChanged(&$event) + { $object =& $event->getObject(); + /* @var $object kDBItem */ - if ($object->GetDBField('IsPrimary') && $object->Validate()) { - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $sql = 'UPDATE '.$table_name.' SET IsPrimary = 0'; + if ( $object->GetDBField('IsPrimary') && $object->Validate() ) { + $sql = 'UPDATE ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + SET IsPrimary = 0'; $this->Conn->Query($sql); - $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') ); + $status_field = array_shift( $this->Application->getUnitOption($event->Prefix, 'StatusField') ); $object->SetDBField($status_field, 1); } } - function OnBeforeItemCreate(&$event) + /** + * Don't allow to delete primary affiliate payment type + * + * @param kEvent $event + * @param string $type + * @return void + * @access protected + */ + protected function customProcessing(&$event, $type) { - $this->OnBeforeItemUpdate($event); - } + if ( $event->Name == 'OnMassDelete' && $type == 'before' ) { + $ids = $event->getEventParam('ids'); - function OnMassDelete(&$event) - { - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { - $event->status = kEvent::erFAIL; - return; - } + $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE IsPrimary = 1'; + $primary_id = $this->Conn->GetOne($sql); - $this->StoreSelectedIDs($event); - $event->setEventParam('ids', $this->getSelectedIDs($event) ); - $ids = $event->getEventParam('ids'); + $ids = array_diff($ids, Array ($primary_id)); - $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); - - $sql = 'SELECT AffiliatePlanId FROM '.$this->Application->getUnitOption('ap', 'TableName').' - WHERE IsPrimary = 1'; - $primary_id = $this->Conn->GetOne($sql); - $ids = array_diff($ids, Array($primary_id)); - - if($ids) - { - $temp->DeleteItems($event->Prefix, $event->Special, $ids); + $event->setEventParam('ids', $ids); } - $this->clearSelectedIDs($event); } } \ No newline at end of file