Skip to content

Commit

Permalink
-- CRM-12809 civicrm#1, civicrm#2 and civicrm#3
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-12809: Reserved CustomGroups
  http://issues.civicrm.org/jira/browse/CRM-12809
  • Loading branch information
Ravish Nair committed Jun 14, 2013
1 parent 5319181 commit d06700a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CRM/Custom/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
3 changes: 3 additions & 0 deletions CRM/Custom/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions CRM/Custom/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions CRM/Custom/Page/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion CRM/Custom/Page/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions CRM/Custom/Page/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
( @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?';
7 changes: 7 additions & 0 deletions xml/schema/Core/CustomGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@
<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>


0 comments on commit d06700a

Please sign in to comment.