3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class generates form components for Relationship Type
40 class CRM_Admin_Form_RelationshipType
extends CRM_Admin_Form
{
43 * Function to build the form
48 public function buildQuickForm() {
49 parent
::buildQuickForm();
50 $this->setPageTitle(ts('Relationship Type'));
52 if ($this->_action
& CRM_Core_Action
::DELETE
) {
56 $this->applyFilter('__ALL__', 'trim');
58 $this->add('text', 'label_a_b', ts('Relationship Label-A to B'),
59 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_a_b'), TRUE
61 $this->addRule('label_a_b', ts('Label already exists in Database.'),
62 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id
, 'label_a_b')
65 $this->add('text', 'label_b_a', ts('Relationship Label-B to A'),
66 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_RelationshipType', 'label_b_a')
69 $this->addRule('label_b_a', ts('Label already exists in Database.'),
70 'objectExists', array('CRM_Contact_DAO_RelationshipType', $this->_id
, 'label_b_a')
73 $this->add('text', 'description', ts('Description'),
74 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_RelationshipType', 'description')
77 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, TRUE, '__');
79 // add select for contact type
80 $contactTypeA = &$this->add('select', 'contact_types_a', ts('Contact Type A') . ' ',
82 '' => ts('All Contacts')) +
$contactTypes
84 $contactTypeB = &$this->add('select', 'contact_types_b', ts('Contact Type B') . ' ',
86 '' => ts('All Contacts')) +
$contactTypes
89 $isActive = &$this->add('checkbox', 'is_active', ts('Enabled?'));
91 //only selected field should be allow for edit, CRM-4888
93 CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_RelationshipType', $this->_id
, 'is_reserved')
95 foreach (array('contactTypeA', 'contactTypeB', 'isActive') as $field)$
$field->freeze();
98 if ($this->_action
& CRM_Core_Action
::VIEW
) {
106 function setDefaultValues() {
107 if ($this->_action
!= CRM_Core_Action
::DELETE
&&
110 $defaults = $params = array();
111 $params = array('id' => $this->_id
);
112 $baoName = $this->_BAOName
;
113 $baoName::retrieve($params, $defaults);
114 $defaults['contact_types_a'] = CRM_Utils_Array
::value('contact_type_a', $defaults);
115 if (!empty($defaults['contact_sub_type_a'])) {
116 $defaults['contact_types_a'] .= '__' . $defaults['contact_sub_type_a'];
119 $defaults['contact_types_b'] = $defaults['contact_type_b'];
120 if (!empty($defaults['contact_sub_type_b'])) {
121 $defaults['contact_types_b'] .= '__' . $defaults['contact_sub_type_b'];
126 return parent
::setDefaultValues();
131 * Function to process the form
137 public function postProcess() {
138 if ($this->_action
& CRM_Core_Action
::DELETE
) {
139 CRM_Contact_BAO_RelationshipType
::del($this->_id
);
140 CRM_Core_Session
::setStatus(ts('Selected Relationship type has been deleted.'), ts('Record Deleted'), 'success');
146 // store the submitted values in an array
147 $params = $this->exportValues();
148 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
150 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
151 $ids['relationshipType'] = $this->_id
;
154 $cTypeA = CRM_Utils_System
::explode('__',
155 $params['contact_types_a'],
158 $cTypeB = CRM_Utils_System
::explode('__',
159 $params['contact_types_b'],
163 $params['contact_type_a'] = $cTypeA[0];
164 $params['contact_type_b'] = $cTypeB[0];
166 $params['contact_sub_type_a'] = $cTypeA[1] ?
$cTypeA[1] : 'NULL';
167 $params['contact_sub_type_b'] = $cTypeB[1] ?
$cTypeB[1] : 'NULL';
169 CRM_Contact_BAO_RelationshipType
::add($params, $ids);
171 CRM_Core_Session
::setStatus(ts('The Relationship Type has been saved.'), ts('Saved'), 'success');