-- CRM-12809 #1, #2 and #3
authorRavish Nair <ravish.nair@webaccess.co.in>
Fri, 14 Jun 2013 13:01:53 +0000 (18:31 +0530)
committerRavish Nair <ravish.nair@webaccess.co.in>
Fri, 14 Jun 2013 13:01:53 +0000 (18:31 +0530)
----------------------------------------
* CRM-12809: Reserved CustomGroups
  http://issues.civicrm.org/jira/browse/CRM-12809

CRM/Custom/Form/Field.php
CRM/Custom/Form/Group.php
CRM/Custom/Form/Option.php
CRM/Custom/Page/Field.php
CRM/Custom/Page/Group.php
CRM/Custom/Page/Option.php
CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl
xml/schema/Core/CustomGroup.xml

index b61baf4e05a27054cf014c079bea22b832dff34d..0f7f5cde9843e8b18b29dd6911c587fc0ecaa9ec 100644 (file)
@@ -106,6 +106,10 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
     //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}"
index 08ffd1d121ba857f3ce660fdb4d8b3fc1d638e2a..486ef5a4d4131e9d6a5e8890a622379a5d463725 100644 (file)
@@ -82,6 +82,9 @@ class CRM_Custom_Form_Group extends CRM_Core_Form {
     // 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);
index 3d159429e5b567e58afcaca992562c6df10a4009..3a1da1d396f76f610874193f8c339f5547e7e477 100644 (file)
@@ -79,6 +79,10 @@ class CRM_Custom_Form_Option extends CRM_Core_Form {
     $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,
index 72d0e05baf226d8d99d94a5aee1ff6411a8c48c6..8030604c2c568d6cbb95e96b9c1d08bef1dafb16 100644 (file)
@@ -231,6 +231,11 @@ class CRM_Custom_Page_Field extends CRM_Core_Page {
     $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'
index 6c5c7712e44f66ea0594d77942be4b1e189d205f..15a68c644c7884e08bcefabea747e37c76a240c6 100644 (file)
@@ -208,7 +208,7 @@ class CRM_Custom_Page_Group extends CRM_Core_Page {
     // 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();
 
index 2816336e6ff50ae4e67f36b954ba89973fefb6b0..2ae8574f94b4af73cb6dccab5087cf6ffe0a826f 100644 (file)
@@ -278,6 +278,10 @@ ORDER BY weight, label
       $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),
index 1a3c5ea63d7f8a8b235c85ebfeb15f05a839a88d..e178d5a1f914a264293d12757e3c9d86ea17b7ec 100644 (file)
@@ -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?';
index 26e6c0425c7e370a5ea1849038c2c723e7d2e95e..517a1adc61fa411d3d7616d70897683c96e6e3f8 100644 (file)
     <comment>Date and time this custom group was created.</comment>
     <add>3.0</add>
   </field>
+  <field>  
+    <name>is_reserved</name>
+    <type>boolean</type>
+    <default>0</default>
+    <comment>Is this a reserved Custom Group?</comment>
+    <add>4.4</add>  
+  </field> 
 </table>