3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_Report_Form_Walklist_Walklist
extends CRM_Report_Form
{
36 protected $_addressField = FALSE;
38 protected $_emailField = FALSE;
40 protected $_phoneField = FALSE;
42 protected $_summary = NULL;
44 public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
46 protected $_customGroupExtends = array(
57 public function __construct() {
58 $this->_columns
= array(
59 'civicrm_contact' => array(
60 'dao' => 'CRM_Contact_DAO_Contact',
63 'title' => ts('Contact ID'),
68 'title' => ts('Contact Name'),
75 'title' => ts('Contact Name'),
79 'grouping' => 'contact-fields',
82 'title' => ts('Contact Name'),
87 'civicrm_address' => array(
88 'dao' => 'CRM_Core_DAO_Address',
90 'street_number' => array(
91 'title' => ts('Street Number'),
94 'street_address' => NULL,
96 'postal_code' => NULL,
97 'state_province_id' => array(
98 'title' => ts('State/Province'),
101 'country_id' => array(
102 'title' => ts('Country'),
106 'street_number' => array(
107 'title' => ts('Street Number'),
109 'name' => 'street_number',
111 'street_address' => NULL,
114 'grouping' => 'location-fields',
116 'civicrm_email' => array(
117 'dao' => 'CRM_Core_DAO_Email',
118 'fields' => array('email' => array('default' => TRUE)),
119 'grouping' => 'location-fields',
121 'civicrm_phone' => array(
122 'dao' => 'CRM_Core_DAO_Phone',
123 'fields' => array('phone' => NULL),
124 'grouping' => 'location-fields',
127 parent
::__construct();
130 public function preProcess() {
131 parent
::preProcess();
134 public function select() {
137 $this->_columnHeaders
= array();
138 foreach ($this->_columns
as $tableName => $table) {
139 foreach ($table['fields'] as $fieldName => $field) {
140 if (!empty($field['required']) ||
141 !empty($this->_params
['fields'][$fieldName])
143 if ($tableName == 'civicrm_address') {
144 $this->_addressField
= TRUE;
146 elseif ($tableName == 'civicrm_email') {
147 $this->_emailField
= TRUE;
149 elseif ($tableName == 'civicrm_phone') {
150 $this->_phoneField
= TRUE;
153 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
154 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = $field['title'];
155 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = $field['type'];
160 $this->_select
= "SELECT " . implode(",\n", $select) . " ";
163 public function from() {
167 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
169 if ($this->_addressField
) {
170 $this->_from
.= "LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
173 if ($this->_emailField
) {
174 $this->_from
.= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
177 if ($this->_phoneField
) {
178 $this->_from
.= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
182 public function where() {
184 foreach ($this->_columns
as $tableName => $table) {
185 if (array_key_exists('filters', $table)) {
186 foreach ($table['filters'] as $fieldName => $field) {
189 if ($field['type'] & CRM_Utils_Type
::T_DATE
) {
190 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
191 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
192 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
194 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
197 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
199 $clause = $this->whereClause($field,
201 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
202 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
203 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
208 if (!empty($clause)) {
209 $clauses[] = $clause;
215 if (empty($clauses)) {
216 $this->_where
= "WHERE ( 1 ) ";
219 $this->_where
= "WHERE " . implode(' AND ', $clauses);
222 if ($this->_aclWhere
) {
223 $this->_where
.= " AND {$this->_aclWhere} ";
227 public function orderBy() {
228 $this->_orderBy
= "";
229 foreach ($this->_columns
as $tableName => $table) {
230 if (array_key_exists('order_bys', $table)) {
231 foreach ($table['order_bys'] as $fieldName => $field) {
232 $this->_orderBy
[] = $field['dbAlias'];
236 $this->_orderBy
= "ORDER BY " . implode(', ', $this->_orderBy
) . " ";
239 public function postProcess() {
240 // get the acl clauses built before we assemble the query
241 $this->buildACLClause($this->_aliases
['civicrm_contact']);
242 parent
::postProcess();
246 * Alter display of rows.
248 * Iterate through the rows retrieved via SQL and make changes for display purposes,
249 * such as rendering contacts as links.
252 * Rows generated by SQL, with an array for each row.
254 public function alterDisplay(&$rows) {
256 foreach ($rows as $rowNum => $row) {
257 // handle state province
258 if (array_key_exists('civicrm_address_state_province_id', $row)) {
259 if ($value = $row['civicrm_address_state_province_id']) {
260 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value);
266 if (array_key_exists('civicrm_address_country_id', $row)) {
267 if ($value = $row['civicrm_address_country_id']) {
268 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value);
273 // convert display name to links
274 if (array_key_exists('civicrm_contact_sort_name', $row) &&
275 array_key_exists('civicrm_contact_id', $row)
277 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
278 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
279 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
281 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
285 // skip looking further in rows, if first row itself doesn't
286 // have the column we need