Пример #1
0
$tpl = templateInit();
$templateFile = 'design:newsletter/user_edit.tpl';
$newsletterUserId = (int) $Params['NewsletterUserId'];
$contextCreateNewsletterUser = false;
$addSubscriptionForListId = false;
$subscriptionDataArr = array('first_name' => '', 'last_name' => '', 'email' => '', 'salutation' => '', 'note' => '', 'id_array' => array(), 'list_array' => array(), 'list_output_format_array' => array());
$warningArr = array();
$messageFeedback = '';
$context = 'user_edit';
$redirectUrlCancel = false;
$redirectUrlStore = false;
// TODO check if current user has access to user_create
// newsletter/user_edit/-1  => create new user
if ($newsletterUserId === -1) {
    $contextCreateNewsletterUser = true;
    $newsletterUserObject = CjwNewsletterUser::create($subscriptionDataArr['email'], $subscriptionDataArr['salutation'], $subscriptionDataArr['first_name'], $subscriptionDataArr['last_name'], false, CjwNewsletterUser::STATUS_CONFIRMED, $context, $customDataText1 = '', $customDataText2 = '', $customDataText3 = '', $customDataText4 = '');
} else {
    $contextCreateNewsletterUser = false;
    $newsletterUserObject = CjwNewsletterUser::fetch($newsletterUserId);
}
if (!is_object($newsletterUserObject)) {
    return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
// check if access came from user_create view
if ($http->hasVariable('UserCreateMsg')) {
    $userCreateMsg = $http->variable('UserCreateMsg');
    switch ($userCreateMsg) {
        case 'edit_new':
            $messageFeedback = ezi18n('cjw_newsletter/user_edit', 'Creating new newsletter user');
            break;
        case 'edit_existing':
Пример #2
0
 /**
  * Create or update Newsletter User identified by email
  * store the changes to Database
  *
  * @param string $email
  * @param int $salutation
  * @param string $firstName
  * @param string $lastName
  * @param int $eZUserId
  * @param int $newNewsletterUserStatus the status for new created Newsletter users CjwNewsletterUser::STATUS_PENDING
  * @param string $context
  * @param string $customDataText1
  * @param string $customDataText2
  * @param string $customDataText3
  * @param string $customDataText4
  * @return object
  */
 static function createUpdateNewsletterUser($email, $salutation, $firstName, $lastName, $eZUserId, $newNewsletterUserStatus = CjwNewsletterUser::STATUS_PENDING, $context = 'default', $customDataText1, $customDataText2, $customDataText3, $customDataText4)
 {
     //
     // 1. exist a current newsletter user?
     //    yes -> register on lists with status PENDING
     //    no  -> create new user with status PENDIG and than register
     //
     $existingNewsletterUserObject = CjwNewsletterUser::fetchByEmail($email);
     // update existing
     if (is_object($existingNewsletterUserObject)) {
         $userObject = $existingNewsletterUserObject;
         $userObject->setAttribute('salutation', $salutation);
         $userObject->setAttribute('first_name', $firstName);
         $userObject->setAttribute('last_name', $lastName);
         $userObject->setAttribute('ez_user_id', (int) $eZUserId);
         $userObject->setAttribute('modified', time());
         $userObject->setAttribute('custom_data_text_1', $customDataText1);
         $userObject->setAttribute('custom_data_text_2', $customDataText2);
         $userObject->setAttribute('custom_data_text_3', $customDataText3);
         $userObject->setAttribute('custom_data_text_4', $customDataText4);
         $userObject->store();
         CjwNewsletterLog::writeDebug('CjwNewsletterUser::createUpdateNewsletterUser', 'user', 'update', array('nl_user' => $userObject->attribute('id'), 'email' => $email, 'salutation' => $salutation, 'first_name' => $firstName, 'last_name' => $lastName, 'ez_user_id' => $userObject->attribute('ez_user_id'), 'status' => $userObject->attribute('status'), 'modifier' => eZUser::currentUserID(), 'context' => $context, 'custom_data_text_1' => $customDataText1, 'custom_data_text_2' => $customDataText2, 'custom_data_text_3' => $customDataText3, 'custom_data_text_4' => $customDataText4));
     } else {
         $userObject = CjwNewsletterUser::create($email, $salutation, $firstName, $lastName, $eZUserId, (int) $newNewsletterUserStatus, $context, $customDataText1, $customDataText2, $customDataText3, $customDataText4);
         if (is_object($userObject) !== TRUE) {
             // error creating the new user => user with same email already exists
             return false;
         }
         $userObject->store();
         CjwNewsletterLog::writeDebug('CjwNewsletterUser::createUpdateNewsletterUser', 'user', 'create', array('nl_user' => $userObject->attribute('id'), 'email' => $email, 'salutation' => $salutation, 'first_name' => $firstName, 'last_name' => $lastName, 'ez_user_id' => $userObject->attribute('ez_user_id'), 'status' => $userObject->attribute('status'), 'modifier' => eZUser::currentUserID(), 'context' => $context, 'custom_data_text_1' => $customDataText1, 'custom_data_text_2' => $customDataText2, 'custom_data_text_3' => $customDataText3, 'custom_data_text_4' => $customDataText4));
     }
     return $userObject;
 }