toevoegen instellingen en lidmaatschapsaanvraag
This commit is contained in:
parent
a70e686cba
commit
9f564d8690
|
@ -36,6 +36,7 @@ class CRM_Bij1algemeen_Bij1AlgemeenService {
|
|||
private $_mandaatIdCustomFieldId = NULL;
|
||||
private $_mandaatIdColumnName = NULL;
|
||||
private $_mollieCustomerIdIdentityType = NULL;
|
||||
private $_lidmaatschapsaanvraagTypeId = NULL;
|
||||
|
||||
/**
|
||||
* CRM_Bij1algemeen_Bij1AlgemeenService constructor.
|
||||
|
@ -364,6 +365,20 @@ class CRM_Bij1algemeen_Bij1AlgemeenService {
|
|||
return $this->_mandaatIdCustomFieldId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int
|
||||
*/
|
||||
public function setLidmaatschapsaanvraagTypeId(int $id) {
|
||||
$this->_lidmaatschapsaanvraagTypeId = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getLidmaatschapsaanvraagTypeId() {
|
||||
return $this->_lidmaatschapsaanvraagTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
|
|
|
@ -85,6 +85,106 @@ class CRM_Bij1algemeen_CustomData {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom data for activiteit lidmaatschapsaanvraag
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function getLidmaatschapsaanvraagData() {
|
||||
$keuzeWaarde = new CRM_Bij1algemeen_KeuzeWaarde();
|
||||
return [
|
||||
'lidmaatschapsaanvraag_data' => [
|
||||
'title' => "Lidmaatschapsaanvraag",
|
||||
'extends' => "Activity",
|
||||
'extends_entity_column_value' => $keuzeWaarde->haalLidmaatschapsaanvraagTypeId(),
|
||||
'style' => "Inline",
|
||||
'table_name' => "civicrm_value_lidmaatschapsaanvraag_data",
|
||||
'is_multiple' => FALSE,
|
||||
'custom_field' => [
|
||||
[
|
||||
'name' => "voornaam",
|
||||
'label' => "Voornaam",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "64",
|
||||
'weight' => 10,
|
||||
],
|
||||
[
|
||||
'name' => "achternaam",
|
||||
'label' => "Achternaam",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "64",
|
||||
'weight' => 20,
|
||||
],
|
||||
[
|
||||
'name' => "email",
|
||||
'label' => "E-mailadres",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "255",
|
||||
'weight' => 30,
|
||||
],
|
||||
[
|
||||
'name' => "adres",
|
||||
'label' => "Adres",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "96",
|
||||
'weight' => 40,
|
||||
|
||||
],
|
||||
[
|
||||
'name' => "postcode",
|
||||
'label' => "Postcode",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "12",
|
||||
'weight' => 50,
|
||||
],
|
||||
[
|
||||
'name' => "plaats",
|
||||
'label' => "Plaats",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "64",
|
||||
'weight' => 60,
|
||||
],
|
||||
[
|
||||
'name' => "frequentie",
|
||||
'label' => "Frequentie",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "32",
|
||||
'weight' => 70,
|
||||
],
|
||||
[
|
||||
'name' => "bedrag",
|
||||
'label' => "Bedrag",
|
||||
'data_type' => "Money",
|
||||
'html_type' => "Text",
|
||||
'weight' => 80,
|
||||
],
|
||||
[
|
||||
'name' => "privacy_akkoord",
|
||||
'label' => "Privacy akkoord",
|
||||
'data_type' => "Boolean",
|
||||
'html_type' => "Radio",
|
||||
'weight' => 90,
|
||||
],
|
||||
[
|
||||
'name' => "bank",
|
||||
'label' => "Bank",
|
||||
'data_type' => "String",
|
||||
'html_type' => "Text",
|
||||
'text_length' => "64",
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method om te kijken of de custom group al bestaat
|
||||
*
|
||||
|
@ -123,6 +223,9 @@ class CRM_Bij1algemeen_CustomData {
|
|||
if (isset($customGroupData['extends_entity_column_value'])) {
|
||||
$customGroups->addValue('extends_entity_column_value', $customGroupData['extends_entity_column_value']);
|
||||
}
|
||||
if (isset($customGroupData['weight'])) {
|
||||
$customGroups->addValue('weight', $customGroupData['weight']);
|
||||
}
|
||||
$customGroups->execute();
|
||||
$customGroupId = $this->haalCustomGroupId($customGroupName);
|
||||
if ($customGroupId) {
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
use CRM_Bij1algemeen_ExtensionUtil as E;
|
||||
|
||||
/**
|
||||
* Form voor BIJ1 specifieke instellingen
|
||||
*
|
||||
* @author Erik Hommel (CiviCooP) <erik.hommel@civicoop.org>
|
||||
* @date 4 Jan 2022
|
||||
* @license AGPL-3.0
|
||||
* @see https://docs.civicrm.org/dev/en/latest/framework/quickform/
|
||||
*/
|
||||
class CRM_Bij1algemeen_Form_Instellingen extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Overridden parent method to build form
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
CRM_Utils_System::setTitle(E::ts('BIJ1 Specifieke instellingen'));
|
||||
$this->add('text', 'bij1_basisbedrag', E::ts("Basis bedrag voor standaard lidmaatschap"), [], TRUE);
|
||||
$this->add('text', 'bij1_betalinggemist', E::ts("Aantal keren betaling gemist voor actie"), [], TRUE);
|
||||
$this->addRule('bij1_basisbedrag', E::ts('Moet een bedrag zijn'), 'money');
|
||||
$this->addRule('bij1_betalinggemist', E::ts('Moet een geheel getal zijn'), 'positiveInteger');
|
||||
$this->addButtons([
|
||||
[
|
||||
'type' => 'next',
|
||||
'name' => E::ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
],
|
||||
[
|
||||
'type' => 'cancel',
|
||||
'name' => E::ts('Cancel')
|
||||
],
|
||||
]);
|
||||
// export form elements
|
||||
$this->assign('elementNames', $this->getRenderableElementNames());
|
||||
}
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden parent method to process submitted form
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$values = $this->exportValues();
|
||||
if (isset($values['bij1_basisbedrag'])) {
|
||||
Civi::settings()->set('bij1_basisbedrag', $values['bij1_basisbedrag']);
|
||||
}
|
||||
if (isset($values['bij1_betalinggemist'])) {
|
||||
Civi::settings()->set('bij1_betalinggemist', $values['bij1_betalinggemist']);
|
||||
}
|
||||
}
|
||||
CRM_Core_Session::setStatus(E::ts("BIJ1 Specifieke instellingen opgeslagen"), E::ts("Saved"), "success");
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden parent method to set defaults
|
||||
*
|
||||
* @return array|NULL
|
||||
* @throws API_Exception
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = [];
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$defaults['bij1_basisbedrag'] = Civi::settings()->get('bij1_basisbedrag');
|
||||
$defaults['bij1_betalinggemist'] = Civi::settings()->get('bij1_betalinggemist');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields/elements defined in this form.
|
||||
*
|
||||
* @return array (string)
|
||||
*/
|
||||
public function getRenderableElementNames() {
|
||||
// The _elements list includes some items which should not be
|
||||
// auto-rendered in the loop -- such as "qfKey" and "buttons". These
|
||||
// items don't have labels. We'll identify renderable by filtering on
|
||||
// the 'label'.
|
||||
$elementNames = array();
|
||||
foreach ($this->_elements as $element) {
|
||||
/** @var HTML_QuickForm_Element $element */
|
||||
$label = $element->getLabel();
|
||||
if (!empty($label)) {
|
||||
$elementNames[] = $element->getName();
|
||||
}
|
||||
}
|
||||
return $elementNames;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
use CRM_Bij1migratie_ExtensionUtil as E;
|
||||
|
||||
/**
|
||||
* Keuzewaarden (option values) aanmaken als ze nog niet bestaan
|
||||
*
|
||||
* @author Erik Hommel(CiviCooP) <erik.hommel@civicoop.org>
|
||||
* @license AGPL-3.0
|
||||
*/
|
||||
class CRM_Bij1algemeen_KeuzeWaarde {
|
||||
|
||||
/**
|
||||
* Method om option value aan te maken
|
||||
* @param array $waardeData
|
||||
*/
|
||||
public function maak(array $waardeData) {
|
||||
if (!empty($waardeData) && isset($waardeData['option_group_id:name']) && !empty($waardeData['option_group_id:name'])) {
|
||||
if (!isset($waardeData['label'])) {
|
||||
$delen = explode("_", $waardeData['name']);
|
||||
foreach ($delen as $deelKey => $deel) {
|
||||
$delen[$deelKey] = ucfirst(strtolower($deel));
|
||||
}
|
||||
$waardeData['label'] = implode(" ", $delen);
|
||||
}
|
||||
try {
|
||||
$optionValue = \Civi\Api4\OptionValue::create()
|
||||
->addValue('option_group_id:name', $waardeData['option_group_id:name'])
|
||||
->addValue('name', $waardeData['name'])
|
||||
->addValue('label', $waardeData['label'])
|
||||
->addValue('is_active', TRUE)
|
||||
->addValue('is_reserved', TRUE);
|
||||
if (isset($waardeData['description']) && !empty($waardeData['description'])) {
|
||||
$optionValue->addValue('description', $waardeData['description']);
|
||||
}
|
||||
$optionValue->execute();
|
||||
}
|
||||
catch (API_Exception $ex) {
|
||||
Civi::log()->error("Kon geen keuzewaarde aanmaken met data: " . json_encode($waardeData) . ", foutboodschap van API4 OptionValue create: " . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method om te checken of de keuzewaarde al bestaat
|
||||
*
|
||||
* @param string $optionGroupNaam
|
||||
* @param string $optionValueNaam
|
||||
* @return bool
|
||||
*/
|
||||
public function bestaat(string $optionGroupNaam, string $optionValueNaam) {
|
||||
if (!empty($optionGroupNaam) && !empty($optionValueNaam)) {
|
||||
try {
|
||||
$optionValues = \Civi\Api4\OptionValue::get()
|
||||
->addSelect('COUNT(*) AS count')
|
||||
->addWhere('option_group_id:name', '=', $optionGroupNaam)
|
||||
->addWhere('name', '=', $optionValueNaam)
|
||||
->execute();
|
||||
foreach ($optionValues as $optionValue) {
|
||||
if ($optionValue['count'] > 0) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (API_Exception $ex) {
|
||||
Civi::log()->error("Kon geen keuzewaarde zoeken met option group naam " . $optionGroupNaam . " en option value naam"
|
||||
. $optionValueNaam . " in " . __METHOD__ . ", foutboodschap van API4 OptionValue get: " . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method om lidmaatschapsaanvraag activity type id op te halen
|
||||
* (eenmalig omdat tijdens de install de service het type nog niet kent)
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function haalLidmaatschapsaanvraagTypeId() {
|
||||
$query = "SELECT cov.value
|
||||
FROM civicrm_option_group AS cog JOIN civicrm_option_value AS cov ON cog.id = cov.option_group_id
|
||||
WHERE cog.name = %1 AND cov.name = %2 LIMIT 1";
|
||||
$activityTypeId = \CRM_Core_DAO::singleValueQuery($query, [
|
||||
1 => ["activity_type", "String"],
|
||||
2 => ["lidmaatschapsaanvraag", "String"],
|
||||
]);
|
||||
if ($activityTypeId) {
|
||||
return $activityTypeId;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method om de data voor lidmaatschapsaanvraag op te nemen
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLidmaatschapsaanvraagData() {
|
||||
return [
|
||||
'option_group_id:name' => 'activity_type',
|
||||
'name' => 'lidmaatschapsaanvraag',
|
||||
'label' => 'Lidmaatschapsaanvraag',
|
||||
'description' => "Activiteitstype voor een aanvraag van lidmaatschap met specifieke gegevens van de aanvraag"
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -13,14 +13,19 @@ class CRM_Bij1algemeen_Upgrader extends CRM_Bij1algemeen_Upgrader_Base {
|
|||
* Eigen velden en groepen voor Bij1 genereren bij install
|
||||
*/
|
||||
public function install() {
|
||||
$keuzeWaarde = new CRM_Bij1algemeen_KeuzeWaarde();
|
||||
$keuzeWaarde->maak($keuzeWaarde->getLidmaatschapsaanvraagData());
|
||||
$customData = new CRM_Bij1algemeen_CustomData();
|
||||
$customData->maak($customData->getAirtableData());
|
||||
$customData->maak($customData->getMollieBetalingData());
|
||||
$customData->maak($customData->getLidmaatschapsaanvraagData());
|
||||
$groep = new CRM_Bij1algemeen_Groep();
|
||||
$groep->maakLedenGroepen();
|
||||
$identity = new CRM_Bij1algemeen_IdentityTracker();
|
||||
$identity->setIsReserved();
|
||||
$identity->maakMollieCustomerIdType();
|
||||
Civi::settings()->set('bij1_basisbedrag', 30);
|
||||
Civi::settings()->set('bij1_betalinggemist', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,6 +92,34 @@ class CRM_Bij1algemeen_Upgrader extends CRM_Bij1algemeen_Upgrader_Base {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade 1040: add lidmaatschapsaanvraag activity type en custom data
|
||||
*
|
||||
* @return TRUE on success
|
||||
* @throws Exception
|
||||
*/
|
||||
public function upgrade_1040() {
|
||||
$this->ctx->log->info('Applying update 1040 - add lidmaatschapsaanvraag activity type en custom data');
|
||||
$keuzeWaarde = new CRM_Bij1algemeen_KeuzeWaarde();
|
||||
$keuzeWaarde->maak($keuzeWaarde->getLidmaatschapsaanvraagData());
|
||||
$customData = new CRM_Bij1algemeen_CustomData();
|
||||
$customData->maak($customData->getLidmaatschapsaanvraagData());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade 1050: bij1 specifieke instellingen
|
||||
*
|
||||
* @return TRUE on success
|
||||
* @throws Exception
|
||||
*/
|
||||
public function upgrade_1050() {
|
||||
$this->ctx->log->info('Applying update 1050 - bij1 specifieke instellingen');
|
||||
Civi::settings()->set('bij1_basisbedrag', 30);
|
||||
Civi::settings()->set('bij1_betalinggemist', 3);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Work with entities usually not available during the install step.
|
||||
*
|
||||
|
|
|
@ -24,10 +24,28 @@ class Bij1AlgemeenContainer implements CompilerPassInterface {
|
|||
$this->setGroups($definition);
|
||||
$this->setBankAccountReference($definition);
|
||||
$this->setCustomData($definition);
|
||||
$this->setActivityTypeIds($definition);
|
||||
$definition->setPublic(TRUE);
|
||||
$container->setDefinition('bij1Algemeen', $definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method om activity type ids te zetten
|
||||
* @param $definition
|
||||
*/
|
||||
private function setActivityTypeIds(&$definition) {
|
||||
$query = "SELECT cov.value
|
||||
FROM civicrm_option_group AS cog JOIN civicrm_option_value AS cov ON cog.id = cov.option_group_id
|
||||
WHERE cog.name = %1 AND cov.name = %2 LIMIT 1";
|
||||
$activityTypeId = \CRM_Core_DAO::singleValueQuery($query, [
|
||||
1 => ["activity_type", "String"],
|
||||
2 => ["lidmaatschapsaanvraag", "String"],
|
||||
]);
|
||||
if ($activityTypeId) {
|
||||
$definition->addMethodCall('setLidmaatschapsaanvraagTypeId', [(int) $activityTypeId]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method om custom data in te stellen
|
||||
* @param $definition
|
||||
|
|
|
@ -16,6 +16,24 @@ use \Symfony\Component\DependencyInjection\Definition;
|
|||
function bij1algemeen_civicrm_container(ContainerBuilder $container) {
|
||||
$container->addCompilerPass(new Civi\Bij1algemeen\Bij1AlgemeenContainer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_civicrm_navigationMenu().
|
||||
*
|
||||
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
|
||||
*/
|
||||
function bij1algemeen_civicrm_navigationMenu(&$menu) {
|
||||
_bij1algemeen_civix_insert_navigation_menu($menu, 'Administer', array(
|
||||
'label' => E::ts('BIJ1 Specifieke Instellingen'),
|
||||
'name' => 'bij1_instellingen',
|
||||
'url' => CRM_Utils_System::url('civicrm/bij1algemeen/form/instellingen', 'reset=1&action=update', TRUE),
|
||||
'permission' => 'administer CiviCRM',
|
||||
'operator' => 'OR',
|
||||
'separator' => 0,
|
||||
));
|
||||
_bij1algemeen_civix_navigationMenu($menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_civicrm_config().
|
||||
*
|
||||
|
|
4
info.xml
4
info.xml
|
@ -14,8 +14,8 @@
|
|||
<url desc="Support">https://civicoop.org</url>
|
||||
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
|
||||
</urls>
|
||||
<releaseDate>2021-12-09</releaseDate>
|
||||
<version>1.0</version>
|
||||
<releaseDate>2022-01-04</releaseDate>
|
||||
<version>1.1</version>
|
||||
<develStage>beta</develStage>
|
||||
<compatibility>
|
||||
<ver>5.0</ver>
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{* HEADER *}
|
||||
|
||||
<div class="crm-submit-buttons">
|
||||
{include file="CRM/common/formButtons.tpl" location="top"}
|
||||
</div>
|
||||
|
||||
{* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *}
|
||||
|
||||
{foreach from=$elementNames item=elementName}
|
||||
<div class="crm-section">
|
||||
<div class="label">{$form.$elementName.label}</div>
|
||||
<div class="content">{$form.$elementName.html}</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
{/foreach}
|
||||
|
||||
{* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
|
||||
|
||||
<div>
|
||||
<span>{$form.favorite_color.label}</span>
|
||||
<span>{$form.favorite_color.html}</span>
|
||||
</div>
|
||||
|
||||
{* FOOTER *}
|
||||
<div class="crm-submit-buttons">
|
||||
{include file="CRM/common/formButtons.tpl" location="bottom"}
|
||||
</div>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<menu>
|
||||
<item>
|
||||
<path>civicrm/bij1algemeen/form/instellingen</path>
|
||||
<page_callback>CRM_Bij1algemeen_Form_Instellingen</page_callback>
|
||||
<title>Instellingen</title>
|
||||
<access_arguments>access CiviCRM</access_arguments>
|
||||
</item>
|
||||
</menu>
|
Loading…
Reference in New Issue