Пример #1
0
 static function fetchIDListByUserID($userID)
 {
     if ($userID == eZUser::anonymousId()) {
         $userCache = eZUSer::getUserCacheByAnonymousId();
         $ruleArray = $userCache['discount_rules'];
     } else {
         $http = eZHTTPTool::instance();
         $handler = eZExpiryHandler::instance();
         $expiredTimeStamp = 0;
         if ($handler->hasTimestamp('user-discountrules-cache')) {
             $expiredTimeStamp = $handler->timestamp('user-discountrules-cache');
         }
         $ruleTimestamp =& $http->sessionVariable('eZUserDiscountRulesTimestamp');
         $ruleArray = false;
         // check for cached version in session
         if ($ruleTimestamp > $expiredTimeStamp) {
             if ($http->hasSessionVariable('eZUserDiscountRules' . $userID)) {
                 $ruleArray =& $http->sessionVariable('eZUserDiscountRules' . $userID);
             }
         }
         if (!is_array($ruleArray)) {
             $ruleArray = self::generateIDListByUserID((int) $userID);
             $http->setSessionVariable('eZUserDiscountRules' . $userID, $ruleArray);
             $http->setSessionVariable('eZUserDiscountRulesTimestamp', time());
         }
     }
     $rules = array();
     foreach ($ruleArray as $ruleRow) {
         $rules[] = $ruleRow['id'];
     }
     return $rules;
 }
Пример #2
0
function notification_addtonotification($nodeID)
{
    // code mostly stolen from notification/addtonotification view
    $user = eZUSer::currentUser();
    $contentNode = eZContentObjectTreeNode::fetch($nodeID);
    if (!$contentNode) {
        eZDebug::writeError('The nodeID parameter was empty or wrong, user ID: ' . $user->attribute('contentobject_id'), __METHOD__);
        throw new Exception('The nodeID parameter was empty or wrong', -10123);
    }
    if (!$contentNode->attribute('can_read')) {
        eZDebug::writeError('User does not have access to subscribe for notification, node ID: ' . $nodeID . ', user ID: ' . $user->attribute('contentobject_id'), __METHOD__);
        throw new Exception('User does not have access to subscribe for notification', -10234);
    }
    $nodeIDList = eZSubtreeNotificationRule::fetchNodesForUserID($user->attribute('contentobject_id'), false);
    if (!in_array($nodeID, $nodeIDList)) {
        $rule = eZSubtreeNotificationRule::create($nodeID, $user->attribute('contentobject_id'));
        $rule->store();
        return 1;
    }
    // notification already exists
    return 2;
}