From d06700a7b7744e24225024bd1b0ffacc43ef993c Mon Sep 17 00:00:00 2001 From: Ravish Nair Date: Fri, 14 Jun 2013 18:31:53 +0530 Subject: [PATCH] -- CRM-12809 #1, #2 and #3 ---------------------------------------- * CRM-12809: Reserved CustomGroups http://issues.civicrm.org/jira/browse/CRM-12809 --- CRM/Custom/Form/Field.php | 4 ++++ CRM/Custom/Form/Group.php | 3 +++ CRM/Custom/Form/Option.php | 4 ++++ CRM/Custom/Page/Field.php | 5 +++++ CRM/Custom/Page/Group.php | 2 +- CRM/Custom/Page/Option.php | 4 ++++ CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl | 6 +++++- xml/schema/Core/CustomGroup.xml | 7 +++++++ 8 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index b61baf4e05a2..0f7f5cde9843 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -106,6 +106,10 @@ public function preProcess() { //custom group id $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); + if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) { + CRM_Core_Error::fatal("You cannot add or edit fields of a Reserved Custom Group"); + } + if ($this->_gid) { $url = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}" diff --git a/CRM/Custom/Form/Group.php b/CRM/Custom/Form/Group.php index 08ffd1d121ba..486ef5a4d413 100644 --- a/CRM/Custom/Form/Group.php +++ b/CRM/Custom/Form/Group.php @@ -82,6 +82,9 @@ public function preProcess() { // current set id $this->_id = $this->get('id'); + if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id')) { + CRM_Core_Error::fatal("You cannot edit the settings of a Reserved Custom Group"); + } // setting title for html page if ($this->_action == CRM_Core_Action::UPDATE) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); diff --git a/CRM/Custom/Form/Option.php b/CRM/Custom/Form/Option.php index 3d159429e5b5..3a1da1d396f7 100644 --- a/CRM/Custom/Form/Option.php +++ b/CRM/Custom/Form/Option.php @@ -79,6 +79,10 @@ public function preProcess() { $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this); $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); + + if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) { + CRM_Core_Error::fatal("You cannot add or edit muliple choice options of a Reserved Custom Group Field"); + } if (!isset($this->_gid) && $this->_fid) { $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $this->_fid, diff --git a/CRM/Custom/Page/Field.php b/CRM/Custom/Page/Field.php index 72d0e05baf22..8030604c2c56 100644 --- a/CRM/Custom/Page/Field.php +++ b/CRM/Custom/Page/Field.php @@ -231,6 +231,11 @@ function run() { $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this ); + + if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) { + CRM_Core_Error::fatal("You cannot add or edit fields of a Reserved Custom Group"); + } + $action = CRM_Utils_Request::retrieve('action', 'String', // default to 'browse' $this, FALSE, 'browse' diff --git a/CRM/Custom/Page/Group.php b/CRM/Custom/Page/Group.php index 6c5c7712e44f..15a68c644c78 100644 --- a/CRM/Custom/Page/Group.php +++ b/CRM/Custom/Page/Group.php @@ -208,7 +208,7 @@ function browse($action = NULL) { // get all custom groups sorted by weight $customGroup = array(); $dao = new CRM_Core_DAO_CustomGroup(); - + $dao->is_reserved = FALSE; $dao->orderBy('weight, title'); $dao->find(); diff --git a/CRM/Custom/Page/Option.php b/CRM/Custom/Page/Option.php index 2816336e6ff5..2ae8574f94b4 100644 --- a/CRM/Custom/Page/Option.php +++ b/CRM/Custom/Page/Option.php @@ -278,6 +278,10 @@ function run() { $this, FALSE, 0 ); + if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) { + CRM_Core_Error::fatal("You cannot add or edit muliple choice options of a Reserved Custom Group Field"); + } + //as url contain $gid so append breadcrumb dynamically. $breadcrumb = array(array('title' => ts('Custom Data Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&gid=' . $this->_gid), diff --git a/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl index 1a3c5ea63d7f..e178d5a1f914 100644 --- a/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl @@ -64,4 +64,8 @@ INSERT INTO civicrm_uf_field ( uf_group_id, field_name, is_required, is_reserved, weight, visibility, in_selector, is_searchable, location_type_id, {localize field='label'}label{/localize}, field_type, help_post, phone_type_id ) VALUES ( @uf_group_contribution_batch_entry, 'soft_credit', 0, 0, 10, 'User and User Admin Only', 0, 0, NULL, {localize}'Soft Credit'{/localize}, 'Contribution', NULL, NULL ), - ( @uf_group_membership_batch_entry, 'soft_credit', 0, 0, 13, 'User and User Admin Only', 0, 0, NULL, {localize}'Soft Credit'{/localize}, 'Membership', NULL, NULL ); \ No newline at end of file + ( @uf_group_membership_batch_entry, 'soft_credit', 0, 0, 13, 'User and User Admin Only', 0, 0, NULL, {localize}'Soft Credit'{/localize}, 'Membership', NULL, NULL ); + +-- CRM-12809 +ALTER TABLE `civicrm_custom_group` + ADD COLUMN `is_reserved` tinyint(4) DEFAULT '0' COMMENT 'Is this a reserved Custom Group?'; diff --git a/xml/schema/Core/CustomGroup.xml b/xml/schema/Core/CustomGroup.xml index 26e6c0425c7e..517a1adc61fa 100644 --- a/xml/schema/Core/CustomGroup.xml +++ b/xml/schema/Core/CustomGroup.xml @@ -179,6 +179,13 @@ Date and time this custom group was created. 3.0 + + is_reserved + boolean + 0 + Is this a reserved Custom Group? + 4.4 +