Commit d8771a21 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 5fcaf4aa
Pipeline #17647 passed with stage
in 25 minutes and 32 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
......@@ -581,54 +581,53 @@ class AuthController extends ZendAfi_Controller_Action {
public function preRegistrationAction() {
$this->view->titre = $this->_('Demande de préinscription');
$this->view->help_message = nl2br(Class_Profil::getCurrentProfil()->getModulePreference('auth', 'pre-registration', 'help_message'));
$registration = new Class_User_PreRegistration($this->view,
function ($message) {
$this->_helper->notify($message); });
if (!$form = $registration->getForm()) {
$this->_helper->notify($this->_('Cette fonctionnalité n\'est pas activée.'));
return $this->_redirect('opac/index');
}
if ('' != $this->_getParam('website'))
return $this->_redirect('/');
return $this->_redirectToReferer();
$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()]);
$registration = Class_WebService_SIGB_AbstractPreRegistration::newFor(Class_Users::getIdentity());
if ( ! $registration->isEnabled()) {
$this->_helper->notify(implode(' ', $registration->getLogger()->getMessages()));
return $this->_redirectToReferer();
}
$this->view->form = $form->populate(ZendAfi_Filters_Post::filterStatic($this->_request->getParams()));
$this->view->titre = $this->_('Demande de préinscription');
$this->view->form = $registration->getForm();
$this->view->help_message =
(nl2br(Class_Profil::getCurrentProfil()
->getModulePreference('auth',
'pre-registration',
'help_message')));
if (!$this->_request->isPost())
return;
$data = ZendAfi_Filters_Post::filterStatic($this->_request->getPost());
unset($data['website']);
if (!$form->isValid($data))
$this->view->form->populate($data);
if (!$this->view->form->isValid($data))
return;
$registration->send($data, $user)
? $this->_preRegistrationRedirect('pre-registration-success',
$registration->getLibrary())
: $this->_preRegistrationRedirect('pre-registration',
$registration->getLibrary());
}
unset($data['website']);
unset($data[Class_WebService_SIGB_AbstractPreRegistration::REQUIRED_CHECKBOX_NAME]);
$registration_data = $registration->getData($data);
$registration->send($registration_data);
if ($messages = $registration->getLogger()->getMessages()) {
$this->_helper->notify(implode(' ', $messages));
return $this->_redirectToReferer();
}
$registration->sendMail($registration_data);
if ($messages = $registration->getLogger()->getMessages())
$this->_helper->notify(implode(' ', $messages));
protected function _preRegistrationRedirect($action, $library) {
$this->_redirect($this->view->absoluteUrl(['action' => $action, 'id_bib' => $library->getId()]));
$this->_redirect($this->view->url(['action' => 'pre-registration-success',
'id_bib' => $registration_data->getLibraryId()]));
}
......
......@@ -128,25 +128,45 @@ class IntBibLoader extends Storm_Model_Loader {
}
public function findAllNanookWithPreRegistration() {
$collection = new Storm_Model_Collection(Class_IntBib::findAll());
$combo = $collection
->select(function($int_bib)
{
return $int_bib->isPreRegistrationNanookEnabled();
})
->injectInto([],
function($combo, $library)
{
$combo[$library->getId()] = $library->getLabel();
return $combo;
});
public function findAllNanookLabelsWithPreRegistration() {
$combo =
$this->_findAllWithPreRegistration(fn($int_bib) => $int_bib->isPreRegistrationNanookEnabled())
->injectInto([],
function($combo, $library)
{
$combo[$library->getId()] = $library->getLabel();
return $combo;
});
asort($combo, SORT_STRING | SORT_FLAG_CASE);
return $combo;
}
public function findAllKohaLabelsWithPreRegistration() : array {
$branchcodes = [];
foreach(Class_IntBib::findAllKohaWithPreRegistration() as $int_bib) {
$from_webservice = $int_bib->getSIGBComm()->getBranches($int_bib->getId());
$branchcodes = array_merge($branchcodes, $from_webservice);
}
return $branchcodes;
}
public function findAllKohaWithPreRegistration() : array {
return $this->_findAllWithPreRegistration(fn($int_bib) => $int_bib->isPreRegistrationKohaEnabled())->getArrayCopy();
}
protected function _findAllWithPreRegistration(Closure $filter_callback) : Storm_Collection {
$collection = new Storm_Model_Collection(Class_IntBib::findAll());
return $collection->select(fn($int_bib) => $filter_callback($int_bib));
}
public function findAllWithPreRegistration() {
return (new Storm_Model_Collection(Class_IntBib::findAll()))
->select(function($int_bib) { return $int_bib->isPreRegistrationEnabled();});
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
abstract class Class_WebService_SIGB_AbstractPreRegistration {
use Trait_Translator, Trait_Logger;
const REQUIRED_CHECKBOX_NAME = 'conditions_message';
protected
$_user,
$_form;
public static function newFor(?Class_Users $user)
: Class_WebService_SIGB_AbstractPreRegistration {
$pre_registration = new Class_WebService_SIGB_PreRegistration_Null($user);
if ( ! $first = Class_IntBib::findAllWithPreRegistration()->first())
return $pre_registration;
return $first->isCommNanook()
? new Class_WebService_SIGB_Nanook_PreRegistration($user)
: new Class_WebService_SIGB_Koha_PreRegistration($user);
}
public function __construct(?Class_Users $user) {
if ($user)
$this->setUser($user);
$this
->initForm()
->setLogger(new Class_Log);
}
public function isEnabled() : bool {
if ( $this->_user && ( ! $this->_user->isInvite())) {
$this->getLogger()->log($this->_('%s, vous ne pouvez pas vous préinscrire à partir d\'un compte déjà connecté.', $this->_user->getNomAff()));
return false;
}
if ( ! $enabled_in_settings = $this->_isIntBibWithPreRegistrationEnabled())
$this->getLogger()->log($this->_('Malheureusement, la fonctionnalité de préinscription n\'est pas activée.'));
return $enabled_in_settings;
}
public function sendMail(Class_WebService_SIGB_PreRegistration_AbstractData $data) : self {
(new Class_WebService_SIGB_PreRegistration_Mail($data))
->setLogger($this->getLogger())
->send();
return $this;
}
public function setUser(Class_Users $user) : self {
$this->_user = $user;
return $this;
}
public function getForm() : ZendAfi_Form {
return $this->_form;
}
public function setForm(ZendAfi_Form $form) : self {
$this->_form = $form;
return $this;
}
public function initForm() : self {
if ($this->_form)
return $this->_form;
$form = $this->_getFormInstance();
$form = $this->_populateFormWith($form, $this->_user);
if ( ! $validation_message = trim(Class_AdminVar::get('PREREGISTRATION_CONDITIONS_MESSAGE')))
return $this->setForm($form);
$form->addElement('requiredCheckbox',
static::REQUIRED_CHECKBOX_NAME,
['label' => $validation_message ]);
$form->addDisplayGroup(['conditions_message'], 'conditions',
['legend' => $this->_('Conditions')]);
return $this->setForm($form);
}
protected function _isIntBibWithPreRegistrationEnabled() : bool {
return ( (bool) (new Storm_Collection(Class_IntBib::findAll()))
->detect(fn($int_bib) => $int_bib->isPreRegistrationEnabled()))
?? false;
}
protected function _populateFormWith(ZendAfi_Form $form,
?Class_Users $user) : ZendAfi_Form {
return $user
? $form->populate($this->getData([])->getUserDataForForm($user))
: $form;
}
abstract protected function _getFormInstance() : ZendAfi_Form;
abstract public function send(Class_WebService_SIGB_PreRegistration_AbstractData $data) : self;
abstract public function getData(array $data_as_array) : Class_WebService_SIGB_PreRegistration_AbstractData;
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_SIGB_Koha_PreRegistration extends Class_WebService_SIGB_AbstractPreRegistration {
public function send(Class_WebService_SIGB_PreRegistration_AbstractData $data) : self {
if( ! $data->getLibrary()) {
$this->getLogger()->log($this->_('Échec de la préinscription, la bibliothèque sélectionnée n\'est pas valide.'));
return $this;
}
$response = Class_IntBib::find($data->getBranchId())
->getSIGBComm()
->preRegistration($data->prepareForWebService());
if( ! $response['statut'])
$this->getLogger()->log($response['erreur']);
return $this;
}
public function getData(array $data_as_array) : Class_WebService_SIGB_PreRegistration_AbstractData {
return new Class_WebService_SIGB_Koha_PreRegistration_Data($data_as_array);
}
protected function _getFormInstance() : ZendAfi_Form {
return new ZendAfi_Form_PreRegistration_Koha;
}
}
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_SIGB_Koha_Preregistration_Data extends Class_WebService_SIGB_PreRegistration_AbstractData {
const
BRANCH_ID = 0,
BRANCH_CODE = 1;
protected static array $_fields_map =
['prenom' => 'firstname',
'nom' => 'surname',
'telephone' => 'phone',
'id_site' => 'branchcode',
'mail' => 'email',
'naissance' => 'dateofbirth',
'ville' => 'city',
'code_postal' => 'zipcode',
'adresse' => 'address'];
protected function _getBranchCode() : string {
return $this->_dataInBranch(static::BRANCH_CODE);
}
public function getBranchId() : string {
return $this->_dataInBranch(static::BRANCH_ID);
}
protected function _dataInBranch($key) : string {
if (!isset($this->_data_as_array['branchcode']))
return '';
return explode('|', $this->_data_as_array['branchcode'])[$key];
}
public function getEmail() : string {
return $this->_data_as_array['email'] ?? '';
}
public function prepareForWebService() : array {
$data = $this->_data_as_array;
$data['branchcode'] = $this->_getBranchCode();
$data['dateofbirth'] = Class_Date::human($data['dateofbirth'] ?? '', '%Y-%m-%d');
return array_filter($data);
}
}
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_SIGB_Nanook_Preregistration extends Class_WebService_SIGB_AbstractPreRegistration {
public function getData(array $data_as_array) : Class_WebService_SIGB_PreRegistration_AbstractData {
return new Class_WebService_SIGB_Nanook_PreRegistration_Data($data_as_array);
}
protected function _getFormInstance() : ZendAfi_Form {
return new ZendAfi_Form_PreRegistration_Nanook;
}
public function send(Class_WebService_SIGB_PreRegistration_AbstractData $data) : self {
$id = $data->getBranchId();
if(!$int_bib = Class_IntBib::find($id)) {
$this->getLogger()->log($this->_('Échec de la préinscription, la médiathèque sélectionnée n\'existe pas.'));
return $this;
}
$response = $int_bib->getSIGBComm()->preRegistration($data);
if (!$response['statut']) {
$this->getLogger()->log($response['erreur']);
return $this;
}
return $this->_updateUser($id, $response);
}
protected function _updateUser(int $library_id, array $response) {
if ( ! $this->_user)
return $this;
if (! $this->_user->isInvite()) {
$this->getLogger()->log($this->_('Votre compte ne vous permet pas de vous préinscrire.'));
return $this;
}
$this->_user
->beAbonneSIGB()
->setIdSite($library_id)
->setIdIntBib($library_id)
->setIdabon($this->_user->getLogin());
if (isset($response['patron_id']))
$this->_user->setIdSigb($response['patron_id']);
if ( ! $this->_user->save())
$this->getLogger()->log($this->_user->getError());
return $this;
}
}
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_SIGB_Nanook_Preregistration_Data extends Class_WebService_SIGB_PreRegistration_AbstractData {
protected static array $_fields_map =
['prenom' => 'firstName',
'nom' => 'lastName',
'mail' => ['mail', 'mail2'],
'naissance' => 'birthDate',
'ville' => 'town',
'code_postal' => 'zipcode',
'adresse' => 'address'];
protected function _getBranchCode() : string {
return $this->_data_as_array['site'] ?? '0';
}
public function getBranchId() : string {
return $this->_getBranchCode();
}
public function getEmail() : string {
return $this->_data_as_array['mail'] ?? '';
}
}
......@@ -387,11 +387,31 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
}
public function preRegistration($data) {
$data = array_filter($data);
protected function _getFieldsAllowedForPreregistration(){
return [
'mail',
'site',
'lastName',
'firstName',
'password',
'birthDate',
'town',
'zipcode',
'address',
'phoneNumber',
'lastNameResp',
'firstNameResp'
];
}
public function preRegistration(Class_WebService_SIGB_Nanook_Preregistration_Data $data) {
$tags_to_keep = $this->_getFieldsAllowedForPreregistration();
$data = array_filter($data->getDataAsArray(),
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']);
......@@ -425,6 +445,11 @@ class Class_Webservice_SIGB_Nanook_Service extends Class_WebService_SIGB_Abstrac
}
public function getEmail($data){
return $data['mail'] ?? '';
}
public function providesPickupLocations() {
if (null !== $this->_provide_pickup_locations)