4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
36 class CRM_Report_Form_Contact_CurrentEmployer
extends CRM_Report_Form
{
38 protected $_summary = NULL;
40 protected $_customGroupExtends = array(
41 'Contact', 'Individual');
43 public $_drilldownReport = array('contact/detail' => 'Link to Detail Report');
51 function __construct() {
53 $this->_columns
= array(
56 'dao' => 'CRM_Contact_DAO_Contact',
59 'organization_name' =>
60 array('title' => ts('Employer Name'),
72 'organization_name' =>
73 array('title' => ts('Employer Name'),
74 'operatorType' => CRM_Report_Form
::OP_STRING
,
80 'dao' => 'CRM_Contact_DAO_Contact',
84 array('title' => ts('Employee Name'),
87 'first_name' => array('title' => ts('First Name'),
89 'last_name' => array('title' => ts('Last Name'),
92 array('title' => ts('Job Title'),
96 array('title' => ts('Gender'),
100 'no_display' => TRUE,
105 'title' => ts('Contact Type'),
107 'contact_sub_type' =>
109 'title' => ts('Contact SubType'),
115 array('title' => ts('Employee Name')),
117 array('no_display' => TRUE),
119 'grouping' => 'contact-fields',
121 'civicrm_relationship' =>
123 'dao' => 'CRM_Contact_DAO_Relationship',
127 array('title' => ts('Employee Since'),
134 array('title' => ts('Employee Since'),
135 'operatorType' => CRM_Report_Form
::OP_DATE
,
136 'type' => CRM_Utils_Type
::T_DATE
,
142 'dao' => 'CRM_Core_DAO_Email',
143 'grouping' => 'contact-fields',
147 array('title' => ts('Email'),
154 'dao' => 'CRM_Core_DAO_Address',
155 'grouping' => 'contact-fields',
158 'street_address' => NULL,
160 'postal_code' => NULL,
161 'state_province_id' =>
162 array('title' => ts('State/Province'),
165 array('title' => ts('Country'),
171 array('title' => ts('Country'),
172 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
173 'options' => CRM_Core_PseudoConstant
::country(NULL, FALSE),
175 'state_province_id' =>
176 array('title' => ts('State/Province'),
177 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
178 'options' => CRM_Core_PseudoConstant
::stateProvince(),
184 'dao' => 'CRM_Contact_DAO_Group',
190 'name' => 'group_id',
191 'title' => ts('Group'),
193 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
194 'options' => CRM_Core_PseudoConstant
::staticGroup(),
200 $this->_tagFilter
= TRUE;
201 parent
::__construct();
204 function preProcess() {
205 parent
::preProcess();
210 $select = $this->_columnHeaders
= array();
212 foreach ($this->_columns
as $tableName => $table) {
213 if (array_key_exists('fields', $table)) {
214 foreach ($table['fields'] as $fieldName => $field) {
215 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
217 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
218 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
219 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
225 $this->_select
= "SELECT " . implode(', ', $select) . " ";
230 FROM civicrm_contact {$this->_aliases['civicrm_contact']}
232 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']}
233 ON {$this->_aliases['civicrm_employer']}.id={$this->_aliases['civicrm_contact']}.employer_id
236 LEFT JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']}
237 ON ( {$this->_aliases['civicrm_relationship']}.contact_id_a={$this->_aliases['civicrm_contact']}.id
238 AND {$this->_aliases['civicrm_relationship']}.contact_id_b={$this->_aliases['civicrm_contact']}.employer_id
239 AND {$this->_aliases['civicrm_relationship']}.relationship_type_id=4)
240 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
241 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id
242 AND {$this->_aliases['civicrm_address']}.is_primary = 1 )
244 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
245 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
246 AND {$this->_aliases['civicrm_email']}.is_primary = 1) ";
252 foreach ($this->_columns
as $tableName => $table) {
253 if (array_key_exists('filters', $table)) {
254 foreach ($table['filters'] as $fieldName => $field) {
256 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
) {
257 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
258 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
259 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
261 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
264 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
266 $clause = $this->whereClause($field,
268 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
269 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
270 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
275 if (!empty($clause)) {
276 $clauses[$fieldName] = $clause;
282 if (empty($clauses)) {
283 $this->_where
= "WHERE {$this->_aliases['civicrm_contact']}.employer_id!='null' ";
286 $this->_where
= "WHERE ({$this->_aliases['civicrm_contact']}.employer_id!='null') AND " . implode(' AND ', $clauses);
289 if ($this->_aclWhere
) {
290 $this->_where
.= " AND {$this->_aclWhere} ";
295 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_employer']}.id,{$this->_aliases['civicrm_contact']}.id";
299 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_employer']}.organization_name, {$this->_aliases['civicrm_contact']}.display_name";
302 function postProcess() {
303 // get the acl clauses built before we assemble the query
304 $this->buildACLClause(array($this->_aliases
['civicrm_contact'], $this->_aliases
['civicrm_employer']));
305 parent
::postProcess();
311 function alterDisplay(&$rows) {
312 // custom code to alter rows
313 $checkList = array();
316 foreach ($rows as $rowNum => $row) {
318 // convert employer name to links
319 if (array_key_exists('civicrm_employer_organization_name', $row) &&
320 array_key_exists('civicrm_employer_id', $row)
322 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
323 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_employer_id'],
324 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
326 $rows[$rowNum]['civicrm_employer_organization_name_link'] = $url;
330 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
331 // not repeat contact display names if it matches with the one
334 foreach ($row as $colName => $colVal) {
335 if (!empty($checkList[$colName]) && is_array($checkList[$colName]) &&
336 in_array($colVal, $checkList[$colName])
338 $rows[$rowNum][$colName] = "";
340 if (in_array($colName, $this->_noRepeats
)) {
341 $checkList[$colName][] = $colVal;
347 if (array_key_exists('civicrm_contact_gender_id', $row)) {
348 if ($value = $row['civicrm_contact_gender_id']) {
349 $gender = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id');
350 $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
355 // convert employee name to links
356 if (array_key_exists('civicrm_contact_display_name', $row) &&
357 array_key_exists('civicrm_contact_id', $row)
359 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
360 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
361 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
363 $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
368 if (array_key_exists('civicrm_address_country_id', $row)) {
369 if ($value = $row['civicrm_address_country_id']) {
370 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
375 if (array_key_exists('civicrm_address_state_province_id', $row)) {
376 if ($value = $row['civicrm_address_state_province_id']) {
377 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
382 // skip looking further in rows, if first row itself doesn't
383 // have the column we need