Skip to content

Commit

Permalink
Merge pull request #10609 from totten/master-case-settings
Browse files Browse the repository at this point in the history
CRM-20816 - Expose CiviCase settings through "Settings" framework
  • Loading branch information
colemanw authored Jul 7, 2017
2 parents 286c768 + c8fd28d commit d2447b3
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 15 deletions.
53 changes: 53 additions & 0 deletions CRM/Admin/Form/Setting/Case.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/

/**
* This class generates form components for CiviCase.
*/
class CRM_Admin_Form_Setting_Case extends CRM_Admin_Form_Setting {

protected $_settings = array(
'civicaseRedactActivityEmail' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'civicaseAllowMultipleClients' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'civicaseNaturalActivityTypeSort' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
);

/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Settings - CiviCase'));
parent::buildQuickForm();
}

}
36 changes: 36 additions & 0 deletions CRM/Case/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,40 @@ public static function onToggleComponents($oldValue, $newValue, $metadata) {
}
}

/**
* @return array
* Array(string $value => string $label).
*/
public static function getRedactOptions() {
return array(
'default' => ts('Default'),
'0' => ts('Do not redact emails'),
'1' => ts('Redact emails'),
);
}

/**
* @return array
* Array(string $value => string $label).
*/
public static function getMultiClientOptions() {
return array(
'default' => ts('Default'),
'0' => ts('Single client per case'),
'1' => ts('Multiple client per case'),
);
}

/**
* @return array
* Array(string $value => string $label).
*/
public static function getSortOptions() {
return array(
'default' => ts('Default'),
'0' => ts('Definition order'),
'1' => ts('Alphabetical order'),
);
}

}
29 changes: 20 additions & 9 deletions CRM/Case/XMLProcessor/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,7 @@ public function getListeners($caseType) {
* @return int
*/
public function getRedactActivityEmail() {
$xml = $this->retrieve("Settings");
return ( string ) $xml->RedactActivityEmail ? 1 : 0;
return $this->getBoolSetting('civicaseRedactActivityEmail', 'RedactActivityEmail');
}

/**
Expand All @@ -645,11 +644,7 @@ public function getRedactActivityEmail() {
* 1 if allowed, 0 if not
*/
public function getAllowMultipleCaseClients() {
$xml = $this->retrieve("Settings");
if ($xml) {
return ( string ) $xml->AllowMultipleCaseClients ? 1 : 0;
}
return 0;
return $this->getBoolSetting('civicaseAllowMultipleClients', 'AllowMultipleCaseClients');
}

/**
Expand All @@ -659,8 +654,24 @@ public function getAllowMultipleCaseClients() {
* 1 if natural, 0 if alphabetic
*/
public function getNaturalActivityTypeSort() {
$xml = $this->retrieve("Settings");
return ( string ) $xml->NaturalActivityTypeSort ? 1 : 0;
return $this->getBoolSetting('civicaseNaturalActivityTypeSort', 'NaturalActivityTypeSort');
}

/**
* @param string $settingKey
* @param string $xmlTag
* @param mixed $default
* @return int
*/
private function getBoolSetting($settingKey, $xmlTag, $default = 0) {
$setting = Civi::settings()->get($settingKey);
if ($setting !== 'default') {
return (int) $setting;
}
if ($xml = $this->retrieve("Settings")) {
return (string) $xml->{$xmlTag} ? 1 : 0;
}
return $default;
}

}
8 changes: 8 additions & 0 deletions CRM/Case/xml/Menu/Case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
<title>Case Details</title>
<page_callback>CRM_Case_Page_CaseDetails</page_callback>
</item>
<item>
<path>civicrm/admin/setting/case</path>
<title>CiviCase Settings</title>
<page_callback>CRM_Admin_Form_Setting_Case</page_callback>
<adminGroup>CiviCase</adminGroup>
<icon>admin/small/36.png</icon>
<weight>380</weight>
</item>
<item>
<path>civicrm/admin/options/case_type</path>
<title>Case Types</title>
Expand Down
16 changes: 15 additions & 1 deletion CRM/Case/xml/configuration.sample/Settings.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings>
<!--
DEPRECATED
The settings in this document should be migrated to the conventional settings framework, which allows
a greater variety of configuration-management practices (e.g. web-based config, API access, file overrides).
-->

<!-- List the group whose members should appear as contacts on all Manage Case screens.
Only one group name is supported for now.
It needs to match the name column in the civicrm_group table (not the title), so avoid using space characters. -->
<group name="Case_Resources" />

<!-- Set this to 1 if you want case activity emails to be redacted -->
<RedactActivityEmail>0</RedactActivityEmail>
<!-- SEE ALSO: Setting "civicaseRedactActivityEmail" -->
<RedactActivityEmail>0</RedactActivityEmail>

<!-- Set this to 1 if you want to allow multiple clients to be associated with a single case -->
<!-- SEE ALSO: Setting "civicaseAllowMultipleClients" -->
<AllowMultipleCaseClients>0</AllowMultipleCaseClients>

<!-- Set this to 1 if you want to have activity types on Manage Case
screen sorted in XML file order, default is alphabetical -->
<!-- SEE ALSO: Setting "civicaseNaturalActivityTypeSort" -->
<NaturalActivityTypeSort>0</NaturalActivityTypeSort>

<!-- Add activity types which should NOT be editable here with editable = 0 -->
<ActivityTypes>
<ActivityType>
Expand Down
9 changes: 9 additions & 0 deletions CRM/Upgrade/Incremental/sql/4.7.22.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@

{include file='../CRM/Upgrade/4.7.22.msg_template/civicrm_msg_template.tpl'}

-- CRM-20816: Add CiviCase settings

SELECT @civicaseAdminId := id FROM civicrm_navigation WHERE name = 'CiviCase' AND domain_id = {$domainID};

INSERT INTO civicrm_navigation
(domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight)
VALUES
({$domainID}, 'civicrm/admin/setting/case?reset=1', '{ts escape="sql" skip="true"}CiviCase Settings{/ts}', 'CiviCase Settings', NULL, 'AND', @civicaseAdminId, '1', NULL, 1);

-- CRM-20387
UPDATE `civicrm_contribution` SET `invoice_number` = `invoice_id` WHERE `invoice_id` LIKE CONCAT('%', `id`);
103 changes: 103 additions & 0 deletions settings/Case.setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/

