Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-11-14-11-21-50
[civicrm-core.git] / CRM / Contact / Form / Edit / Household.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Auxilary class to provide support to the Contact Form class. Does this by implementing
38 * a small set of static methods
39 *
40 */
41class CRM_Contact_Form_Edit_Household {
42
43 /**
44 * This function provides the HTML form elements that are specific
45 * to the Household Contact Type
46 *
47 * @param object $form form object
48 * @param int $inlineEditMode ( 1 for contact summary
49 * top bar form and 2 for display name edit )
50 *
51 * @access public
52 * @return void
53 */
54 public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
55 $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
56
57 $form->applyFilter('__ALL__', 'trim');
58
59 if ( !$inlineEditMode || $inlineEditMode == 1 ) {
60 // household_name
61 $form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']);
62 }
63
64 if ( !$inlineEditMode || $inlineEditMode == 2 ) {
65 // nick_name
66 $form->addElement('text', 'nick_name', ts('Nickname'), $attributes['nick_name']);
67 $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
68 }
69
70 if ( !$inlineEditMode ) {
7b99ead3 71 $form->add('text', 'external_identifier', ts('External ID'), $attributes['external_identifier'], FALSE);
6a488035
TO
72 $form->addRule('external_identifier',
73 ts('External ID already exists in Database.'),
74 'objectExists',
75 array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')
76 );
77 }
78 }
79
80 /**
81 * add rule for household
82 *
83 * @params array $fields array of form values
84 *
77b97be7
EM
85 * @param $fields
86 * @param $files
87 * @param null $contactID
88 *
89 * @return array|bool $error@static
6a488035
TO
90 * @public
91 */
92 static function formRule($fields, $files, $contactID = NULL) {
93 $errors = array();
94 $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
95
96 // make sure that household name is set
a7488080 97 if (empty($fields['household_name'])) {
6a488035
TO
98 $errors['household_name'] = 'Household Name should be set.';
99 }
100
101 //check for duplicate - dedupe rules
102 CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
103
104 return empty($errors) ? TRUE : $errors;
105 }
106}
107