/**
  * fetch current data from contentobject for use in newsletter user object
  * @return array if success , false if user_account is not found in dataMap
  */
 private function fetchCurrentContentObjectData(&$contentObjectAttribute)
 {
     $http = eZHTTPTool::instance();
     // mapping of user data from contentobject for the newsletter user
     // the current object must be a User!!!
     $contentObject = $contentObjectAttribute->attribute('object');
     $contentObjectCurrentVersionId = (int) $contentObjectAttribute->attribute('version');
     $contentObjectIsPublished = $contentObject->attribute('is_published');
     // only for user/register  if version = 1 and published = false
     // don't fetch existing nl user because
     // otherwise you will see his registration
     $isNewObjectDraft = false;
     if ($contentObjectCurrentVersionId == 1 && $contentObjectIsPublished == false) {
         $isNewObjectDraft = true;
     }
     $dataMap = $contentObject->attribute('data_map');
     $userAccount = null;
     $subscriptionDataArr = array('ez_user_id' => 0, 'email' => '', 'salutation' => 0, 'first_name' => '', 'last_name' => '', 'id_array' => array(), 'list_array' => array());
     if (isset($dataMap['user_account'])) {
         $userAccount = $dataMap['user_account'];
     } else {
         return false;
     }
     if (isset($dataMap['salutation'])) {
         $subscriptionDataArr['salutation'] = (int) $dataMap['salutation']->content();
     }
     if (isset($dataMap['first_name'])) {
         $subscriptionDataArr['first_name'] = $dataMap['first_name']->content();
     }
     if (isset($dataMap['last_name'])) {
         $subscriptionDataArr['last_name'] = $dataMap['last_name']->content();
     }
     if (is_object($userAccount)) {
         $userAccountContent = $userAccount->content();
         // we are fetching the email directly from Post because we need this for checking
         // $subscriptionDataArr['email'] = $userAccountContent->attribute( 'email' );
         // has the value stored in db but not this from Post => onPublish has the Post value
         // only need for email
         // only in edit mode
         $base = 'ContentObjectAttribute';
         if ($http->hasPostVariable($base . "_data_user_email_" . $userAccount->attribute("id"))) {
             $subscriptionDataArr['email'] = $http->postVariable($base . "_data_user_email_" . $userAccount->attribute("id"));
         } else {
             $subscriptionDataArr['email'] = $userAccountContent->attribute('email');
         }
         $subscriptionDataArr['ez_user_id'] = (int) $userAccountContent->attribute('contentobject_id');
         // is_eabled is modified in user/register after this call
         // so we can't use this here
         //$newsletterUserDataArray['ez_user_is_enabled'] = $userAccount->attribute( 'is_enabled' );
     }
     if ($http->hasPostVariable('Subscription_IdArray')) {
         $subscriptionDataArr['id_array'] = $http->postVariable('Subscription_IdArray');
     }
     if ($http->hasPostVariable('Subscription_ListArray')) {
         $subscriptionDataArr['list_array'] = $http->postVariable('Subscription_ListArray');
     }
     foreach ($subscriptionDataArr['id_array'] as $listId) {
         if ($http->hasPostVariable("Subscription_OutputFormatArray_{$listId}")) {
             $subscriptionDataArr['list_output_format_array'][$listId] = $http->postVariable("Subscription_OutputFormatArray_{$listId}");
         } else {
             $defaultOutputFormatId = 0;
             $subscriptionDataArr['list_output_format_array'][$listId] = array($defaultOutputFormatId);
         }
     }
     if ($isNewObjectDraft === true) {
         $existingNewsletterUser = false;
     } elseif ($subscriptionDataArr['ez_user_id'] > 0) {
         $existingNewsletterUser = CjwNewsletterUser::fetchByEzUserId($subscriptionDataArr['ez_user_id']);
         if (is_object($existingNewsletterUser) === false) {
             if ($subscriptionDataArr['email'] != '') {
                 $existingNewsletterUser = CjwNewsletterUser::fetchByEmail($subscriptionDataArr['email']);
             }
         }
     } elseif ($subscriptionDataArr['email'] != '') {
         $existingNewsletterUser = CjwNewsletterUser::fetchByEmail($subscriptionDataArr['email']);
     } else {
         $existingNewsletterUser = false;
     }
     $returnArray = array('is_new_object_draft' => $isNewObjectDraft, 'subscription_data_array' => $subscriptionDataArr, 'existing_newsletter_user' => $existingNewsletterUser);
     // var_dump( $returnArray );
     return $returnArray;
 }
