/** * Import registrations and registration types. */ function importRegistrations() { if ($this->hasOption('verbose')) { printf("Importing registrations\n"); } $registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO'); $registrationDao =& DAORegistry::getDAO('RegistrationDAO'); $userDao =& DAORegistry::getDAO('UserDAO'); $registrationTypes = array(); foreach ($this->conferenceInfo as $conferenceId => $conferenceInfo) { $levels = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_levels']))); $fees = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_fees']))); $levelsLate = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_levels_late']))); $feesLate = array_map('trim', split("\n", Core::cleanVar($conferenceInfo['reg_fees_late']))); $lateDate = Core::cleanVar($conferenceInfo['reg_late_date']); $schedConf =& $this->schedConfMap[$conferenceId]; foreach ($levels as $key => $level) { $fee = $fees[$key]; $registrationType = new RegistrationType(); $registrationType->setSchedConfId($schedConf->getId()); $registrationType->setName($level, Locale::getLocale()); $registrationType->setCost($fee); $registrationType->setCurrencyCodeAlpha('USD'); // FIXME? $registrationType->setOpeningDate(Core::cleanVar($conferenceInfo['accept_deadline'])); $registrationType->setClosingDate($lateDate); $registrationType->setAccess(REGISTRATION_TYPE_ACCESS_ONLINE); $registrationType->setPublic(0); $registrationType->setInstitutional(0); $registrationType->setMembership(0); $registrationType->setSequence($key); $registrationTypeDao->insertRegistrationType($registrationType); $registrationTypes[substr($level, 0, 60)] =& $registrationType; // Truncated in 1.x DB unset($registrationType); } foreach ($levelsLate as $key => $level) { $fee = $feesLate[$key]; $registrationType = new RegistrationType(); $registrationType->setSchedConfId($schedConf->getId()); $registrationType->setName($level . ' (Late)', Locale::getLocale()); $registrationType->setCost($fee); $registrationType->setCurrencyCodeAlpha('USD'); // FIXME? $registrationType->setOpeningDate($lateDate); $registrationType->setClosingDate(Core::cleanVar($conferenceInfo['start_date'])); $registrationType->setAccess(REGISTRATION_TYPE_ACCESS_ONLINE); $registrationType->setPublic(0); $registrationType->setInstitutional(0); $registrationType->setMembership(0); $registrationType->setSequence($key); $registrationTypeDao->insertRegistrationType($registrationType); $registrationTypes[substr($level, 0, 60) . ' (Late)'] =& $registrationType; // Truncated in 1.x DB unset($registrationType); } } $result =& $this->importDao->retrieve('SELECT * FROM registrants ORDER BY cf, id'); while (!$result->EOF) { $row =& $result->fields; $schedConf =& $this->schedConfMap[$row['cf']]; $email = Core::cleanVar($row['email']); if (!($user =& $userDao->getUserByEmail($email))) { // The user doesn't exist by email; create one. $name = Core::cleanVar($row['name']); $nameParts = split(' ', $name); $lastName = array_pop($nameParts); $firstName = join(' ', $nameParts); $user = new User(); $user->setEmail($email); $user->setFirstName($firstName); $user->setLastName($lastName); $user->setPhone(Core::cleanVar($row['phone'])); $user->setFax(Core::cleanVar($row['fax'])); $user->setMailingAddress(Core::cleanVar($row['address'])); $i = ""; while ($userDao->userExistsByUsername($lastName . $i)) { $i++; } $user->setUsername($lastName . $i); $user->setDateRegistered($row['date_registered']); $user->setDateLastLogin(null); $user->setMustChangePassword(1); $password = Validation::generatePassword(); $user->setPassword(Validation::encryptCredentials($user->getUsername(), $password)); $userDao->insertUser($user); if ($this->hasOption('emailUsers')) { import('classes.mail.MailTemplate'); $mail = new MailTemplate('USER_REGISTER'); $mail->setFrom($schedConf->getSetting('contactEmail'), $schedConf->getSetting('contactName')); $mail->assignParams(array('username' => $user->getUsername(), 'password' => $password, 'conferenceName' => $schedConf->getFullTitle())); $mail->addRecipient($user->getEmail(), $user->getFullName()); $mail->send(); } } $regLevel = trim(Core::cleanVar($row['reg_level'])); $regFee = Core::cleanVar($row['reg_fee']); $conferenceInfo =& $this->conferenceInfo[$row['cf']]; $seekingRegLevel = $regLevel . (strtotime($row['date_registered']) > strtotime($conferenceInfo['reg_late_date']) ? ' (Late)' : ''); $registrationType =& $registrationTypes[$seekingRegLevel]; if (!$registrationType || $registrationType->getCost() != $regFee) { if (!$registrationType) { $this->errors[] = "Registration data inconsistency: Registration type \"{$seekingRegLevel}\" not found for user with email {$email}."; } else { $this->errors[] = "Registration data inconsistency: Paid registration fee {$regFee} does not match registration type cost for \"{$seekingRegLevel}\" (" . $registrationType->getCost() . ") for user with email {$email}."; unset($registrationType); } unset($user); unset($schedConf); $result->MoveNext(); continue; } if ($registrationDao->registrationExistsByUser($user->getId(), $schedConf->getId())) { $this->errors[] = "A duplicate registration (level \"{$seekingRegLevel}\") was skipped for user with email {$email}."; } else { $registration = new Registration(); $registration->setSchedConfId($schedConf->getId()); $registration->setUserId($user->getId()); $registration->setTypeId($registrationType->getTypeId()); if ($row['has_paid'] == 'paid') { $registration->setDatePaid(Core::cleanVar($row['date_paid'])); } $registration->setSpecialRequests(Core::cleanVar($row['special_requests'])); $registration->setDateRegistered($row['date_registered']); $registrationDao->insertRegistration($registration); unset($registration); } unset($user); unset($registrationType); unset($conferenceInfo); unset($schedConf); $result->MoveNext(); } $result->Close(); }
/** * Internal function to return a RegistrationType object from a row. * @param $row array * @return RegistrationType */ function &_returnRegistrationTypeFromRow(&$row) { $registrationType = new RegistrationType(); $registrationType->setTypeId($row['type_id']); $registrationType->setSchedConfId($row['sched_conf_id']); $registrationType->setCode($row['code']); $registrationType->setCost($row['cost']); $registrationType->setCurrencyCodeAlpha($row['currency_code_alpha']); $registrationType->setOpeningDate($this->dateFromDB($row['opening_date'])); $registrationType->setClosingDate($this->datetimeFromDB($row['closing_date'])); $registrationType->setExpiryDate($this->datetimeFromDB($row['expiry_date'])); $registrationType->setAccess($row['access']); $registrationType->setInstitutional($row['institutional']); $registrationType->setMembership($row['membership']); $registrationType->setPublic($row['pub']); $registrationType->setSequence($row['seq']); $this->getDataObjectSettings('registration_type_settings', 'type_id', $row['type_id'], $registrationType); HookRegistry::call('RegistrationTypeDAO::_returnRegistrationTypeFromRow', array(&$registrationType, &$row)); return $registrationType; }