Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Report_Form_Walklist_Walklist extends CRM_Report_Form { | |
6a488035 TO |
18 | |
19 | protected $_summary = NULL; | |
20 | ||
be2fb01f | 21 | public $_drilldownReport = ['contact/detail' => 'Link to Detail Report']; |
6a488035 | 22 | |
be2fb01f | 23 | protected $_customGroupExtends = [ |
9d72cede EM |
24 | 'Contact', |
25 | 'Individual', | |
26 | 'Household', | |
21dfd5f5 | 27 | 'Organization', |
be2fb01f | 28 | ]; |
430ae6dd | 29 | |
74cf4551 | 30 | /** |
73b448bf | 31 | * Class constructor. |
74cf4551 | 32 | */ |
00be9182 | 33 | public function __construct() { |
be2fb01f CW |
34 | $this->_columns = [ |
35 | 'civicrm_contact' => [ | |
6a488035 | 36 | 'dao' => 'CRM_Contact_DAO_Contact', |
be2fb01f CW |
37 | 'fields' => [ |
38 | 'id' => [ | |
9d72cede | 39 | 'title' => ts('Contact ID'), |
6a488035 TO |
40 | 'no_display' => TRUE, |
41 | 'required' => TRUE, | |
be2fb01f CW |
42 | ], |
43 | 'sort_name' => [ | |
9d72cede | 44 | 'title' => ts('Contact Name'), |
6a488035 TO |
45 | 'required' => TRUE, |
46 | 'no_repeat' => TRUE, | |
be2fb01f CW |
47 | ], |
48 | ], | |
49 | 'filters' => [ | |
50 | 'sort_name' => [ | |
9d72cede | 51 | 'title' => ts('Contact Name'), |
6a488035 | 52 | 'operator' => 'like', |
be2fb01f CW |
53 | ], |
54 | ], | |
6a488035 | 55 | 'grouping' => 'contact-fields', |
be2fb01f CW |
56 | 'order_bys' => [ |
57 | 'sort_name' => [ | |
9d72cede | 58 | 'title' => ts('Contact Name'), |
6a488035 | 59 | 'required' => TRUE, |
be2fb01f CW |
60 | ], |
61 | ], | |
62 | ], | |
63 | 'civicrm_email' => [ | |
6a488035 | 64 | 'dao' => 'CRM_Core_DAO_Email', |
be2fb01f | 65 | 'fields' => ['email' => ['default' => TRUE]], |
6a488035 | 66 | 'grouping' => 'location-fields', |
be2fb01f CW |
67 | ], |
68 | 'civicrm_phone' => [ | |
6a488035 | 69 | 'dao' => 'CRM_Core_DAO_Phone', |
be2fb01f | 70 | 'fields' => ['phone' => NULL], |
6a488035 | 71 | 'grouping' => 'location-fields', |
be2fb01f CW |
72 | ], |
73 | ] + $this->getAddressColumns(['group_bys' => FALSE]); | |
6a488035 TO |
74 | parent::__construct(); |
75 | } | |
76 | ||
00be9182 | 77 | public function preProcess() { |
6a488035 TO |
78 | parent::preProcess(); |
79 | } | |
80 | ||
00be9182 | 81 | public function select() { |
cd2426ba | 82 | // @todo remove this function & use parent. |
be2fb01f | 83 | $select = []; |
6a488035 | 84 | |
be2fb01f | 85 | $this->_columnHeaders = []; |
6a488035 TO |
86 | foreach ($this->_columns as $tableName => $table) { |
87 | foreach ($table['fields'] as $fieldName => $field) { | |
9d72cede EM |
88 | if (!empty($field['required']) || |
89 | !empty($this->_params['fields'][$fieldName]) | |
90 | ) { | |
6a488035 TO |
91 | |
92 | $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; | |
93 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title']; | |
94 | $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = $field['type']; | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | $this->_select = "SELECT " . implode(",\n", $select) . " "; | |
100 | } | |
101 | ||
00be9182 | 102 | public function from() { |
6a488035 TO |
103 | $this->_from = NULL; |
104 | ||
105 | $this->_from = " | |
106 | FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} | |
107 | "; | |
6a488035 | 108 | |
cd2426ba | 109 | $this->joinAddressFromContact(); |
110 | $this->joinPhoneFromContact(); | |
111 | $this->joinEmailFromContact(); | |
6a488035 TO |
112 | } |
113 | ||
00be9182 | 114 | public function where() { |
be2fb01f | 115 | $clauses = []; |
6a488035 TO |
116 | foreach ($this->_columns as $tableName => $table) { |
117 | if (array_key_exists('filters', $table)) { | |
118 | foreach ($table['filters'] as $fieldName => $field) { | |
119 | $clause = NULL; | |
120 | ||
121 | if ($field['type'] & CRM_Utils_Type::T_DATE) { | |
9c1bc317 CW |
122 | $relative = $this->_params["{$fieldName}_relative"] ?? NULL; |
123 | $from = $this->_params["{$fieldName}_from"] ?? NULL; | |
124 | $to = $this->_params["{$fieldName}_to"] ?? NULL; | |
6a488035 TO |
125 | |
126 | $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); | |
127 | } | |
128 | else { | |
9c1bc317 | 129 | $op = $this->_params["{$fieldName}_op"] ?? NULL; |
6a488035 TO |
130 | if ($op) { |
131 | $clause = $this->whereClause($field, | |
132 | $op, | |
133 | CRM_Utils_Array::value("{$fieldName}_value", $this->_params), | |
134 | CRM_Utils_Array::value("{$fieldName}_min", $this->_params), | |
135 | CRM_Utils_Array::value("{$fieldName}_max", $this->_params) | |
136 | ); | |
137 | } | |
138 | } | |
139 | ||
140 | if (!empty($clause)) { | |
141 | $clauses[] = $clause; | |
142 | } | |
143 | } | |
144 | } | |
145 | } | |
146 | ||
147 | if (empty($clauses)) { | |
148 | $this->_where = "WHERE ( 1 ) "; | |
149 | } | |
150 | else { | |
151 | $this->_where = "WHERE " . implode(' AND ', $clauses); | |
152 | } | |
153 | ||
154 | if ($this->_aclWhere) { | |
155 | $this->_where .= " AND {$this->_aclWhere} "; | |
156 | } | |
157 | } | |
158 | ||
00be9182 | 159 | public function postProcess() { |
6a488035 TO |
160 | // get the acl clauses built before we assemble the query |
161 | $this->buildACLClause($this->_aliases['civicrm_contact']); | |
162 | parent::postProcess(); | |
163 | } | |
164 | ||
74cf4551 | 165 | /** |
ced9bfed EM |
166 | * Alter display of rows. |
167 | * | |
168 | * Iterate through the rows retrieved via SQL and make changes for display purposes, | |
169 | * such as rendering contacts as links. | |
170 | * | |
171 | * @param array $rows | |
172 | * Rows generated by SQL, with an array for each row. | |
74cf4551 | 173 | */ |
00be9182 | 174 | public function alterDisplay(&$rows) { |
6a488035 TO |
175 | $entryFound = FALSE; |
176 | foreach ($rows as $rowNum => $row) { | |
6a488035 TO |
177 | // convert display name to links |
178 | if (array_key_exists('civicrm_contact_sort_name', $row) && | |
179 | array_key_exists('civicrm_contact_id', $row) | |
180 | ) { | |
181 | $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', | |
182 | 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], | |
183 | $this->_absoluteUrl, $this->_id, $this->_drilldownReport | |
184 | ); | |
185 | $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; | |
186 | $entryFound = TRUE; | |
187 | } | |
188 | ||
96d30001 | 189 | $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, NULL, NULL) ? TRUE : $entryFound; |
190 | ||
6a488035 TO |
191 | // skip looking further in rows, if first row itself doesn't |
192 | // have the column we need | |
193 | if (!$entryFound) { | |
194 | break; | |
195 | } | |
196 | } | |
197 | } | |
96025800 | 198 | |
6a488035 | 199 | } |