Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
b44e3f84 | 37 | * Auxiliary class to provide support to the Contact Form class. Does this by implementing |
6a488035 TO |
38 | * a small set of static methods |
39 | * | |
40 | */ | |
41 | class CRM_Contact_Form_Edit_Organization { | |
42 | ||
353ffa53 | 43 | /** |
6a488035 TO |
44 | * This function provides the HTML form elements that are specific |
45 | * to the Organization Contact Type | |
46 | * | |
77c5b619 TO |
47 | * @param CRM_Core_Form $form |
48 | * Form object. | |
49 | * @param int $inlineEditMode | |
50 | * ( 1 for contact summary. | |
6a488035 TO |
51 | * top bar form and 2 for display name edit ) |
52 | * | |
6a488035 TO |
53 | * @return void |
54 | */ | |
55 | public static function buildQuickForm(&$form, $inlineEditMode = NULL) { | |
56 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); | |
57 | ||
58 | $form->applyFilter('__ALL__', 'trim'); | |
59 | ||
481a74f4 | 60 | if (!$inlineEditMode || $inlineEditMode == 1) { |
6a488035 TO |
61 | // Organization_name |
62 | $form->add('text', 'organization_name', ts('Organization Name'), $attributes['organization_name']); | |
63 | } | |
64 | ||
481a74f4 | 65 | if (!$inlineEditMode || $inlineEditMode == 2) { |
6a488035 TO |
66 | // legal_name |
67 | $form->addElement('text', 'legal_name', ts('Legal Name'), $attributes['legal_name']); | |
68 | ||
69 | // nick_name | |
70 | $form->addElement('text', 'nick_name', ts('Nickname'), | |
71 | CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name') | |
72 | ); | |
73 | ||
74 | // sic_code | |
75 | $form->addElement('text', 'sic_code', ts('SIC Code'), $attributes['sic_code']); | |
76 | ||
77 | $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes)); | |
78 | } | |
79 | ||
481a74f4 | 80 | if (!$inlineEditMode) { |
7b99ead3 | 81 | $form->add('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE); |
6a488035 TO |
82 | $form->addRule('external_identifier', |
83 | ts('External ID already exists in Database.'), | |
84 | 'objectExists', | |
85 | array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier') | |
86 | ); | |
87 | } | |
88 | } | |
89 | ||
86538308 EM |
90 | /** |
91 | * @param $fields | |
92 | * @param $files | |
100fef9d | 93 | * @param int $contactID |
86538308 EM |
94 | * |
95 | * @return array|bool | |
96 | */ | |
00be9182 | 97 | public static function formRule($fields, $files, $contactID = NULL) { |
6a488035 TO |
98 | $errors = array(); |
99 | $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID); | |
100 | ||
101 | // make sure that organization name is set | |
a7488080 | 102 | if (empty($fields['organization_name'])) { |
6a488035 TO |
103 | $errors['organization_name'] = 'Organization Name should be set.'; |
104 | } | |
105 | ||
106 | //check for duplicate - dedupe rules | |
107 | CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Organization'); | |
108 | ||
109 | // add code to make sure that the uniqueness criteria is satisfied | |
110 | return empty($errors) ? TRUE : $errors; | |
111 | } | |
96025800 | 112 | |
6a488035 | 113 | } |