Example #1
0
 public function onSubscriptionDeleted(Am_Event_SubscriptionDeleted $event)
 {
     if (!$this->getConfig('expired_list')) {
         return;
     }
     $user = $event->getUser();
     $lmDb = $this->getConfig('db') . '.' . $this->getConfig('prefix');
     Am_Di::getInstance()->db->query("\n            INSERT INTO {$lmDb}users\n                (uid,list,fname,lname,email,cseq,cdel,cnf,dateadd,htmail)\n            VALUES\n                (?,?,?,?,?, 1, 0, 1, ?, 1)\n            ", $this->_getUniqUid(), $this->getConfig('expired_list'), $user->name_f, $user->name_l, $user->email, sqlDate(time()));
 }
Example #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();
     }
 }