3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class generates form components for Relationship Type.
37 class CRM_Admin_Form_RelationshipType
extends CRM_Admin_Form
{
40 * Build the form object.
42 public function buildQuickForm() {
43 parent
::buildQuickForm();
44 $this->setPageTitle(ts('Relationship Type'));
46 if ($this->_action
& CRM_Core_Action
::DELETE
) {
50 $this->applyFilter('__ALL__', 'trim');
52 $this->add('text', 'label_a_b', ts('Relationship Label-A to B'),
53 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_a_b'), TRUE
55 $this->addRule('label_a_b', ts('Label already exists in Database.'),
56 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id
, 'label_a_b')
59 $this->add('text', 'label_b_a', ts('Relationship Label-B to A'),
60 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_b_a')
63 $this->addRule('label_b_a', ts('Label already exists in Database.'),
64 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id
, 'label_b_a')
67 $this->add('text', 'description', ts('Description'),
68 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_RelationshipType', 'description')
71 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, TRUE, '__');
73 // add select for contact type
74 $contactTypeA = &$this->add('select', 'contact_types_a', ts('Contact Type A') . ' ',
76 '' => ts('All Contacts'),
79 $contactTypeB = &$this->add('select', 'contact_types_b', ts('Contact Type B') . ' ',
81 '' => ts('All Contacts'),
85 $isActive = &$this->add('checkbox', 'is_active', ts('Enabled?'));
87 //only selected field should be allow for edit, CRM-4888
89 CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_RelationshipType', $this->_id
, 'is_reserved')
91 foreach (array('contactTypeA', 'contactTypeB', 'isActive') as $field) {
96 if ($this->_action
& CRM_Core_Action
::VIEW
) {
100 $this->assign('relationship_type_id', $this->_id
);
107 public function setDefaultValues() {
108 if ($this->_action
!= CRM_Core_Action
::DELETE
&&
111 $defaults = $params = array();
112 $params = array('id' => $this->_id
);
113 $baoName = $this->_BAOName
;
114 $baoName::retrieve($params, $defaults);
115 $defaults['contact_types_a'] = CRM_Utils_Array
::value('contact_type_a', $defaults);
116 if (!empty($defaults['contact_sub_type_a'])) {
117 $defaults['contact_types_a'] .= '__' . $defaults['contact_sub_type_a'];
120 $defaults['contact_types_b'] = CRM_Utils_Array
::value('contact_type_b', $defaults);
121 if (!empty($defaults['contact_sub_type_b'])) {
122 $defaults['contact_types_b'] .= '__' . $defaults['contact_sub_type_b'];
127 return parent
::setDefaultValues();
132 * Process the form submission.
134 public function postProcess() {
135 if ($this->_action
& CRM_Core_Action
::DELETE
) {
136 CRM_Contact_BAO_RelationshipType
::del($this->_id
);
137 CRM_Core_Session
::setStatus(ts('Selected Relationship type has been deleted.'), ts('Record Deleted'), 'success');
142 // store the submitted values in an array
143 $params = $this->exportValues();
144 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
146 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
147 $ids['relationshipType'] = $this->_id
;
150 $cTypeA = CRM_Utils_System
::explode('__',
151 $params['contact_types_a'],
154 $cTypeB = CRM_Utils_System
::explode('__',
155 $params['contact_types_b'],
159 $params['contact_type_a'] = $cTypeA[0];
160 $params['contact_type_b'] = $cTypeB[0];
162 $params['contact_sub_type_a'] = $cTypeA[1] ?
$cTypeA[1] : 'NULL';
163 $params['contact_sub_type_b'] = $cTypeB[1] ?
$cTypeB[1] : 'NULL';
165 $result = CRM_Contact_BAO_RelationshipType
::add($params, $ids);
167 $this->ajaxResponse
['relationshipType'] = $result->toArray();
169 CRM_Core_Session
::setStatus(ts('The Relationship Type has been saved.'), ts('Saved'), 'success');