152 lines
3.9 KiB
PHP
152 lines
3.9 KiB
PHP
<?php
|
|
|
|
use CRM_Mailinglistsync_ExtensionUtil as E;
|
|
use Civi\Mailinglistsync\MailingListSettings as Settings;
|
|
|
|
/**
|
|
* Form controller class
|
|
*
|
|
* @see https://docs.civicrm.org/dev/en/latest/framework/quickform/
|
|
*/
|
|
class CRM_Mailinglistsync_Form_MailingListSettings extends CRM_Core_Form {
|
|
|
|
protected ?array $_settings = NULL;
|
|
|
|
public function buildQuickForm(): void {
|
|
$this->add(
|
|
'checkbox',
|
|
E::SHORT_NAME . '_enable',
|
|
label: E::ts('Enable synchronization of mailing lists groups and events'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'checkbox',
|
|
E::SHORT_NAME . '_logging',
|
|
label: E::ts('Enable logging of synchronization'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'text',
|
|
E::SHORT_NAME . '_domain',
|
|
label: E::ts('Domain for mailing list email addresses'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'text',
|
|
E::SHORT_NAME . '_mlmmj_host',
|
|
label: E::ts('mlmmj Host'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'password',
|
|
E::SHORT_NAME . '_mlmmj_token',
|
|
label: E::ts('mlmmj Token'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'text',
|
|
E::SHORT_NAME . '_mlmmj_port',
|
|
label: E::ts('mlmmj Port<br>(default: 443)'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'text',
|
|
E::SHORT_NAME . '_dovecot_host',
|
|
label: E::ts('Dovecot Host'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'password',
|
|
E::SHORT_NAME . '_dovecot_token',
|
|
label: E::ts('Dovecot Token'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'text',
|
|
E::SHORT_NAME . '_dovecot_port',
|
|
label: E::ts('Dovecot Port<br>(default: 443)'),
|
|
extra: ['class' => 'huge'],
|
|
);
|
|
$this->add(
|
|
'select',
|
|
E::SHORT_NAME . '_participant_status',
|
|
label: E::ts('Participant status'),
|
|
attributes: static::getParticipantStatusOptions(),
|
|
extra: ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
|
|
);
|
|
$this->add(
|
|
'select',
|
|
E::SHORT_NAME . '_ad_contact_tags',
|
|
label: E::ts('Tags to restrict contact matching for AD groups'),
|
|
attributes: static::getContactTags(),
|
|
extra: ['class' => 'crm-select2 huge', 'multiple' => 'multiple']
|
|
);
|
|
$this->addButtons([
|
|
[
|
|
'type' => 'submit',
|
|
'name' => E::ts('Submit'),
|
|
'isDefault' => TRUE,
|
|
],
|
|
]);
|
|
|
|
$this->assign('EXTENSION_SHORT_NAME', E::SHORT_NAME);
|
|
|
|
parent::buildQuickForm();
|
|
}
|
|
|
|
public function setDefaultValues() {
|
|
return Settings::get();
|
|
}
|
|
|
|
public function postProcess(): void {
|
|
// Set configuration values
|
|
Settings::set($this->exportValues());
|
|
|
|
parent::postProcess();
|
|
|
|
// Display message
|
|
CRM_Utils_System::setUFMessage(E::ts('Settings saved'));
|
|
}
|
|
|
|
public function validate(): bool {
|
|
parent::validate();
|
|
Settings::validate($this->exportValues(), $this->_errors);
|
|
return (0 == count($this->_errors));
|
|
}
|
|
|
|
/**
|
|
* Get the participant status options.
|
|
*
|
|
* @return array
|
|
*
|
|
* @throws \Civi\API\Exception\UnauthorizedException
|
|
* @throws \CRM_Core_Exception
|
|
*/
|
|
protected static function getParticipantStatusOptions(): array {
|
|
$result = \Civi\Api4\ParticipantStatusType::get()
|
|
->addSelect('id', 'label')
|
|
->addWhere('is_active', '=', TRUE)
|
|
->execute()
|
|
->getArrayCopy();
|
|
return array_column($result, 'label', 'id');
|
|
}
|
|
|
|
/**
|
|
* Get available contact tags.
|
|
*
|
|
* @return array
|
|
*
|
|
* @throws \CRM_Core_Exception
|
|
* @throws \Civi\API\Exception\UnauthorizedException
|
|
*/
|
|
protected static function getContactTags(): array {
|
|
$result = \Civi\Api4\Tag::get()
|
|
->addSelect('id', 'label')
|
|
->addWhere('used_for', '=', 'civicrm_contact')
|
|
->addWhere('is_selectable', '=', TRUE)
|
|
->addWhere('is_tagset', '=', FALSE)
|
|
->execute()
|
|
->getArrayCopy();
|
|
return array_column($result, 'label', 'id');
|
|
}
|
|
}
|