diff --git a/civicrm.info b/civicrm.info index 37cc214f2..2015f7475 100644 --- a/civicrm.info +++ b/civicrm.info @@ -90,6 +90,7 @@ files[] = modules/views/civicrm/civicrm_handler_relationship_memberships_contrib files[] = modules/views/civicrm/civicrm_handler_relationship_location.inc files[] = modules/views/civicrm/civicrm_handler_relationship_mail.inc files[] = modules/views/civicrm/civicrm_handler_relationship_phone.inc +files[] = modules/views/civicrm/civicrm_handler_relationship_im.inc files[] = modules/views/civicrm/civicrm_handler_relationship_address.inc ; views plugins diff --git a/modules/views/civicrm/civicrm_handler_field_address.inc b/modules/views/civicrm/civicrm_handler_field_address.inc index 006771b80..9983a07b6 100644 --- a/modules/views/civicrm/civicrm_handler_field_address.inc +++ b/modules/views/civicrm/civicrm_handler_field_address.inc @@ -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; } @@ -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; } diff --git a/modules/views/civicrm/civicrm_handler_field_im.inc b/modules/views/civicrm/civicrm_handler_field_im.inc new file mode 100644 index 000000000..c8e9aa62f --- /dev/null +++ b/modules/views/civicrm/civicrm_handler_field_im.inc @@ -0,0 +1,103 @@ + 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; + } +} + diff --git a/modules/views/civicrm/civicrm_handler_field_location.inc b/modules/views/civicrm/civicrm_handler_field_location.inc index 7230c7068..cb6abd3d9 100644 --- a/modules/views/civicrm/civicrm_handler_field_location.inc +++ b/modules/views/civicrm/civicrm_handler_field_location.inc @@ -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) { @@ -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; } @@ -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; + } +} diff --git a/modules/views/civicrm/civicrm_handler_field_phone.inc b/modules/views/civicrm/civicrm_handler_field_phone.inc index aee3d1d51..64b1572d6 100644 --- a/modules/views/civicrm/civicrm_handler_field_phone.inc +++ b/modules/views/civicrm/civicrm_handler_field_phone.inc @@ -30,6 +30,7 @@ */ class civicrm_handler_field_phone extends civicrm_handler_field_location { static $_phoneType; + function construct() { parent::construct(); if (!self::$_phoneType) { @@ -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; } diff --git a/modules/views/civicrm/civicrm_handler_field_website.inc b/modules/views/civicrm/civicrm_handler_field_website.inc new file mode 100644 index 000000000..7d8a83ed6 --- /dev/null +++ b/modules/views/civicrm/civicrm_handler_field_website.inc @@ -0,0 +1,103 @@ + 0); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $websiteOptions = array(0 => 'Any'); + foreach (self::$_websiteType as $id => $type) { + $websiteOptions[$id] = $type; + } + $form['website_type'] = array( + '#type' => 'radios', + '#title' => 'Website type for this field', + '#options' => $websiteOptions, + '#description' => t('Website type to be displayed for this field'), + '#default_value' => $this->options['website_type'], + '#fieldset' => 'location_choices', + ); + } + + function join_website($join = array()) { + $extra = array(); + if (isset($join->extra)) { + $extra = $join->extra; + } + if (isset($this->options['website_type']) && $this->options['website_type']) { + $extra[] = array( + 'value' => $this->options['website_type'], + 'numeric' => TRUE, + 'field' => 'website_type_id', + 'operator' => '=', + ); + } + if (!empty($extra)) { + $join->extra = $extra; + } + return $join; + } + + function get_join() { + $join = parent::get_join(); + $join = $this->join_website($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; + } +} + diff --git a/modules/views/civicrm/civicrm_handler_relationship_address.inc b/modules/views/civicrm/civicrm_handler_relationship_address.inc index 75d33053b..f370b0820 100644 --- a/modules/views/civicrm/civicrm_handler_relationship_address.inc +++ b/modules/views/civicrm/civicrm_handler_relationship_address.inc @@ -29,36 +29,14 @@ * @ingroup civicrm_relationship_handlers */ class civicrm_handler_relationship_address extends civicrm_handler_relationship_location { - - function ensure_my_table() { - if (!isset($this->table_alias)) { - if (!method_exists($this->query, 'ensure_table')) { - vpr_trace(); - exit; - } - $extra = $this->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; - // 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); - } - } - return $this->table_alias; + + function option_definition() { + $options = parent::option_definition(); + $options['is_billing'] = array('default' => 0); + return $options; } - function options_form(&$form, &$form_state) { + function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['is_billing'] = array( '#type' => 'checkbox', @@ -69,5 +47,60 @@ class civicrm_handler_relationship_address extends civicrm_handler_relationship_ '#fieldset' => 'location_choices', ); } + + 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(t('Ensure my table called but query has no ensure_table method.')); + return; + } + $join = $this->get_join(); + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); + } + return $this->table_alias; + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + // Just ensure the one table. This is briefer than parent::query(), which + // attempts to create an additional join. + $this->alias = $this->ensure_my_table(); + + //register relationship + $this->view->relationship[$this->options['id']]->alias = $this->alias; + $this->query->relationships[$this->alias] = array( + 'link' => $this->relationship, + 'table' => $this->table, + 'base' => $this->table, + ); + } } diff --git a/modules/views/civicrm/civicrm_handler_relationship_im.inc b/modules/views/civicrm/civicrm_handler_relationship_im.inc new file mode 100644 index 000000000..3f9214997 --- /dev/null +++ b/modules/views/civicrm/civicrm_handler_relationship_im.inc @@ -0,0 +1,119 @@ + 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 relationship', + '#options' => $imOptions, + '#description' => t('Instant Messaging provider to be used for this relationship'), + '#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(t('Ensure my table called but query has no ensure_table method.')); + return; + } + $join = $this->get_join(); + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); + } + return $this->table_alias; + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + // Just ensure the one table. This is briefer than parent::query(), which + // attempts to create an additional join. + $this->alias = $this->ensure_my_table(); + //register relationship + $this->view->relationship[$this->options['id']]->alias = $this->alias; + $this->query->relationships[$this->alias] = array( + 'link' => $this->relationship, + 'table' => $this->table, + 'base' => $this->table, + ); + } +} + diff --git a/modules/views/civicrm/civicrm_handler_relationship_location.inc b/modules/views/civicrm/civicrm_handler_relationship_location.inc index b536b96f8..77438fe1f 100644 --- a/modules/views/civicrm/civicrm_handler_relationship_location.inc +++ b/modules/views/civicrm/civicrm_handler_relationship_location.inc @@ -105,7 +105,6 @@ class civicrm_handler_relationship_location extends views_handler_relationship { ); } - function location_extras() { $extra = array(); if (!empty($this->options['location_type'])) { @@ -127,6 +126,37 @@ class civicrm_handler_relationship_location extends views_handler_relationship { 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; + } + + function ensure_my_table() { + if (!isset($this->table_alias)) { + if (!method_exists($this->query, 'ensure_table')) { + vpr(t('Ensure my table called but query has no ensure_table method.')); + return; + } + $join = $this->get_join(); + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); + } + return $this->table_alias; + } + /** * Called to implement a relationship in a query. */ @@ -134,6 +164,8 @@ class civicrm_handler_relationship_location extends views_handler_relationship { // Just ensure the one table. This is briefer than parent::query(), which // attempts to create an additional join. $this->ensure_my_table(); + //register relationship + $this->view->relationship[$this->options['id']]->alias = $this->alias; + $this->alias = $this->table_alias; } } - diff --git a/modules/views/civicrm/civicrm_handler_relationship_mail.inc b/modules/views/civicrm/civicrm_handler_relationship_mail.inc index 67b9de434..30046a1a5 100644 --- a/modules/views/civicrm/civicrm_handler_relationship_mail.inc +++ b/modules/views/civicrm/civicrm_handler_relationship_mail.inc @@ -29,24 +29,15 @@ * @ingroup civicrm_relationship_handlers */ class civicrm_handler_relationship_mail extends civicrm_handler_relationship_location { - + function ensure_my_table() { if (!isset($this->table_alias)) { if (!method_exists($this->query, 'ensure_table')) { - vpr_trace(); - exit; - } - $extra = $this->location_extras(); - if (isset($extra) && !empty($extra)) { - $join = $this->get_join(); - $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); + vpr(t('Ensure my table called but query has no ensure_table method.')); + return; } + $join = $this->get_join(); + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); } return $this->table_alias; } @@ -57,7 +48,14 @@ class civicrm_handler_relationship_mail extends civicrm_handler_relationship_loc function query() { // Just ensure the one table. This is briefer than parent::query(), which // attempts to create an additional join. - $this->ensure_my_table(); + $this->alias = $this->ensure_my_table(); + //register relationship + $this->view->relationship[$this->options['id']]->alias = $this->alias; + $this->query->relationships[$this->alias] = array( + 'link' => $this->relationship, + 'table' => $this->table, + 'base' => $this->table, + ); } } diff --git a/modules/views/civicrm/civicrm_handler_relationship_phone.inc b/modules/views/civicrm/civicrm_handler_relationship_phone.inc index ce0951681..6c56413d7 100644 --- a/modules/views/civicrm/civicrm_handler_relationship_phone.inc +++ b/modules/views/civicrm/civicrm_handler_relationship_phone.inc @@ -29,7 +29,7 @@ * @ingroup civicrm_relationship_handlers */ class civicrm_handler_relationship_phone extends civicrm_handler_relationship_location { - + static $_phoneType; function construct() { parent::construct(); @@ -63,31 +63,40 @@ class civicrm_handler_relationship_phone extends civicrm_handler_relationship_lo ); } + + 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); + vpr(t('Ensure my table called but query has no ensure_table method.')); + return; } + $join = $this->get_join(); + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); } return $this->table_alias; } @@ -98,7 +107,13 @@ class civicrm_handler_relationship_phone extends civicrm_handler_relationship_lo function query() { // Just ensure the one table. This is briefer than parent::query(), which // attempts to create an additional join. - $this->ensure_my_table(); + $this->alias = $this->ensure_my_table(); + //register relationship + $this->view->relationship[$this->options['id']]->alias = $this->alias; + $this->query->relationships[$this->alias] = array( + 'link' => $this->relationship, + 'table' => $this->table, + 'base' => $this->table, + ); } } - diff --git a/modules/views/civicrm/civicrm_handler_relationship_website.inc b/modules/views/civicrm/civicrm_handler_relationship_website.inc new file mode 100644 index 000000000..00489e222 --- /dev/null +++ b/modules/views/civicrm/civicrm_handler_relationship_website.inc @@ -0,0 +1,119 @@ + 0); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $websiteOptions = array(0 => 'Any'); + foreach (self::$_websiteType as $id => $type) { + $websiteOptions[$id] = $type; + } + $form['website_type'] = array( + '#type' => 'radios', + '#title' => 'Website type for this relationship', + '#options' => $websiteOptions, + '#description' => t('Website type to be used for this relationship'), + '#default_value' => $this->options['website_type'], + '#fieldset' => 'location_choices', + ); + } + + function join_website($join = array()) { + $extra = array(); + if (isset($join->extra)) { + $extra = $join->extra; + } + if (isset($this->options['website_type']) && $this->options['website_type']) { + $extra[] = array( + 'value' => $this->options['website_type'], + 'numeric' => TRUE, + 'field' => 'website_type_id', + 'operator' => '=', + ); + } + if (!empty($extra)) { + $join->extra = $extra; + } + return $join; + } + + function get_join() { + $join = parent::get_join(); + $join = $this->join_website($join); + return $join; + } + + function ensure_my_table() { + if (!isset($this->table_alias)) { + if (!method_exists($this->query, 'ensure_table')) { + vpr(t('Ensure my table called but query has no ensure_table method.')); + return; + } + $join = $this->get_join(); + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); + } + return $this->table_alias; + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + // Just ensure the one table. This is briefer than parent::query(), which + // attempts to create an additional join. + $this->alias = $this->ensure_my_table(); + //register relationship + $this->view->relationship[$this->options['id']]->alias = $this->alias; + $this->query->relationships[$this->alias] = array( + 'link' => $this->relationship, + 'table' => $this->table, + 'base' => $this->table, + ); + } +} + diff --git a/modules/views/components/civicrm.core.inc b/modules/views/components/civicrm.core.inc index 3b1e5af65..3ac410cfd 100644 --- a/modules/views/components/civicrm.core.inc +++ b/modules/views/components/civicrm.core.inc @@ -30,6 +30,7 @@ * civicrm_address * civicrm_email * civicrm_website + * civicrm_im * civicrm_phone * civicrm_group * civicrm_tag @@ -1184,7 +1185,7 @@ function _civicrm_core_data(&$data, $enabled) { 'left_field' => 'contact_id', 'field' => 'contact_id', ); - + // EMAIL ADDRESS ID $data['civicrm_email']['id'] = array( 'title' => t('Email Address'), @@ -1519,7 +1520,205 @@ function _civicrm_core_data(&$data, $enabled) { ); - // CHILLING OUT AT THE CIVICRM_WEBSITE TABLE + // CHILLING OUT AT THE CIVICRM_IM TABLE + + $data['civicrm_im']['table']['group'] = t('CiviCRM Instant Messaging'); + + // Explain how this table joins to others. + $data['civicrm_im']['table']['join'] = array( + // Directly links to contact table. + 'civicrm_contact' => array( + 'left_field' => 'id', + 'field' => 'contact_id', + ), + ); + + //CiviCRM Im Using Contacts as a pitstop before going on to Participants + $data['civicrm_im']['table']['join']['civicrm_participant'] = array( + 'left_table' => 'civicrm_contact', + 'left_field' => 'id', + 'field' => 'contact_id', + ); + + //CiviCRM Im Using Contacts as a pitstop before going on to Contributions + $data['civicrm_im']['table']['join']['civicrm_contribution'] = array( + 'left_table' => 'civicrm_contact', + 'left_field' => 'id', + 'field' => 'contact_id', + ); + + //CiviCRM Im Using Contacts as a pitstop before going on to Activities + $data['civicrm_im']['table']['join']['civicrm_activity'] = array( + 'left_table' => 'civicrm_contact', + 'left_field' => 'id', + 'field' => 'contact_id', + ); + + + //CiviCRM Im Using Locations as a pitstop before going on to Events + $data['civicrm_im']['table']['join']['civicrm_event'] = array( + 'left_table' => 'civicrm_loc_block', + 'left_field' => 'im_id', + 'field' => 'id', + ); + //CiviCRM Im Using Contacts as a pitstop before going on to Memberhsips + $data['civicrm_im']['table']['join']['civicrm_membership'] = array( + 'left_table' => 'civicrm_contact', + 'left_field' => 'id', + 'field' => 'contact_id', + ); + + //Display Im Details in User Views + $data['civicrm_im']['table']['join']['users'] = array( + 'left_table' => 'civicrm_uf_match', + 'left_field' => 'contact_id', + 'field' => 'contact_id', + ); + + + //BOOLEAN : IS PRIMARY IM + $data['civicrm_im']['is_primary'] = array( + 'title' => t('Is Primary Instant Messaging'), + 'help' => t('Is this the contact\'s primary Instant Messaging?'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + //BOOLEAN : IS BILLING IM + $data['civicrm_im']['is_billing'] = array( + 'title' => t('Is Billing Instant Messaging'), + 'help' => t('Is this the contact\'s billing Instant Messaging?'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + //IM'S LOCATION TYPE + $data['civicrm_im']['location_type'] = array( + 'title' => t('Location Type'), + 'real field' => 'location_type_id', + 'help' => t('The Location of the Instant Messaging for the Contact'), + 'field' => array( + 'handler' => 'civicrm_handler_field_pseudo_constant', + 'click sortable' => TRUE, + 'pseudo class' => 'CRM_Core_PseudoConstant', + 'pseudo method' => 'get', + 'dao class' => 'CRM_Core_DAO_IM', + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + 'filter' => array( + 'handler' => 'civicrm_handler_filter_pseudo_constant', + 'allow empty' => TRUE, + 'pseudo class' => 'CRM_Core_PseudoConstant', + 'pseudo method' => 'get', + 'dao class' => 'CRM_Core_DAO_IM', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + //NAME + $data['civicrm_im']['name'] = array( + 'title' => t('Name'), + 'help' => t('IM screen name'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + ); + + // IM ID + $data['civicrm_im']['id'] = array( + 'title' => t('Instant Messaging'), + 'help' => t('Contact Instant Messaging'), + 'relationship' => array( + 'base' => 'civicrm_contact', + 'field' => 'id', + 'relationship table' => 'civicrm_im', + 'relationship field' => 'contact_id', + 'handler' => 'civicrm_handler_relationship_im', + 'label' => t('CiviCRM Instant Messaging'), + ), + ); + + //CONTACT ID contact this IM belongs to + $data['civicrm_im']['contact_id'] = array( + 'title' => t('Contact ID'), + 'help' => t('Contact Instant Messaging belongs to '), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + 'allow empty' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'base' => 'civicrm_contact', + 'base field' => 'id', + 'handler' => 'views_handler_relationship', + 'label' => t('Related Instant Messaging'), + ), + ); + + //IM Provider + $data['civicrm_im']['provider'] = array( + 'title' => t('IM Provider'), + 'real field' => 'provider_id', + 'help' => t('Which IM Provider does this screen name belong to'), + 'field' => array( + 'handler' => 'civicrm_handler_field_pseudo_constant', + 'click sortable' => TRUE, + 'pseudo class' => 'CRM_Core_PseudoConstant', + 'pseudo method' => 'get', + 'dao class' => 'CRM_Core_DAO_IM', + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + 'filter' => array( + 'handler' => 'civicrm_handler_filter_pseudo_constant', + 'allow empty' => TRUE, + 'pseudo class' => 'CRM_Core_PseudoConstant', + 'pseudo method' => 'get', + 'dao class' => 'CRM_Core_DAO_IM', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + +// CHILLING OUT AT THE CIVICRM_WEBSITE TABLE $data['civicrm_website']['table']['group'] = t('CiviCRM Website');