forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
send and accept invitation views php integrations
- Loading branch information
Showing
19 changed files
with
1,409 additions
and
4 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
classes/components/forms/invitation/AcceptUserDetailsForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* @file classes/components/forms/invitation/AcceptUserDetailsForm.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class AcceptUserDetailsForm | ||
* | ||
* | ||
* @brief Handles accept invitation user details form | ||
*/ | ||
|
||
namespace PKP\components\forms\invitation; | ||
|
||
use PKP\components\forms\FieldSelect; | ||
use PKP\components\forms\FieldText; | ||
use PKP\components\forms\FormComponent; | ||
use PKP\facades\Locale; | ||
|
||
define('ACCEPT_FORM_USER_DETAILS', 'acceptUserDetails'); | ||
class AcceptUserDetailsForm extends FormComponent | ||
{ | ||
/** @copydoc FormComponent::$id */ | ||
public $id = ACCEPT_FORM_USER_DETAILS; | ||
|
||
/** @copydoc FormComponent::$method */ | ||
public $method = 'POST'; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $action URL to submit the form to | ||
* @param array $locales Supported locales | ||
*/ | ||
public function __construct($action, $locales) | ||
{ | ||
$this->action = $action; | ||
$this->locales = $locales; | ||
|
||
$countries = []; | ||
foreach (Locale::getCountries() as $country) { | ||
$countries[] = [ | ||
'value' => $country->getAlpha2(), | ||
'label' => $country->getLocalName() | ||
]; | ||
} | ||
|
||
usort($countries, function ($a, $b) { | ||
return strcmp($a['label'], $b['label']); | ||
}); | ||
|
||
$this->addField(new FieldText('givenName', [ | ||
'label' => __('user.givenName'), | ||
'description' => __('acceptInvitation.userDetailsForm.givenName.description'), | ||
'isRequired' => true, | ||
'isMultilingual' => true, | ||
'size' => 'large', | ||
'value' => '' | ||
])) | ||
->addField(new FieldText('familyName', [ | ||
'label' => __('user.familyName'), | ||
'description' => __('acceptInvitation.userDetailsForm.familyName.description'), | ||
'isRequired' => true, | ||
'isMultilingual' => true, | ||
'size' => 'large', | ||
'value' => '' | ||
])) | ||
->addField(new FieldText('affiliation', [ | ||
'label' => __('user.affiliation'), | ||
'description' => __('acceptInvitation.userDetailsForm.affiliation.description'), | ||
'isMultilingual' => true, | ||
'isRequired' => true, | ||
'size' => 'large', | ||
|
||
])) | ||
->addField(new FieldSelect('userCountry', [ | ||
'label' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.label'), | ||
'description' => __('acceptInvitation.userDetailsForm.countryOfAffiliation.description'), | ||
'options' => $countries, | ||
'isRequired' => true, | ||
'size' => 'large', | ||
])); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* @file classes/components/forms/invitation/UserDetailsForm.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class AcceptUserDetailsForm | ||
* | ||
* | ||
* @brief Handles send invitation user details form | ||
*/ | ||
|
||
namespace PKP\components\forms\invitation; | ||
|
||
use PKP\components\forms\FieldHTML; | ||
use PKP\components\forms\FieldText; | ||
use PKP\components\forms\FormComponent; | ||
|
||
define('FORM_USER_DETAILS', 'userDetails'); | ||
class UserDetailsForm extends FormComponent | ||
{ | ||
/** @copydoc FormComponent::$id */ | ||
public $id = FORM_USER_DETAILS; | ||
|
||
/** @copydoc FormComponent::$method */ | ||
public $method = 'POST'; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $action URL to submit the form to | ||
* @param array $locales Supported locales | ||
* @param \PKP\context\Context $context Journal or Press to change settings for | ||
*/ | ||
public function __construct($action, $locales, $context) | ||
{ | ||
$this->action = $action; | ||
$this->locales = $locales; | ||
|
||
$this->addField(new FieldText('email', [ | ||
'label' => __('user.email'), | ||
'description' => __('invitation.email.description'), | ||
'isRequired' => true, | ||
'size' => 'large', | ||
])) | ||
->addField(new FieldHTML('orcid', [ | ||
'label' => __('user.orcid'), | ||
'description' => __('invitation.orcid.description'), | ||
'isRequired' => false, | ||
'size' => 'large', | ||
])) | ||
->addField(new FieldText('givenName', [ | ||
'label' => __('user.givenName'), | ||
'description' => __('invitation.givenName.description'), | ||
'isRequired' => false, | ||
'isMultilingual' => true, | ||
'size' => 'large', | ||
])) | ||
->addField(new FieldText('familyName', [ | ||
'label' => __('user.familyName'), | ||
'description' => __('invitation.familyName.description'), | ||
'isRequired' => false, | ||
'isMultilingual' => true, | ||
'size' => 'large', | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* @file classes/invitation/sections/Email.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class Email | ||
* | ||
* @brief A section in an invitation workflow that shows an email composer. | ||
*/ | ||
|
||
namespace PKP\invitation\sections; | ||
|
||
use APP\core\Application; | ||
use APP\facades\Repo; | ||
use Exception; | ||
use PKP\emailTemplate\EmailTemplate; | ||
use PKP\facades\Locale; | ||
use PKP\mail\Mailable; | ||
use PKP\user\User; | ||
use stdClass; | ||
|
||
class Email extends Section | ||
{ | ||
public bool $anonymousRecipients = false; | ||
public array $locales; | ||
public Mailable $mailable; | ||
public array $recipients; | ||
public string $type = 'email'; | ||
|
||
/** | ||
* @param array<User> $recipients One or more User objects who are the recipients of this email | ||
* @param Mailable $mailable The mailable that will be used to send this email | ||
* | ||
* @throws Exception | ||
*/ | ||
public function __construct(string $id, string $name, string $description, array $recipients, Mailable $mailable, array $locales) | ||
{ | ||
parent::__construct($id, $name, $description); | ||
$this->locales = $locales; | ||
$this->mailable = $mailable; | ||
$this->recipients = $recipients; | ||
} | ||
|
||
public function getState(): stdClass | ||
{ | ||
$config = parent::getState(); | ||
$config->canChangeRecipients = false; | ||
$config->canSkip = false; | ||
$config->emailTemplates = $this->getEmailTemplates(); | ||
$config->initialTemplateKey = $this->mailable::getEmailTemplateKey(); | ||
$config->recipientOptions = $this->getRecipientOptions(); | ||
$config->anonymousRecipients = $this->anonymousRecipients; | ||
$config->variables = []; | ||
$config->locale = Locale::getLocale(); | ||
$config->locales = []; | ||
return $config; | ||
} | ||
|
||
protected function getRecipientOptions(): array | ||
{ | ||
$recipientOptions = []; | ||
foreach ($this->recipients as $user) { | ||
$names = []; | ||
foreach ($this->locales as $locale) { | ||
$names[$locale] = $user->getFullName(true, false, $locale); | ||
} | ||
$recipientOptions[] = [ | ||
'value' => $user->getId(), | ||
'label' => $names, | ||
]; | ||
} | ||
return $recipientOptions; | ||
} | ||
|
||
protected function getEmailTemplates(): array | ||
{ | ||
$request = Application::get()->getRequest(); | ||
$context = $request->getContext(); | ||
|
||
$emailTemplates = collect(); | ||
if ($this->mailable::getEmailTemplateKey()) { | ||
$emailTemplate = Repo::emailTemplate()->getByKey($context->getId(), $this->mailable::getEmailTemplateKey()); | ||
if ($emailTemplate) { | ||
$emailTemplates->add($emailTemplate); | ||
} | ||
Repo::emailTemplate() | ||
->getCollector($context->getId()) | ||
->alternateTo([$this->mailable::getEmailTemplateKey()]) | ||
->getMany() | ||
->each(fn (EmailTemplate $e) => $emailTemplates->add($e)); | ||
} | ||
|
||
return Repo::emailTemplate()->getSchemaMap()->mapMany($emailTemplates)->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* @file classes/invitation/sections/Form.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class Form | ||
* | ||
* @brief A section in an invitation workflow that shows a form. | ||
*/ | ||
namespace PKP\invitation\sections; | ||
|
||
use Exception; | ||
use PKP\components\forms\FormComponent; | ||
use stdClass; | ||
|
||
class Form extends Section | ||
{ | ||
public string $type = 'form'; | ||
public FormComponent $form; | ||
|
||
/** | ||
* @param FormComponent $form The form to show in this step | ||
* | ||
* @throws Exception | ||
*/ | ||
public function __construct(string $id, string $name, string $description, FormComponent $form) | ||
{ | ||
parent::__construct($id, $name, $description); | ||
$this->form = $form; | ||
} | ||
|
||
public function getState(): stdClass | ||
{ | ||
$config = parent::getState(); | ||
foreach ($this->form->getConfig() as $key => $value) { | ||
$config->$key = $value; | ||
} | ||
unset($config->pages[0]['submitButton']); | ||
|
||
return $config; | ||
} | ||
} |
Oops, something went wrong.