コード例 #1
0
 public function apiUnsubscribe($params)
 {
     if (empty($params['emails']) || !is_array($params['emails'])) {
         throw new InvalidArgumentException('Invalid email list');
     }
     foreach ($params['emails'] as $email) {
         $user = BOL_UserService::getInstance()->findByEmail($email);
         if ($user === null) {
             throw new LogicException('User with email ' . $email . ' not found');
         }
         $userId = $user->getId();
         $activeActions = $this->service->collectActionList();
         $rules = $this->service->findRuleList($userId);
         $action = empty($params['action']) ? null : $params['action'];
         foreach ($activeActions as $actionInfo) {
             if ($action !== null && $actionInfo['action'] != $action) {
                 continue;
             }
             if (empty($rules[$actionInfo['action']])) {
                 $rule = new NOTIFICATIONS_BOL_Rule();
                 $rule->action = $actionInfo['action'];
                 $rule->userId = $userId;
             } else {
                 $rule = $rules[$actionInfo['action']];
             }
             $rule->checked = false;
             $this->service->saveRule($rule);
         }
     }
 }