Commit af552422 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

hotline#147634 : pre-registration : mail sent now can use placeholders...

hotline#147634 : pre-registration : mail sent now can use placeholders {user.nom} and {user.prenom} for subscriber first name and last name
parent b22737d3
Pipeline #17504 failed with stage
in 8 minutes and 35 seconds
- correctif #147634 : Préinscription : Les mails de préinscription avec le SIGB Nanook peuvent être customisés avec les entrées {user.first_name} {user.last_name} pour afficher respectivement le prénom et le nom rentrés par l'utilisateur
\ No newline at end of file
......@@ -597,16 +597,8 @@ class AuthController extends ZendAfi_Controller_Action {
$form = $registration->getForm();
if ($user = Class_Users::getIdentity()) {
$form->populate(['birthDate' => $user->getNaissance(),
'mail' => $user->getMail(),
'mail2' => $user->getMail(),
'lastName' => $user->getNom(),
'firstName' => $user->getPrenom(),
'town' => $user->getVille(),
'zipcode' => $user->getCodePostal(),
'address' => $user->getAdresse()]);
}
if ($user = Class_Users::getIdentity())
$registration->populateFormWith($user);
$this->view->form = $form->populate(ZendAfi_Filters_Post::filterStatic($this->_request->getParams()));
......
......@@ -57,9 +57,10 @@ class Class_User_PreRegistration {
return false;
}
$bokeh_preregistered_user = $this->_webservice->getUserFromData($data);
if ($this->_email = $this->_webservice->getEmail($data))
$this->_sendEmailNotification($data);
$this->_sendEmailNotification($bokeh_preregistered_user);
return true;
}
......@@ -98,7 +99,7 @@ class Class_User_PreRegistration {
$modelfusion = (new Class_ModeleFusion())
->setContenu($template)
->setDataSource(['library' => $this->getLibrary(), 'user' => new Class_Entity($data)]);
->setDataSource(['library' => $this->getLibrary(), 'user' => $data]);
return ($templated = $modelfusion->getContenuFusionne())
? $templated
......
......@@ -387,11 +387,31 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
}
protected function _getFieldsAllowedForPreregistration(){
return [
'mail',
'site',
'lastName',
'firstName',
'password',
'birthDate',
'town',
'zipcode',
'address',
'phoneNumber',
'lastNameResp',
'firstNameResp'
];
}
public function preRegistration($data) {
$data = array_filter($data);
$tags_to_keep = $this->_getFieldsAllowedForPreregistration();
$data = array_filter($data,
fn ($val, $key) => in_array($key, $tags_to_keep) && $val,
ARRAY_FILTER_USE_BOTH);
unset($data['mail2']);
unset($data['password2']);
$data['site'] = (int) $data['site'];
$url = $this->buildQueryURL(['service' => 'pre-register']);
......
......@@ -27,7 +27,8 @@ class Class_WebService_SIGB_PreRegistration {
protected
$_enabled,
$_strategy,
$_errors;
$_errors,
$_form;
public function isEnabled() {
......@@ -50,7 +51,25 @@ class Class_WebService_SIGB_PreRegistration {
$form->addDisplayGroup(['conditions_message'], 'conditions',
['legend' => $this->_('Conditions')]);
return $form;
return $this->_form = $form;
}
public function getFieldMapping() {
return $this->getStrategy()->getFieldMapping();
}
public function populateFormWith($userdata) {
$userfieldmapping = $this->getFieldMapping();
$default_values = [];
foreach ($this->_form->getElementsNames() as $name)
if ($userfieldmapping[$name])
$default_values[$name] = call_user_func([$userdata,'get'.Storm_Inflector::camelize($userfieldmapping[$name])]);
$this->_form->populate($default_values);
return $this;
}
......@@ -93,6 +112,16 @@ class Class_WebService_SIGB_PreRegistration {
}
public function getUserFromData($data){
$user = [];
$mapping = $this->getFieldMapping();
foreach ($data as $key => $value)
if (isset($mapping[$key])) $user[Storm_Inflector::camelize($mapping[$key])]=$value;
return new Class_Entity($user);
}
public function addError($message) {
$this->getErrors()->append($message);
}
......@@ -146,6 +175,9 @@ class Class_WebService_SIGB_PreRegistrationAbstract {
public function getEmail($data) {}
public function getFieldMapping() {}
}
......@@ -157,6 +189,21 @@ class Class_WebService_SIGB_PreRegistrationNanook extends Class_WebService_SIGB_
}
public function getFieldMapping() {
return [
'firstName' => 'prenom',
'lastName' => 'nom',
'site' => 'bib',
'birthDate' => 'naissance',
'mail2' => 'mail',
'mail' => 'mail',
'town' => 'ville',
'zipcode' => 'code_postal',
'address' => 'adresse'
];
}
public function send($data, $user) {
if(!$int_bib = Class_IntBib::find($this->getBranchCode($data)))
return $this->_pre_registration->addError($this->_('Échec de la préinscription, la médiathèque sélectionnée n\'existe pas.'));
......@@ -211,6 +258,20 @@ class Class_WebService_SIGB_PreRegistrationKoha extends Class_WebService_SIGB_Pr
}
public function getFieldMapping() {
return [
'firstname' => 'prenom',
'surname' => 'nom',
'branchcode' => 'bib',
'dateofbirth' => 'naissance',
'address' => 'adresse',
'zipcode' => 'code_postal',
'city' => 'ville',
'phone' => 'telephone'
];
}
public function send($data, $user) {
$int_bib = $this->_extractIntBibFrom($data);
return $this->_preRegistrationWithKoha($int_bib, $data);
......
......@@ -456,6 +456,8 @@ class AuthControllerPreRegistrationNanookPostDispatchTest
'address' => '123'])
->answers(NanooKFixtures::xmlGetPatronInfoFrancoisMorel());
Class_AdminVar::set('NOTIFICATION_TEMPLATE_PREREGISTRATION',"Bonjour {user.prenom} {user.nom},<br><br><p>Votre demande d'inscription à <b>{library.libelle}</b> a bien été enregistrée.</p><p>Afin de finaliser votre inscription, merci de vous rendre dans votre médiathèque : <b>{library.adresse} {library.cp} {library.ville}</b></p>");
$this->postDispatch('/opac/auth/pre-registration', ['site' => '1',
'lastName' => 'Jiro',
'firstName' => 'Tom',
......@@ -494,6 +496,13 @@ class AuthControllerPreRegistrationNanookPostDispatchTest
$this->assertContains('Préinscription à Arcadia',
quoted_printable_decode($this->mock_transport->getSentMails()[0]->getSubject()));
}
/** @test */
public function mailBodyShouldContainsBonjourTomJiro() {
$this->assertContains('Bonjour Tom Jiro,',
quoted_printable_decode($this->mock_transport->getSentMails()[0]->getBodyHtml()->getContent()));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment