Commit 10a0e3de authored by Mathieu Lutfy's avatar Mathieu Lutfy Committed by Aegir user
Browse files

Add support for Organizations and Contact Sub-Types.

parent f32b8e2d
......@@ -17,10 +17,30 @@ class CRM_Activityprofile_APIWrappers_Profile {
// This is a profile with activity fields, but without an activity_id
// Let's create a new contact and a new activity.
// We only do the minimum and let profile.submit do the rest.
$contact = civicrm_api3('Contact', 'create', [
'contact_type' => 'Individual',
'display_name' => 'activityprofile-temp-contact',
]);
$contact_params = [];
$ctype = Civi::settings()->get('activityprofile_' . $profile_id . '_ctype');
$csubtype = Civi::settings()->get('activityprofile_' . $profile_id . '_csubtype');
if ($ctype) {
$contact_params['contact_type'] = 'Organization';
$contact_params['organization_name'] = $apiRequest['params']['organization_name'] ?? 'ActivityProfile TempContact';
}
elseif (!empty($apiRequest['params']['organization_name'])) {
$contact_params['contact_type'] = 'Organization';
$contact_params['organization_name'] = $apiRequest['params']['organization_name'];
}
else {
$contact_params['contact_type'] = 'Individual';
$contact_params['first_name'] = $apiRequest['params']['first_name'] ?? 'ActivityProfile';
$contact_params['last_name'] = $apiRequest['params']['last_name'] ?? 'TempContact';
}
if ($csubtype) {
$contact_params['contact_sub_type'] = $csubtype;
}
$contact = civicrm_api3('Contact', 'create', $contact_params);
// Setting the contact_id is necessary so that we can pass through
// CRM_Profile_Form::validateContactActivityProfile()
......
......@@ -8,6 +8,7 @@ class CRM_Activityprofile_UF_Form_Group {
* @see activityprofile_civicrm_buildForm().
*/
public static function buildForm(&$form) {
// Activity Type
$activity_types = [
'' => E::ts('- none -'),
];
......@@ -18,16 +19,48 @@ class CRM_Activityprofile_UF_Form_Group {
$form->add('select', 'activityprofile_atype', E::ts('Create Activity'), $activity_types, NULL, ['class' => 'crm-select2']);
// Contact Type
$contact_types = [
'' => E::ts('- select -'),
];
$contact_types += civicrm_api3('Contact', 'getoptions', [
'field' => 'contact_type',
])['values'];
$form->add('select', 'activityprofile_ctype', E::ts('Contact Type'), $contact_types, NULL, ['class' => 'crm-select2']);
// Contact SubType
$contact_subtypes = [
'' => E::ts('- none -'),
];
$contact_subtypes += civicrm_api3('Contact', 'getoptions', [
'field' => 'contact_sub_type',
])['values'];
$form->add('select', 'activityprofile_csubtype', E::ts('Contact SubType'), $contact_subtypes, NULL, ['class' => 'crm-select2']);
CRM_Core_Region::instance('page-body')->add([
'template' => 'CRM/Activityprofile/UF/Form/Group-atype.tpl',
]);
// Set default
if ($id = $form->getVar('_id')) {
$defaults = [];
if ($atype = Civi::settings()->get('activityprofile_' . $id . '_atype')) {
$form->setDefaults([
'activityprofile_atype' => $atype,
]);
$defaults['activityprofile_atype'] = $atype;
}
if ($ctype = Civi::settings()->get('activityprofile_' . $id . '_ctype')) {
$defaults['activityprofile_ctype'] = $ctype;
}
if ($csubtype = Civi::settings()->get('activityprofile_' . $id . '_csubtype')) {
$defaults['activityprofile_csubtype'] = $csubtype;
}
if (!empty($defaults)) {
$form->setDefaults($defaults);
}
}
}
......@@ -40,6 +73,8 @@ class CRM_Activityprofile_UF_Form_Group {
$id = $form->getVar('_id');
Civi::settings()->set('activityprofile_' . $id . '_atype', $values['activityprofile_atype']);
Civi::settings()->set('activityprofile_' . $id . '_ctype', $values['activityprofile_ctype']);
Civi::settings()->set('activityprofile_' . $id . '_csubtype', $values['activityprofile_csubtype']);
}
}
<table>
<tr id="activityprofile-atype">
<table id="activityprofile-settings">
<tr>
<td class="label">
<label>{$form.activityprofile_ctype.label}</label>
</td>
<td>
{$form.activityprofile_ctype.html}
<div class="description">{ts}Contact Type of the main contact associated with the profile. If empty, the contact type will be guessed depending on the presence of the Organization Name field.{/ts}</div>
</td>
</tr>
<tr>
<td class="label">
<label>{$form.activityprofile_csubtype.label}</label>
</td>
<td>
{$form.activityprofile_csubtype.html}
<div class="description">{ts}Optional Contact Sub-Type.{/ts}</div>
</td>
</tr>
<tr>
<td class="label">
<label>{$form.activityprofile_atype.label}</label>
</td>
......@@ -12,6 +30,6 @@
{literal}
<script>
CRM.$('tr#activityprofile-atype').appendTo('.crm-uf-advancesetting-form-block > table > tbody');
CRM.$('#activityprofile-settings tr').appendTo('.crm-uf-advancesetting-form-block > table > tbody');
</script>
{/literal}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment