Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20816 - Expose CiviCase settings through "Settings" framework #10609

Merged
merged 9 commits into from
Jul 7, 2017
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,
'civicaseAllowMultipleCaseClients' => 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(
'auto' => ts('Auto'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think "Auto" will make sense to a user here? I've seen the help text in the template and settings/Case.setting.php file. I'm not so familiar with the context, but just thought something like "default" would be more standard here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we could call it "Magic", and it would make just as much sense. ;)

But... yes, "Default" does feel a bit more standard. Updating.

'0' => ts('Do not redact emails'),
'1' => ts('Redact emails'),
);
}

/**
* @return array
* Array(string $value => string $label).
*/
public static function getMultiClientOptions() {
return array(
'auto' => ts('Auto'),
'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(
'auto' => ts('Auto'),
'0' => ts('Definition order'),
'1' => ts('Alphabetical order'),
);
}

}
12 changes: 12 additions & 0 deletions CRM/Case/XMLProcessor/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ public function getListeners($caseType) {
* @return int
*/
public function getRedactActivityEmail() {
$setting = Civi::settings()->get('civicaseRedactActivityEmail');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for these three method is the same, I wonder would a private function be helpful to remove the duplication?

Copy link
Member Author

@totten totten Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, sometimes a little duplication is better. It seems like a placing a bet for where you think it'll go.

In this case... the functions are not quite identical. One guards explicitly against the condition where $xml is unavailable, and the others don't. This situation feels like a mistake -- the guard seems sensible for all three. Which is the kind of problem you'd expect from too much duplication... so I agree on consolidating...

if ($setting !== 'auto') {
return (int) $setting;
}
$xml = $this->retrieve("Settings");
return ( string ) $xml->RedactActivityEmail ? 1 : 0;
}
Expand All @@ -645,6 +649,10 @@ public function getRedactActivityEmail() {
* 1 if allowed, 0 if not
*/
public function getAllowMultipleCaseClients() {
$setting = Civi::settings()->get('civicaseAllowMultipleCaseClients');
if ($setting !== 'auto') {
return (int) $setting;
}
$xml = $this->retrieve("Settings");
if ($xml) {
return ( string ) $xml->AllowMultipleCaseClients ? 1 : 0;
Expand All @@ -659,6 +667,10 @@ public function getAllowMultipleCaseClients() {
* 1 if natural, 0 if alphabetic
*/
public function getNaturalActivityTypeSort() {
$setting = Civi::settings()->get('civicaseNaturalActivityTypeSort');
if ($setting !== 'auto') {
return (int) $setting;
}
$xml = $this->retrieve("Settings");
return ( string ) $xml->NaturalActivityTypeSort ? 1 : 0;
}
Expand Down
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 "civicaseAllowMultipleCaseClients" -->
<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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totten should you also update the weight of the other case navigation items?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I wondered about that and tested -- as you might expect/hope, the two items with weight==1 float to the top next to each other. The current code seems to work.

Going the other way, it didn't seem like a good idea to manually set the weight of each of the other items -- because they could have been manually rearranged/supplemented/removed, and changing them seemed edgy.

But on second thought... if it really matters... I guess this particular situation could be addressed by incrementing all the weights. Ex:

UPDATE civicrm_navigation 
SET weight = weight+1 
WHERE domain_id = {$domainID} AND parent_id = @civicaseAdminId;

INSERT INTO civicrm_navigation ...;


-- 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' => 'auto',
'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 "Auto" to load setting from the legacy "Settings.xml" file.)',
'help_text' => '',
),
'civicaseAllowMultipleCaseClients' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'civicaseAllowMultipleCaseClients',
'type' => 'String',
'quick_form_type' => 'Select',
'html_type' => 'Select',
'html_attributes' => array(
//'class' => 'crm-select2',
),
'default' => 'auto',
'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 "Auto" 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' => 'auto',
'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 "Auto" 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 "Auto" to load setting from the legacy "Settings.xml" file.){/ts}</span>
</td>
</tr>
<tr class="crm-case-form-block-civicaseAllowMultipleCaseClients">
<td class="label">{$form.civicaseAllowMultipleCaseClients.label}</td>
<td>{$form.civicaseAllowMultipleCaseClients.html}<br />
<span class="description">{ts}How many clients may be associated with a given case?{/ts} {ts}(Set "Auto" 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 "Auto" 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