예제 #1
0
 /**
  * @param Am_Event_SubscriptionChanged $event 
  * @param User $oldUser presents if called from onUserLoginChanged
  */
 function onSubscriptionChanged(Am_Event_SubscriptionChanged $event, User $oldUser = null)
 {
     if ($oldUser === null) {
         $oldUser = $event->getUser();
     }
     $user = $event->getUser();
     $found = $this->getTable()->findByAmember($oldUser);
     if ($found) {
         if ($this->canUpdate($found)) {
             $this->getTable()->updateFromAmember($found, $user, $this->calculateGroups($user, true));
             $pass = $this->findPassword($user, true);
             if ($pass) {
                 $this->getTable()->updatePassword($found, $pass);
             }
         }
     } elseif ($groups = $this->calculateGroups($user, false)) {
         // we will only insert record if it makes sense - there are groups
         $this->getTable()->insertFromAmember($user, $this->findPassword($user, true), $groups);
     }
 }
예제 #2
0
 function checkSubscriptions($updateCache = false)
 {
     if (!$this->user_id) {
         throw new Am_Exception_InternalError("Could not do User->checkSubscriptions() : user_id is empty");
     }
     if ($updateCache) {
         $this->getDi()->resourceAccessTable->updateCache($this->user_id);
     }
     $newStatus = $this->getDi()->accessTable->getStatusByUserId($this->user_id);
     $active = array_keys(array_filter($newStatus, array($this, '_trueIfActive')));
     $oldStatus = $this->getProductsStatus();
     $saved = array_keys(array_filter($oldStatus, array($this, '_trueIfActive')));
     $merged = array_unique(array_merge($active, $saved));
     $added = array_diff($merged, $saved);
     $deleted = array_diff($merged, $active);
     foreach ($added as $product_id) {
         $e = new Am_Event_SubscriptionAdded($this, $this->getDi()->productTable->load($product_id));
         $e->run();
     }
     foreach ($deleted as $product_id) {
         $e = new Am_Event_SubscriptionDeleted($this, $this->getDi()->productTable->load($product_id));
         $e->run();
     }
     if ($active) {
         $newUserStatus = self::STATUS_ACTIVE;
     } elseif (array_filter($newStatus, array($this, '_trueIfExpired'))) {
         $newUserStatus = self::STATUS_EXPIRED;
     } else {
         $newUserStatus = self::STATUS_PENDING;
     }
     if ($newUserStatus != @$this->status) {
         $this->sendSignupEmailIfNecessary();
         $this->updateQuick('status', $newUserStatus);
     }
     if ($added || $deleted || array_diff_assoc($newStatus, $oldStatus)) {
         $this->data()->set(self::NEED_SESSION_REFRESH, true)->update();
         $this->getDi()->userStatusTable->setByUserId($this->user_id, $newStatus);
         $e = new Am_Event_SubscriptionChanged($this, $added, $deleted);
         $e->run();
     }
 }
예제 #3
0
 function onSubscriptionChanged(Am_Event_SubscriptionChanged $event)
 {
     $this->getDi()->newsletterUserSubscriptionTable->checkSubscriptions($event->getUser());
 }