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,247 additions
and
4 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
<?php | ||
|
||
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, | ||
'size' => 'large', | ||
'value' => '' | ||
])) | ||
->addField(new FieldText('familyName', [ | ||
'label' => __('user.familyName'), | ||
'description' => __('acceptInvitation.userDetailsForm.familyName.description'), | ||
'isRequired' => true, | ||
'size' => 'large', | ||
'value' => '' | ||
])) | ||
->addField(new FieldText('affiliation', [ | ||
'label' => __('user.affiliation'), | ||
'description' => __('acceptInvitation.userDetailsForm.affiliation.description'), | ||
'isRequired' => true, | ||
'size' => 'large', | ||
|
||
])) | ||
->addField(new FieldSelect('country', [ | ||
'label' => __('acceptInvitation.userDetailsForm.countyOfAffiliation.label'), | ||
'description' => __('acceptInvitation.userDetailsForm.countyOfAffiliation.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,55 @@ | ||
<?php | ||
|
||
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, | ||
'size' => 'large', | ||
])) | ||
->addField(new FieldText('familyName', [ | ||
'label' => __('user.familyName'), | ||
'description' => __('invitation.familyName.description'), | ||
'isRequired' => false, | ||
'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
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 | ||
|
||
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,35 @@ | ||
<?php | ||
|
||
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; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace PKP\invitation\sections; | ||
|
||
use Exception; | ||
use stdClass; | ||
|
||
abstract class Section | ||
{ | ||
public string $id; | ||
public string $type; | ||
public string $name; | ||
public string $description; | ||
|
||
/** | ||
* @param string $id A unique id for this step | ||
* @param string $name The name of this step. Shown to the user. | ||
* @param string $description A description of this step. Shown to the user. | ||
*/ | ||
public function __construct(string $id, string $name, string $description = '') | ||
{ | ||
$this->id = $id; | ||
$this->name = $name; | ||
$this->description = $description; | ||
if (!isset($this->type)) { | ||
throw new Exception('Decision workflow step created without specifying a type.'); | ||
} | ||
} | ||
|
||
/** | ||
* Compile initial state data to pass to the frontend | ||
*/ | ||
public function getState(): stdClass | ||
{ | ||
$config = new stdClass(); | ||
$config->id = $this->id; | ||
$config->type = $this->type; | ||
$config->name = $this->name; | ||
$config->description = $this->description; | ||
$config->errors = new stdClass(); | ||
|
||
return $config; | ||
} | ||
} |
Oops, something went wrong.