4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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');
45 function __construct() {
47 $this->_columns
= array(
50 'dao' => 'CRM_Contact_DAO_Contact',
53 'organization_name' =>
54 array('title' => ts('Employer Name'),
66 'organization_name' =>
67 array('title' => ts('Employer Name'),
68 'operatorType' => CRM_Report_Form
::OP_STRING
,
74 'dao' => 'CRM_Contact_DAO_Contact',
78 array('title' => ts('Employee Name'),
81 'first_name' => array('title' => ts('First Name'),
83 'last_name' => array('title' => ts('Last Name'),
86 array('title' => ts('Job Title'),
90 array('title' => ts('Gender'),
101 array('title' => ts('Employee Name')),
103 array('no_display' => TRUE),
105 'grouping' => 'contact-fields',
107 'civicrm_relationship' =>
109 'dao' => 'CRM_Contact_DAO_Relationship',
113 array('title' => ts('Employee Since'),
120 array('title' => ts('Employee Since'),
121 'operatorType' => CRM_Report_Form
::OP_DATE
,
122 'type' => CRM_Utils_Type
::T_DATE
,
128 'dao' => 'CRM_Core_DAO_Email',
129 'grouping' => 'contact-fields',
133 array('title' => ts('Email'),
140 'dao' => 'CRM_Core_DAO_Address',
141 'grouping' => 'contact-fields',
144 'street_address' => NULL,
146 'postal_code' => NULL,
147 'state_province_id' =>
148 array('title' => ts('State/Province'),
151 array('title' => ts('Country'),
157 array('title' => ts('Country'),
158 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
159 'options' => CRM_Core_PseudoConstant
::country(NULL, FALSE),
161 'state_province_id' =>
162 array('title' => ts('State/Province'),
163 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
164 'options' => CRM_Core_PseudoConstant
::stateProvince(),
170 'dao' => 'CRM_Contact_DAO_Group',
176 'name' => 'group_id',
177 'title' => ts('Group'),
179 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
180 'options' => CRM_Core_PseudoConstant
::staticGroup(),
186 $this->_tagFilter
= TRUE;
187 parent
::__construct();
190 function preProcess() {
191 parent
::preProcess();
196 $select = $this->_columnHeaders
= array();
198 foreach ($this->_columns
as $tableName => $table) {
199 if (array_key_exists('fields', $table)) {
200 foreach ($table['fields'] as $fieldName => $field) {
201 if (CRM_Utils_Array
::value('required', $field) ||
202 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
205 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
206 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
207 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
213 $this->_select
= "SELECT " . implode(', ', $select) . " ";
218 FROM civicrm_contact {$this->_aliases['civicrm_contact']}
220 LEFT JOIN civicrm_contact {$this->_aliases['civicrm_employer']}
221 ON {$this->_aliases['civicrm_employer']}.id={$this->_aliases['civicrm_contact']}.employer_id
224 LEFT JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']}
225 ON ( {$this->_aliases['civicrm_relationship']}.contact_id_a={$this->_aliases['civicrm_contact']}.id
226 AND {$this->_aliases['civicrm_relationship']}.contact_id_b={$this->_aliases['civicrm_contact']}.employer_id
227 AND {$this->_aliases['civicrm_relationship']}.relationship_type_id=4)
228 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
229 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id
230 AND {$this->_aliases['civicrm_address']}.is_primary = 1 )
232 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
233 ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id
234 AND {$this->_aliases['civicrm_email']}.is_primary = 1) ";
240 foreach ($this->_columns
as $tableName => $table) {
241 if (array_key_exists('filters', $table)) {
242 foreach ($table['filters'] as $fieldName => $field) {
244 if (CRM_Utils_Array
::value('operatorType', $field) & CRM_Report_Form
::OP_DATE
) {
245 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
246 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
247 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
249 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
252 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
254 $clause = $this->whereClause($field,
256 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
257 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
258 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
263 if (!empty($clause)) {
264 $clauses[$fieldName] = $clause;
270 if (empty($clauses)) {
271 $this->_where
= "WHERE {$this->_aliases['civicrm_contact']}.employer_id!='null' ";
274 $this->_where
= "WHERE ({$this->_aliases['civicrm_contact']}.employer_id!='null') AND " . implode(' AND ', $clauses);
277 if ($this->_aclWhere
) {
278 $this->_where
.= " AND {$this->_aclWhere} ";
283 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_employer']}.id,{$this->_aliases['civicrm_contact']}.id";
287 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_employer']}.organization_name, {$this->_aliases['civicrm_contact']}.display_name";
290 function postProcess() {
291 // get the acl clauses built before we assemble the query
292 $this->buildACLClause(array($this->_aliases
['civicrm_contact'], $this->_aliases
['civicrm_employer']));
293 parent
::postProcess();
296 function alterDisplay(&$rows) {
297 // custom code to alter rows
298 $checkList = array();
301 foreach ($rows as $rowNum => $row) {
303 // convert employer name to links
304 if (array_key_exists('civicrm_employer_organization_name', $row) &&
305 array_key_exists('civicrm_employer_id', $row)
307 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
308 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_employer_id'],
309 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
311 $rows[$rowNum]['civicrm_employer_organization_name_link'] = $url;
315 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
316 // not repeat contact display names if it matches with the one
319 foreach ($row as $colName => $colVal) {
320 if (CRM_Utils_Array
::value($colName, $checkList) && is_array($checkList[$colName]) &&
321 in_array($colVal, $checkList[$colName])
323 $rows[$rowNum][$colName] = "";
325 if (in_array($colName, $this->_noRepeats
)) {
326 $checkList[$colName][] = $colVal;
332 if (array_key_exists('civicrm_contact_gender_id', $row)) {
333 if ($value = $row['civicrm_contact_gender_id']) {
334 $gender = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id');
335 $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
340 // convert employee name to links
341 if (array_key_exists('civicrm_contact_display_name', $row) &&
342 array_key_exists('civicrm_contact_id', $row)
344 $url = CRM_Report_Utils_Report
::getNextUrl('contact/detail',
345 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
346 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
348 $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
353 if (array_key_exists('civicrm_address_country_id', $row)) {
354 if ($value = $row['civicrm_address_country_id']) {
355 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
360 if (array_key_exists('civicrm_address_state_province_id', $row)) {
361 if ($value = $row['civicrm_address_state_province_id']) {
362 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value, FALSE);
367 // skip looking further in rows, if first row itself doesn't
368 // have the column we need