Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
5a409b50 | 35 | * Auxiliary class to provide support to the Contact Form class. |
6a488035 | 36 | * |
5a409b50 | 37 | * Does this by implementing a small set of static methods. |
6a488035 TO |
38 | */ |
39 | class CRM_Contact_Form_Edit_Organization { | |
40 | ||
353ffa53 | 41 | /** |
5a409b50 | 42 | * This function provides the HTML form elements that are specific to the Organization Contact Type. |
6a488035 | 43 | * |
77c5b619 TO |
44 | * @param CRM_Core_Form $form |
45 | * Form object. | |
46 | * @param int $inlineEditMode | |
47 | * ( 1 for contact summary. | |
6a488035 | 48 | * top bar form and 2 for display name edit ) |
6a488035 TO |
49 | */ |
50 | public static function buildQuickForm(&$form, $inlineEditMode = NULL) { | |
6a488035 TO |
51 | $form->applyFilter('__ALL__', 'trim'); |
52 | ||
481a74f4 | 53 | if (!$inlineEditMode || $inlineEditMode == 1) { |
6a488035 | 54 | // Organization_name |
4a63142c | 55 | $form->addField('organization_name'); |
6a488035 TO |
56 | } |
57 | ||
481a74f4 | 58 | if (!$inlineEditMode || $inlineEditMode == 2) { |
6a488035 | 59 | // legal_name |
4a63142c | 60 | $form->addField('legal_name'); |
6a488035 TO |
61 | |
62 | // nick_name | |
4a63142c | 63 | $form->addField('nick_name'); |
6a488035 TO |
64 | |
65 | // sic_code | |
4a63142c TM |
66 | $form->addField('sic_code'); |
67 | $form->addField('contact_source'); | |
6a488035 TO |
68 | } |
69 | ||
481a74f4 | 70 | if (!$inlineEditMode) { |
4a63142c | 71 | $form->addField('external_identifier', array('label' => ts('External ID'))); |
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 | ||
86538308 EM |
80 | /** |
81 | * @param $fields | |
82 | * @param $files | |
100fef9d | 83 | * @param int $contactID |
86538308 EM |
84 | * |
85 | * @return array|bool | |
86 | */ | |
00be9182 | 87 | public static function formRule($fields, $files, $contactID = NULL) { |
6a488035 | 88 | $errors = array(); |
d6def514 | 89 | $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Organization'); |
6a488035 TO |
90 | |
91 | // make sure that organization name is set | |
a7488080 | 92 | if (empty($fields['organization_name'])) { |
6a488035 TO |
93 | $errors['organization_name'] = 'Organization Name should be set.'; |
94 | } | |
95 | ||
6a488035 TO |
96 | // add code to make sure that the uniqueness criteria is satisfied |
97 | return empty($errors) ? TRUE : $errors; | |
98 | } | |
96025800 | 99 | |
6a488035 | 100 | } |