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 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
5a409b50 | 35 | * Form helper class for contact name section. |
6a488035 TO |
36 | */ |
37 | class CRM_Contact_Form_Inline_ContactName extends CRM_Contact_Form_Inline { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Build the form object elements. |
6a488035 TO |
41 | */ |
42 | public function buildQuickForm() { | |
43 | parent::buildQuickForm(); | |
44 | ||
45 | // Build contact type specific fields | |
46 | $class = 'CRM_Contact_Form_Edit_' . $this->_contactType; | |
47 | $class::buildQuickForm($this, 1); | |
ed645ef9 CW |
48 | $this->addFormRule(array('CRM_Contact_Form_Inline_ContactName', 'formRule'), $this); |
49 | } | |
50 | ||
51 | /** | |
52 | * Global validation rules for the form. | |
53 | * | |
54 | * @param array $fields | |
55 | * Posted values of the form. | |
56 | * @param array $errors | |
57 | * List of errors to be posted back to the form. | |
58 | * @param CRM_Contact_Form_Inline_ContactName $form | |
59 | * | |
60 | * @return array | |
61 | */ | |
62 | public static function formRule($fields, $errors, $form) { | |
63 | if (empty($fields['first_name']) && empty($fields['last_name']) | |
64 | && empty($fields['organization_name']) | |
65 | && empty($fields['household_name'])) { | |
66 | $emails = civicrm_api3('Email', 'getcount', array('contact_id' => $form->_contactId)); | |
67 | if (!$emails) { | |
68 | $errorField = $form->_contactType == 'Individual' ? 'last' : strtolower($form->_contactType); | |
69 | $errors[$errorField . '_name'] = ts('Contact with no email must have a name.'); | |
70 | } | |
71 | } | |
72 | return $errors; | |
6a488035 TO |
73 | } |
74 | ||
75 | /** | |
fe482240 | 76 | * Process the form. |
6a488035 TO |
77 | */ |
78 | public function postProcess() { | |
79 | $params = $this->exportValues(); | |
80 | ||
81 | // Process / save contact info | |
82 | $params['contact_type'] = $this->_contactType; | |
353ffa53 | 83 | $params['contact_id'] = $this->_contactId; |
6a488035 TO |
84 | |
85 | if (!empty($this->_contactSubType)) { | |
86 | $params['contact_sub_type'] = $this->_contactSubType; | |
87 | } | |
88 | ||
89 | CRM_Contact_BAO_Contact::create($params); | |
90 | ||
91 | $this->response(); | |
92 | } | |
96025800 | 93 | |
6a488035 | 94 | } |