Skip to content

Commit

Permalink
fixes relationships issues to be able to display phone of the household
Browse files Browse the repository at this point in the history
of the contact
best practices : moving the location related code to the location
objects
adding the possibility to choose location and type in field for Instant
Messaging and Website
  • Loading branch information
Véronique Gratioulet committed Sep 6, 2016
1 parent 42336ea commit f091f4c
Show file tree
Hide file tree
Showing 11 changed files with 585 additions and 155 deletions.
58 changes: 28 additions & 30 deletions modules/views/civicrm/civicrm_handler_field_address.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,10 @@
* @ingroup civicrm_field_handlers
*/
class civicrm_handler_field_address extends civicrm_handler_field_location {
static $_locationOps;
function construct() {
parent::construct();
if (!self::$_locationOps) {
if (!civicrm_initialize()) {
return;
}
self::$_locationOps = array(0 => 'AND', 1 => 'OR');
}
}

function option_definition() {
$options = parent::option_definition();
$options['is_billing'] = array('default' => '');
$options['is_billing'] = array('default' => 0);
return $options;
}

Expand All @@ -58,31 +48,39 @@ class civicrm_handler_field_address extends civicrm_handler_field_location {
);
}

function join_address($join = array()) {
$extra = array();
if (isset($join->extra)) {
$extra = $join->extra;
}
if (isset($this->options['is_billing']) && $this->options['is_billing']) {
$extra[] = array(
'value' => $this->options['is_billing'],
'numeric' => TRUE,
'field' => 'is_billing',
'operator' => '=',
);
}
if (!empty($extra)) {
$join->extra = $extra;
}
return $join;
}

function get_join() {
$join = parent::get_join();
$join = $this->join_address($join);
return $join;
}

function ensure_my_table() {
if (!isset($this->table_alias)) {
if (!method_exists($this->query, 'ensure_table')) {
vpr_trace();
exit;
}
$extra = array();
$extra = parent::location_extras();
if (isset($this->options['is_billing']) && $this->options['is_billing']) {
$extra[] = array(
'value' => $this->options['is_billing'],
'numeric' => TRUE,
'field' => 'is_billing',
'operator' => '=',
);
}
if (isset($extra) && !empty($extra)) {
$join = $this->get_join();
$join->extra = $extra;
$join->extra_type = self::$_locationOps[$this->options['location_op']];
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
}
else {
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship);
}
$join = $this->get_join();
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
}
return $this->table_alias;
}
Expand Down
103 changes: 103 additions & 0 deletions modules/views/civicrm/civicrm_handler_field_im.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Field handler for Instant Messaging field
*
* @ingroup civicrm_field_handlers
*/
class civicrm_handler_field_im extends civicrm_handler_field_location {
static $_provider;

function construct() {
parent::construct();
if (!self::$_provider) {
if (!civicrm_initialize()) {
return;
}
self::$_provider = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
}
}

function option_definition() {
$options = parent::option_definition();
$options['provider'] = array('default' => 0);
return $options;
}

function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$imOptions = array(0 => 'Any');
foreach (self::$_provider as $id => $type) {
$imOptions[$id] = $type;
}
$form['provider'] = array(
'#type' => 'radios',
'#title' => 'Instant Messaging provider for this field',
'#options' => $imOptions,
'#description' => t('Instant Messaging provider to be displayed for this field'),
'#default_value' => $this->options['provider'],
'#fieldset' => 'location_choices',
);
}

function join_im($join = array()) {
$extra = array();
if (isset($join->extra)) {
$extra = $join->extra;
}
if (isset($this->options['provider']) && $this->options['provider']) {
$extra[] = array(
'value' => $this->options['provider'],
'numeric' => TRUE,
'field' => 'provider_id',
'operator' => '=',
);
}
if (!empty($extra)) {
$join->extra = $extra;
}
return $join;
}

function get_join() {
$join = parent::get_join();
$join = $this->join_im($join);
return $join;
}

function ensure_my_table() {
if (!isset($this->table_alias)) {
if (!method_exists($this->query, 'ensure_table')) {
vpr_trace();
exit;
}
$join = $this->get_join();
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
}
return $this->table_alias;
}
}

37 changes: 21 additions & 16 deletions modules/views/civicrm/civicrm_handler_field_location.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class civicrm_handler_field_location extends civicrm_handler_field {
static $_locationTypes;
static $_locationOps;
static $location_op;

function construct() {
parent::construct();
if (!self::$_locationTypes) {
Expand Down Expand Up @@ -109,19 +110,8 @@ class civicrm_handler_field_location extends civicrm_handler_field {
vpr_trace();
exit;
}
if ($this->options['location_type'] > 0 ||
(isset($this->options['is_primary']) && $this->options['is_primary'])
) {
$join = $this->get_join();
$extra = $this->location_extras();
$join->extra = $extra;
// Decide between And/Or
$join->extra_type = self::$_locationOps[$this->options['location_op']];
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
}
else {
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship);
}
$join = $this->get_join();
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
}
return $this->table_alias;
}
Expand All @@ -146,8 +136,23 @@ class civicrm_handler_field_location extends civicrm_handler_field {
}
return $extra;
}
}



function join_location($join = array()) {
$extra = array();
if (isset($join->extra)) {
$extra = $join->extra;
}
$extra = array_merge($extra, $this->location_extras());
if (!empty($extra)) {
$join->extra = $extra;
$join->extra_type = self::$_locationOps[$this->options['location_op']];
}
return $join;
}

function get_join() {
$join = parent::get_join();
$join = $this->join_location($join);
return $join;
}
}
47 changes: 28 additions & 19 deletions modules/views/civicrm/civicrm_handler_field_phone.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
class civicrm_handler_field_phone extends civicrm_handler_field_location {
static $_phoneType;

function construct() {
parent::construct();
if (!self::$_phoneType) {
Expand Down Expand Up @@ -62,31 +63,39 @@ class civicrm_handler_field_phone extends civicrm_handler_field_location {
);
}

function join_phone($join = array()) {
$extra = array();
if (isset($join->extra)) {
$extra = $join->extra;
}
if (isset($this->options['phone_type']) && $this->options['phone_type']) {
$extra[] = array(
'value' => $this->options['phone_type'],
'numeric' => TRUE,
'field' => 'phone_type_id',
'operator' => '=',
);
}
if (!empty($extra)) {
$join->extra = $extra;
}
return $join;
}

function get_join() {
$join = parent::get_join();
$join = $this->join_phone($join);
return $join;
}

function ensure_my_table() {
if (!isset($this->table_alias)) {
if (!method_exists($this->query, 'ensure_table')) {
vpr_trace();
exit;
}
if (isset($this->options['phone_type']) && $this->options['phone_type']) {
$join = $this->get_join();
$extra = parent::location_extras();
$extra[] = array(
'value' => $this->options['phone_type'],
'numeric' => TRUE,
'field' => 'phone_type_id',
'operator' => '=',
);
$join->extra = $extra;
$join->extra_type = self::$_locationOps[$this->options['location_op']];
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
}
else {
$join = $this->get_join();
$join->extra = parent::location_extras();
$join->extra_type = self::$_locationOps[$this->options['location_op']];
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
}
$join = $this->get_join();
$this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
}
return $this->table_alias;
}
Expand Down
Loading

0 comments on commit f091f4c

Please sign in to comment.