Application->isAdmin ) { $object =& $event->getObject(); /* @var $object kDBList */ $object->addFilter('active', '%1$s.Status = ' . STATUS_ACTIVE); } } /** * Enter description here... * * @param kEvent $event */ function OnSetPrimary(&$event) { $object =& $event->getObject(); /* @var $object kDBItem */ $object->SetDBField('IsPrimary', 1); $object->Update(); } /** * Ensures, that user have only one "use as billing" / "use as shipping" address * * @param kEvent $event * @return void * @access protected */ protected function OnBeforeItemUpdate(kEvent &$event) { parent::OnBeforeItemUpdate($event); $this->itemChanged($event); } /** * Occurs before creating item * * @param kEvent $event * @return void * @access protected */ protected function OnBeforeItemCreate(kEvent &$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() ) { $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') ); $object->SetDBField($status_field, 1); } } /** * Don't allow to delete primary affiliate payment type * * @param kEvent $event * @param string $type * @return void * @access protected */ protected function customProcessing(kEvent &$event, $type) { if ( $event->Name == 'OnMassDelete' && $type == 'before' ) { $ids = $event->getEventParam('ids'); $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' WHERE IsPrimary = 1'; $primary_id = $this->Conn->GetOne($sql); $ids = array_diff($ids, Array ($primary_id)); $event->setEventParam('ids', $ids); } } }