comment fixes
[civicrm-core.git] / CRM / Contact / Form / Edit / Household.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33
34 /**
35 * Auxiliary class to provide support to the Contact Form class.
36 *
37 * Does this by implementing a small set of static methods.
38 */
39 class CRM_Contact_Form_Edit_Household {
40
41 /**
42 * This function provides the HTML form elements that are specific to the Household Contact Type.
43 *
44 * @param CRM_Core_Form $form
45 * Form object.
46 * @param int $inlineEditMode
47 * ( 1 for contact summary.
48 * top bar form and 2 for display name edit )
49 */
50 public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
51 $form->applyFilter('__ALL__', 'trim');
52
53 if (!$inlineEditMode || $inlineEditMode == 1) {
54 // household_name
55 $form->addField('household_name');
56 }
57
58 if (!$inlineEditMode || $inlineEditMode == 2) {
59 // nick_name
60 $form->addField('nick_name');
61 $form->addField('contact_source', array('label' => ts('Source')));
62 }
63
64 if (!$inlineEditMode) {
65 $form->addField('external_identifier', array('label' => ts('External ID')));
66 $form->addRule('external_identifier',
67 ts('External ID already exists in Database.'),
68 'objectExists',
69 array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
70 );
71 }
72 }
73
74 /**
75 * Add rule for household.
76 *
77 * @param array $fields
78 * Array of form values.
79 * @param array $files
80 * Unused.
81 * @param int $contactID
82 *
83 * @return array|bool
84 * $error
85 */
86 public static function formRule($fields, $files, $contactID = NULL) {
87 $errors = array();
88 $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
89
90 // make sure that household name is set
91 if (empty($fields['household_name'])) {
92 $errors['household_name'] = 'Household Name should be set.';
93 }
94
95 //check for duplicate - dedupe rules
96 CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
97
98 return empty($errors) ? TRUE : $errors;
99 }
100
101 }