Ejemplo n.º 2
0
 /**
  * check if $email and $ezUserId can update/create
  * negative value fail
  * @see CjwNewsletterSubscription::createSubscriptionByArray
  */
 public static function checkIfUserCanBeUpdated($email, $ezUserId, $updateNewEmail = false)
 {
     // TODO cache fetches
     // check if new email exists in the system
     $idNlUser = CjwNewsletterUser::fetchByEzUserId($ezUserId);
     $emailNlUser = CjwNewsletterUser::fetchByEmail($email);
     $idNlUserEmail = false;
     $idNlUserEzUserId = 0;
     $idNlUserId = 0;
     $idNlUserExists = false;
     $emailNlUserEmail = false;
     $emailNlUserEzUserId = 0;
     $emailNlUserId = 0;
     $emailNlUserExists = false;
     if (is_object($idNlUser)) {
         $idNlUserEmail = strtolower(trim($idNlUser->attribute('email')));
         $idNlUserEzUserId = $idNlUser->attribute('ez_user_id');
         $idNlUserId = $idNlUser->attribute('id');
         if ($idNlUserEzUserId > 0) {
             $idNlUserExists = true;
         }
     } else {
         if ($ezUserId > 0) {
             $idNlUserEzUserId = $ezUserId;
         }
     }
     if (is_object($emailNlUser)) {
         $emailNlUserEmail = strtolower(trim($emailNlUser->attribute('email')));
         $emailNlUserEzUserId = $emailNlUser->attribute('ez_user_id');
         $emailNlUserId = $emailNlUser->attribute('id');
         $emailNlUserExists = true;
     } else {
         $emailNlUserEmail = $email;
     }
     // new user => email + ezUserId not found in any nl user objects  => 40
     // update user => ezUserId == 0 or found + email not found + email1 == email2 => 41
     // update user with new email => ez_user_id found + email1 != email2 => 42
     $returnStatus = -1;
     $returnObject = false;
     // email is already used by an other nl_user with other ez_user_id
     if ($emailNlUserExists && $emailNlUserEmail != $idNlUserEmail && $emailNlUserEzUserId != $idNlUserEzUserId) {
         $returnStatus = -20;
     } elseif (!$idNlUserExists && !$emailNlUserExists && $emailNlUserEmail == '') {
         $returnStatus = -21;
     } elseif (!$idNlUserExists && !$emailNlUserExists && $emailNlUserEmail != '') {
         $returnStatus = 40;
     } elseif ($idNlUserExists && $emailNlUserExists && $idNlUserId == $emailNlUserId) {
         $returnStatus = 41;
     } elseif ($idNlUserExists && !$emailNlUserExists && $emailNlUserEmail != '') {
         $returnStatus = 42;
         if ($updateNewEmail === true) {
             // check if email has is not set by an other user
             // this could happend when the nl user is imported
             // check this in where the user can change the email address
             // for example in datatype validation
             $idNlUser->setAttribute('email', $emailNlUserEmail);
             $idNlUser->store();
         }
     }
     /*
              echo "ezUserId = $ezUserId <br>
     idNlUserEmail = $idNlUserEmail <br>
     idNlUserId = $idNlUserId <br>
     idNlUserEzUserId = $idNlUserEzUserId <br>
     idNlUserExists = $idNlUserExists <br><hr>
     
     email = $email<br>
     emailNlUserEmail = $emailNlUserEmail<br>
     emailNlUserId = $emailNlUserId <br>
     emailNlUserEzUserId = $emailNlUserEzUserId<br>
     emailNlUserExists = $emailNlUserExists<br>
     <hr> return stratus = $returnStatus <hr>";
     */
     //
     return $returnStatus;
 }