Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
ee17a760 | 29 | * This class provides the functionality to add contact(s) to Household. |
6a488035 | 30 | */ |
ee17a760 | 31 | class CRM_Contact_Form_Task_AddToHousehold extends CRM_Contact_Form_Task_AddToParentClass { |
6a488035 TO |
32 | |
33 | /** | |
fe482240 | 34 | * Build the form object. |
6a488035 | 35 | */ |
00be9182 | 36 | public function buildQuickForm() { |
6a488035 TO |
37 | |
38 | CRM_Utils_System::setTitle(ts('Add Members to Household')); | |
39 | $this->addElement('text', 'name', ts('Find Target Household')); | |
40 | ||
41 | $this->add('select', 'relationship_type_id', ts('Relationship Type'), | |
42 | array( | |
d5cc0fc2 | 43 | '' => ts('- select -'), |
353ffa53 | 44 | ) + |
6a488035 TO |
45 | CRM_Contact_BAO_Relationship::getRelationType("Household"), TRUE |
46 | ); | |
47 | ||
48 | $searchRows = $this->get('searchRows'); | |
49 | $searchCount = $this->get('searchCount'); | |
50 | if ($searchRows) { | |
51 | $checkBoxes = array(); | |
ee17a760 | 52 | $checkFlag = 0; |
6a488035 | 53 | foreach ($searchRows as $id => $row) { |
ee17a760 EM |
54 | if (!$checkFlag) { |
55 | $checkFlag = $id; | |
6a488035 TO |
56 | } |
57 | $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); | |
58 | } | |
59 | $this->addGroup($checkBoxes, 'contact_check'); | |
ee17a760 EM |
60 | if ($checkFlag) { |
61 | $checkBoxes[$checkFlag]->setChecked(TRUE); | |
6a488035 TO |
62 | } |
63 | $this->assign('searchRows', $searchRows); | |
64 | } | |
65 | ||
66 | $this->assign('searchCount', $searchCount); | |
67 | $this->assign('searchDone', $this->get('searchDone')); | |
68 | $this->assign('contact_type_display', ts('Household')); | |
97e557d7 CW |
69 | $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); |
70 | $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); | |
6a488035 TO |
71 | |
72 | $this->addButtons(array( | |
73 | array( | |
74 | 'type' => 'next', | |
75 | 'name' => ts('Add to Household'), | |
76 | 'isDefault' => TRUE, | |
77 | ), | |
78 | array( | |
79 | 'type' => 'cancel', | |
80 | 'name' => ts('Cancel'), | |
81 | ), | |
82 | ) | |
83 | ); | |
84 | } | |
85 | ||
86 | /** | |
fe482240 | 87 | * Process the form after the input has been submitted and validated. |
6a488035 TO |
88 | */ |
89 | public function postProcess() { | |
90 | ||
91 | // store the submitted values in an array | |
ee17a760 | 92 | $this->params = $this->controller->exportValues($this->_name); |
6a488035 TO |
93 | |
94 | $this->set('searchDone', 0); | |
a7488080 | 95 | if (!empty($_POST['_qf_AddToHousehold_refresh'])) { |
6a488035 | 96 | $searchParams['contact_type'] = array('Household' => 'Household'); |
ee17a760 EM |
97 | $searchParams['rel_contact'] = $this->params['name']; |
98 | $this->search($this, $searchParams); | |
6a488035 TO |
99 | $this->set('searchDone', 1); |
100 | return; | |
101 | } | |
102 | ||
ee17a760 | 103 | $this->addRelationships(); |
6a488035 | 104 | } |
96025800 | 105 | |
6a488035 | 106 | } |