/**
* Settings metadata file
*/
return array(
'civicaseRedactActivityEmail' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'civicaseRedactActivityEmail',
'type' => 'String',
'quick_form_type' => 'Select',
'html_type' => 'Select',
'html_attributes' => array(
//'class' => 'crm-select2',
),
'default' => 'default',
'add' => '4.7',
'title' => 'Redact Activity Email',
'is_domain' => 1,
'is_contact' => 0,
'pseudoconstant' => array(
'callback' => 'CRM_Case_Info::getRedactOptions',
),
'description' => 'Should activity emails be redacted? (Set "Default" to load setting from the legacy "Settings.xml" file.)',
'help_text' => '',
),
'civicaseAllowMultipleClients' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'civicaseAllowMultipleClients',
'type' => 'String',
'quick_form_type' => 'Select',
'html_type' => 'Select',
'html_attributes' => array(
//'class' => 'crm-select2',
),
'default' => 'default',
'add' => '4.7',
'title' => 'Allow Multiple Case Clients',
'is_domain' => 1,
'is_contact' => 0,
'pseudoconstant' => array(
'callback' => 'CRM_Case_Info::getMultiClientOptions',
),
'description' => 'How many clients may be associated with a given case? (Set "Default" to load setting from the legacy "Settings.xml" file.)',
'help_text' => '',
),
'civicaseNaturalActivityTypeSort' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'civicaseNaturalActivityTypeSort',
'type' => 'String',
'quick_form_type' => 'Select',
'html_type' => 'Select',
'html_attributes' => array(
//'class' => 'crm-select2',
),
'default' => 'default',
'add' => '4.7',
'title' => 'Activity Type Sorting',
'is_domain' => 1,
'is_contact' => 0,
'pseudoconstant' => array(
'callback' => 'CRM_Case_Info::getSortOptions',
),
'description' => 'How to sort activity-types on the "Manage Case" screen? (Set "Default" to load setting from the legacy "Settings.xml" file.)',
'help_text' => '',
),
);
2 changes: 1 addition & 1 deletion sql/civicrm_generated.mysql

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions templates/CRM/Admin/Form/Setting/Case.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
<div class="crm-block crm-form-block crm-case-form-block">
{*<div class="help">*}
{*{ts}...{/ts} {docURL page="Debugging for developers" resource="wiki"}*}
{*</div>*}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout">
<tr class="crm-case-form-block-civicaseRedactActivityEmail">
<td class="label">{$form.civicaseRedactActivityEmail.label}</td>
<td>{$form.civicaseRedactActivityEmail.html}<br />
<span class="description">{ts}Should activity emails be redacted?{/ts} {ts}(Set "Default" to load setting from the legacy "Settings.xml" file.){/ts}</span>
</td>
</tr>
<tr class="crm-case-form-block-civicaseAllowMultipleClients">
<td class="label">{$form.civicaseAllowMultipleClients.label}</td>
<td>{$form.civicaseAllowMultipleClients.html}<br />
<span class="description">{ts}How many clients may be associated with a given case?{/ts} {ts}(Set "Default" to load setting from the legacy "Settings.xml" file.){/ts}</span>
</td>
</tr>
<tr class="crm-case-form-block-civicaseNaturalActivityTypeSort">
<td class="label">{$form.civicaseNaturalActivityTypeSort.label}</td>
<td>{$form.civicaseNaturalActivityTypeSort.html}<br />
<span class="description">{ts}How to sort activity-types on the "Manage Case" screen? {/ts} {ts}(Set "Default" to load setting from the legacy "Settings.xml" file.){/ts}</span>
</td>
</tr>
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
<div class="spacer"></div>
</div>
9 changes: 5 additions & 4 deletions xml/templates/civicrm_navigation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,11 @@ SET @adminCaselastID:=LAST_INSERT_ID();
INSERT INTO civicrm_navigation
( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
VALUES
( @domainID, 'civicrm/a/#/caseType', '{ts escape="sql" skip="true"}Case Types{/ts}', 'Case Types', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 1 ),
( @domainID, 'civicrm/admin/options/redaction_rule?reset=1', '{ts escape="sql" skip="true"}Redaction Rules{/ts}', 'Redaction Rules', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 2 ),
( @domainID, 'civicrm/admin/options/case_status?reset=1', '{ts escape="sql" skip="true"}Case Statuses{/ts}', 'Case Statuses', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 3 ),
( @domainID, 'civicrm/admin/options/encounter_medium?reset=1', '{ts escape="sql" skip="true"}Encounter Medium{/ts}', 'Encounter Medium', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 4 );
( @domainID, 'civicrm/admin/setting/case?reset=1', '{ts escape="sql" skip="true"}CiviCase Settings{/ts}', 'CiviCase Settings', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 1 ),
( @domainID, 'civicrm/a/#/caseType', '{ts escape="sql" skip="true"}Case Types{/ts}', 'Case Types', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 2 ),
( @domainID, 'civicrm/admin/options/redaction_rule?reset=1', '{ts escape="sql" skip="true"}Redaction Rules{/ts}', 'Redaction Rules', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 3 ),
( @domainID, 'civicrm/admin/options/case_status?reset=1', '{ts escape="sql" skip="true"}Case Statuses{/ts}', 'Case Statuses', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 4 ),
( @domainID, 'civicrm/admin/options/encounter_medium?reset=1', '{ts escape="sql" skip="true"}Encounter Medium{/ts}', 'Encounter Medium', 'administer CiviCase', NULL, @adminCaselastID, '1', NULL, 5 );

INSERT INTO civicrm_navigation
( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
Expand Down

0 comments on commit d2447b3

Please sign in to comment.