more comment fixes
[civicrm-core.git] / CRM / Contact / Form / Location.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 class CRM_Contact_Form_Location {
34
35 /**
36 * Set variables up before form is built.
37 *
38 * @param CRM_Core_Form $form
39 */
40 public static function preProcess(&$form) {
41 $form->_addBlockName = CRM_Utils_Request::retrieve('block', 'String', CRM_Core_DAO::$_nullObject);
42 $additionalblockCount = CRM_Utils_Request::retrieve('count', 'Positive', CRM_Core_DAO::$_nullObject);
43
44 $form->assign('addBlock', FALSE);
45 if ($form->_addBlockName && $additionalblockCount) {
46 $form->assign('addBlock', TRUE);
47 $form->assign('blockName', $form->_addBlockName);
48 $form->assign('blockId', $additionalblockCount);
49 $form->set($form->_addBlockName . '_Block_Count', $additionalblockCount);
50 }
51
52 if (is_a($form, 'CRM_Event_Form_ManageEvent_Location')
53 || is_a($form, 'CRM_Contact_Form_Domain')) {
54 $form->_blocks = array(
55 'Address' => ts('Address'),
56 'Email' => ts('Email'),
57 'Phone' => ts('Phone'),
58 );
59 }
60
61 $form->assign('blocks', $form->_blocks);
62 $form->assign('className', CRM_Utils_System::getClassName($form));
63
64 // get address sequence.
65 if (!$addressSequence = $form->get('addressSequence')) {
66 $addressSequence = CRM_Core_BAO_Address::addressSequence();
67 $form->set('addressSequence', $addressSequence);
68 }
69 $form->assign('addressSequence', $addressSequence);
70 }
71
72 /**
73 * Build the form object.
74 *
75 * @param CRM_Core_Form $form
76 */
77 public static function buildQuickForm(&$form) {
78 // required for subsequent AJAX requests.
79 $ajaxRequestBlocks = array();
80 $generateAjaxRequest = 0;
81
82 //build 1 instance of all blocks, without using ajax ...
83 foreach ($form->_blocks as $blockName => $label) {
84 require_once str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_Form_Edit_' . $blockName) . '.php';
85 $name = strtolower($blockName);
86
87 $instances = array(1);
88 if (!empty($_POST[$name]) && is_array($_POST[$name])) {
89 $instances = array_keys($_POST[$name]);
90 }
91 elseif (property_exists($form, '_values') && !empty($form->_values[$name]) && is_array($form->_values[$name])) {
92 $instances = array_keys($form->_values[$name]);
93 }
94
95 foreach ($instances as $instance) {
96 if ($instance == 1) {
97 $form->assign('addBlock', FALSE);
98 $form->assign('blockId', $instance);
99 }
100 else {
101 //we are going to build other block instances w/ AJAX
102 $generateAjaxRequest++;
103 $ajaxRequestBlocks[$blockName][$instance] = TRUE;
104 }
105
106 $form->set($blockName . '_Block_Count', $instance);
107 $formName = 'CRM_Contact_Form_Edit_' . $blockName;
108 $formName::buildQuickForm($form);
109 }
110 }
111
112 //assign to generate AJAX request for building extra blocks.
113 $form->assign('generateAjaxRequest', $generateAjaxRequest);
114 $form->assign('ajaxRequestBlocks', $ajaxRequestBlocks);
115 }
116
117 }