CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Full State/Province name in views?
Pages: [1] 2

Author Topic: Full State/Province name in views?  (Read 6328 times)

SweetTooth

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Full State/Province name in views?
March 13, 2011, 10:52:44 am

Hi all!

2 Questions for all you Drupal Views gurus out there:

1) Does anyone know of a way to get the full state/province name to be displayed in Drupal views rather than just the abbreviation?

2) Would anyone know how to hack views so that a custom field for individual contacts can be made to come up when listing contributions in Views? For instance civicrm_mapit creates some custom fields against the contact (donor)...if those can listed in my contribution view and then grouped (I'm using Views 3), then it would be extremly useful to me.


Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Full State/Province name in views?
March 13, 2011, 10:36:02 pm
Hi,

Try this patch, it will change state abbreviation to actual state name also it will allow contact related custom data in contribution and participant views :) .
I have not tested it detail but hope it will work.
Don't forget to clear views cache after applying this patch.

Code: [Select]
Index: drupal/modules/views/civicrm.views.inc
===================================================================
--- drupal/modules/views/civicrm.views.inc (revision 32968)
+++ drupal/modules/views/civicrm.views.inc (working copy)
@@ -5113,6 +5113,7 @@
     }
 
     $jointable = null;
+    $contact_join = array( );
     switch ($entity_type) {
             
     case "Contact":
@@ -5120,6 +5121,8 @@
     case "Household":
     case "Organization":
         $jointable = 'civicrm_contact';
+        $contact_join = array( 'civicrm_contribution',
+                               'civicrm_participant' );
         break;
     case "Event":
         $jointable = 'civicrm_event';
@@ -5155,6 +5158,18 @@
                                       'field' => 'entity_id',
                                       ),
                   );
+       
+        if ( $jointable == 'civicrm_contact' ) {
+            foreach ( $contact_join as $cjoin ) {
+                $data[$currentgroup['table_name']]['table']['join'][$cjoin] =
+                    array(
+                          'left_table' => 'civicrm_contact',
+                          'left_field' => 'id',
+                          'right_field' => 'contact_id',
+                          'field'      => 'entity_id' );
+            }
+        }
+       
         $currentgroupfields = $currentgroup['fields'];
         $customHTMLTypes = array( 'Select', 'Multi-Select', 'AdvMulti-Select', 'Radio', 'CheckBox',
                                   'Select State/Province', 'Select Country', 'Multi-Select Country',
Index: drupal/modules/views/civicrm/civicrm_handler_field_state.inc
===================================================================
--- drupal/modules/views/civicrm/civicrm_handler_field_state.inc (revision 32968)
+++ drupal/modules/views/civicrm/civicrm_handler_field_state.inc (working copy)
@@ -37,7 +37,7 @@
                 return;
             }
             require_once 'CRM/Core/PseudoConstant.php';
-            self::$_states = CRM_Core_PseudoConstant::stateProvinceAbbreviation( );
+            self::$_states = CRM_Core_PseudoConstant::stateProvince( );
         }
     }

Rajan

SweetTooth

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Full State/Province name in views?
March 14, 2011, 07:31:38 am

Moi Moi Moi I love you!

I've just worked out howerver, that the custom data I'm looking for, is actually in the billing address and as such, that's not really part of the contact, but an address record if you see what I mean. Is there any way to get that out?


qjensen

  • I post frequently
  • ***
  • Posts: 141
  • Karma: 11
    • Scaled Solutions
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Full State/Province name in views?
March 14, 2011, 02:44:35 pm
I just put this together as a modification to the civicrm_views_handler_field_state.inc. It adds an option to the field for you to choose full or abbreviated name and modifies the render function to return the version you selected. This will work for any state/province field because this handler is used for all of them.

This patch has also been submitted to core for consideration.


Code: [Select]
--- "drupal/modules/views/civicrm/civicrm_handler_field_state.inc"
+++ "drupal/modules/views/civicrm/civicrm_handler_field_state.inc"
@@ -30,14 +30,16 @@
  */
 class civicrm_handler_field_state extends views_handler_field {
     static $_states;
-
+    static $_states_full;
+   
     function construct( ) {
-        if ( ! self::$_states ) {
+        if ( ! self::$_states || ! self::$_states_full) {
             if ( ! civicrm_initialize( ) ) {
                 return;
             }
             require_once 'CRM/Core/PseudoConstant.php';
             self::$_states = CRM_Core_PseudoConstant::stateProvinceAbbreviation( );
+            self::$_states_full = CRM_Core_PseudoConstant::stateProvince( );
         }
     }
 
@@ -47,8 +49,30 @@ class civicrm_handler_field_state extends views_handler_field {
              (int ) $sid <= 0 ) {
             return null;
         }
-
-        return self::$_states[$values->{$this->field_alias}];
+       
+        if($this->options['prov_display']==1){
+          return self::$_states[$values->{$this->field_alias}];
+        }
+        else{
+          return self::$_states_full[$values->{$this->field_alias}];
+        }
+    }
+   
+    function option_definition() {
+      $options = parent::option_definition();
+      $options['prov_display'] = array('default' => '');
+      return $options;
+    }
+   
+    function options_form(&$form, &$form_state) {
+      parent::options_form($form, $form_state);
+      $form['prov_display'] = array(
+        '#type' => 'radios',
+        '#title' => 'Phone type for this field',
+        '#options' => array(1 => 'Display state/province abbreviations', 2 => 'Display full state/province name'),
+        '#description' => t('Phone type to be used for this field'),
+        '#default_value' => $this->options['prov_display']
+      );
     }
 }
 ?>
« Last Edit: March 14, 2011, 06:37:08 pm by qjensen »
Quint Jensen
Web Developer
Scaled Solutions
--" Remove the 'I want you to like me' notes from your forehead and place them where they truly will do the most good -- on your mirror!" Author Unknown

Traveler777

  • I post occasionally
  • **
  • Posts: 43
  • Karma: 0
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.2
Re: Full State/Province name in views?
March 14, 2011, 09:49:39 pm
Would this also work for country names? Noticed they also get abbreviated.

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Full State/Province name in views?
March 15, 2011, 01:06:44 am
@SweetTooth: looks like views missing address related custom data,  so here is more generalised :) diff for you.
provides:
- contact related custom data on Participant, Contribution, Activity, Membership views
- event related custom data on Participant views
- address related custom data on contact views
( would u like to add any other cases? so that patch can be extend further )
Code: [Select]
Index: drupal/modules/views/civicrm.views.inc
===================================================================
--- drupal/modules/views/civicrm.views.inc (revision 32968)
+++ drupal/modules/views/civicrm.views.inc (working copy)
@@ -5113,6 +5113,7 @@
     }
 
     $jointable = null;
+    $extrajoin = array( );
     switch ($entity_type) {
             
     case "Contact":
@@ -5120,9 +5121,24 @@
     case "Household":
     case "Organization":
         $jointable = 'civicrm_contact';
+        $extrajoin = array( 'tables' => array( 'civicrm_participant',
+                                               'civicrm_contribution',
+                                               'civicrm_activity',
+                                               'civicrm_membership'),
+                            'fields' => array(  'left_table'  => 'civicrm_contact',
+                                                'left_field'  => 'id',
+                                                'right_field' => 'contact_id',
+                                                'field'       => 'entity_id' )
+                        );
         break;
     case "Event":
         $jointable = 'civicrm_event';
+        $extrajoin = array( 'tables' => array( 'civicrm_participant' ),
+                            'fields' => array(  'left_table'  => 'civicrm_event',
+                                                'left_field'  => 'id',
+                                                'right_field' => 'event_id',
+                                                'field'       => 'entity_id' )
+                            );
         break;
     case "Participant":
         $jointable = 'civicrm_participant';
@@ -5139,6 +5155,15 @@
     case "Membership":
         $jointable = 'civicrm_membership';
         break;
+    case "Address":
+        $jointable = 'civicrm_address';
+        $extrajoin = array( 'tables' => array( 'civicrm_contact' ),
+                            'fields' => array(  'left_table'  => 'civicrm_address',
+                                                'left_field'  => 'id',
+                                                'right_field' => 'contact_id',
+                                                'field'       => 'entity_id' )
+                            );
+        break;
     }
 
     foreach ($tree as $groupkey => $currentgroup) {
@@ -5155,6 +5180,13 @@
                                       'field' => 'entity_id',
                                       ),
                   );
+       
+        if ( !empty($extrajoin) ) {
+            foreach( $extrajoin['tables'] as $jtable ) {
+                $data[$currentgroup['table_name']]['table']['join'][$jtable] = $extrajoin['fields'];
+            }
+        }
+       
         $currentgroupfields = $currentgroup['fields'];
         $customHTMLTypes = array( 'Select', 'Multi-Select', 'AdvMulti-Select', 'Radio', 'CheckBox',
                                   'Select State/Province', 'Select Country', 'Multi-Select Country',
Let me know if any bug u found in this ;).

Rajan

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Full State/Province name in views?
March 15, 2011, 01:23:10 am
@Traveler777: nope, it will work for state only.
But I would like to recommend diff provided by 'Quint Jensen' it will provides option to choose abbreviation or full name for state display in views.
( @qjensen: thanks for the diff  :) )

If u want this for country, try following
This will makes country abbreviations in actual country name.
Code: [Select]
Index: drupal/modules/views/civicrm/civicrm_handler_field_country.inc
===================================================================
--- drupal/modules/views/civicrm/civicrm_handler_field_country.inc (revision 32968)
+++ drupal/modules/views/civicrm/civicrm_handler_field_country.inc (working copy)
@@ -40,7 +40,7 @@
                 return;
             }
             require_once 'CRM/Core/PseudoConstant.php';
-            self::$_countries = CRM_Core_PseudoConstant::countryIsoCode( );
+            self::$_countries = CRM_Core_PseudoConstant::country( );
         }
     }

Rajan

qjensen

  • I post frequently
  • ***
  • Posts: 141
  • Karma: 11
    • Scaled Solutions
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Full State/Province name in views?
March 15, 2011, 03:15:22 am
Hey Rajan,

I don't know if you missed copying some of your patch file, but I think there is a little bit missing to give the user the option of getting the full country name or abbreviation. I submitted a patch to CiviCRM last night with code to enable that selection that is just like the state/province field.

Code: [Select]

--- "drupal/modules/views/civicrm/civicrm_handler_field_country.inc"
+++ "drupal/modules/views/civicrm/civicrm_handler_field_country.inc"
@@ -33,6 +33,7 @@
 
 class civicrm_handler_field_country extends views_handler_field {
     static $_countries;
+    static $_countries_full;
 
     function construct( ) {
         if ( ! self::$_countries ) {
@@ -41,6 +42,7 @@ class civicrm_handler_field_country extends views_handler_field {
             }
             require_once 'CRM/Core/PseudoConstant.php';
             self::$_countries = CRM_Core_PseudoConstant::countryIsoCode( );
+            self::$_countries_full = CRM_Core_PseudoConstant::country( );
         }
     }
 
@@ -51,7 +53,29 @@ class civicrm_handler_field_country extends views_handler_field {
             return null;
         }
 
-        return self::$_countries[$values->{$this->field_alias}];
+        if($this->options['country_display']==1){
+          return self::$_countries[$values->{$this->field_alias}];
+        }
+        else{
+          return self::$_countries_full[$values->{$this->field_alias}];
+        }
+    }
+   
+    function option_definition() {
+      $options = parent::option_definition();
+      $options['country_display'] = array('default' => '');
+      return $options;
+    }
+   
+    function options_form(&$form, &$form_state) {
+      parent::options_form($form, $form_state);
+      $form['country_display'] = array(
+        '#type' => 'radios',
+        '#title' => 'Type of display for country field',
+        '#options' => array(1 => 'Display two letter country code', 2 => 'Display full country name'),
+        '#description' => t('Display full or abbreviated country name'),
+        '#default_value' => $this->options['country_display']
+      );
     }
 }
 ?>
Quint Jensen
Web Developer
Scaled Solutions
--" Remove the 'I want you to like me' notes from your forehead and place them where they truly will do the most good -- on your mirror!" Author Unknown

SweetTooth

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 1
  • CiviCRM version: 4.1
  • CMS version: Drupal 6.20
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Full State/Province name in views?
March 15, 2011, 10:20:35 am
Quote from: Rajan Mayekar on March 15, 2011, 01:06:44 am
@SweetTooth: looks like views missing address related custom data,  so here is more generalised :) diff for you.
provides:
- contact related custom data on Participant, Contribution, Activity, Membership views
- event related custom data on Participant views
- address related custom data on contact views
( would u like to add any other cases? so that patch can be extend further )
Code: [Select]
Index: drupal/modules/views/civicrm.views.inc
===================================================================
--- drupal/modules/views/civicrm.views.inc (revision 32968)
+++ drupal/modules/views/civicrm.views.inc (working copy)
@@ -5113,6 +5113,7 @@
     }
 
     $jointable = null;
+    $extrajoin = array( );
     switch ($entity_type) {
             
     case "Contact":
@@ -5120,9 +5121,24 @@
     case "Household":
     case "Organization":
         $jointable = 'civicrm_contact';
+        $extrajoin = array( 'tables' => array( 'civicrm_participant',
+                                               'civicrm_contribution',
+                                               'civicrm_activity',
+                                               'civicrm_membership'),
+                            'fields' => array(  'left_table'  => 'civicrm_contact',
+                                                'left_field'  => 'id',
+                                                'right_field' => 'contact_id',
+                                                'field'       => 'entity_id' )
+                        );
         break;
     case "Event":
         $jointable = 'civicrm_event';
+        $extrajoin = array( 'tables' => array( 'civicrm_participant' ),
+                            'fields' => array(  'left_table'  => 'civicrm_event',
+                                                'left_field'  => 'id',
+                                                'right_field' => 'event_id',
+                                                'field'       => 'entity_id' )
+                            );
         break;
     case "Participant":
         $jointable = 'civicrm_participant';
@@ -5139,6 +5155,15 @@
     case "Membership":
         $jointable = 'civicrm_membership';
         break;
+    case "Address":
+        $jointable = 'civicrm_address';
+        $extrajoin = array( 'tables' => array( 'civicrm_contact' ),
+                            'fields' => array(  'left_table'  => 'civicrm_address',
+                                                'left_field'  => 'id',
+                                                'right_field' => 'contact_id',
+                                                'field'       => 'entity_id' )
+                            );
+        break;
     }
 
     foreach ($tree as $groupkey => $currentgroup) {
@@ -5155,6 +5180,13 @@
                                       'field' => 'entity_id',
                                       ),
                   );
+       
+        if ( !empty($extrajoin) ) {
+            foreach( $extrajoin['tables'] as $jtable ) {
+                $data[$currentgroup['table_name']]['table']['join'][$jtable] = $extrajoin['fields'];
+            }
+        }
+       
         $currentgroupfields = $currentgroup['fields'];
         $customHTMLTypes = array( 'Select', 'Multi-Select', 'AdvMulti-Select', 'Radio', 'CheckBox',
                                   'Select State/Province', 'Select Country', 'Multi-Select Country',
Let me know if any bug u found in this ;).

Rajan


Thanks, but how do you want me to apply the patch? Here is what I'm putting in and getting back.

[root]# patch -p1 < viewspatch2.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: drupal/modules/views/civicrm.views.inc
|===================================================================
|--- drupal/modules/views/civicrm.views.inc   (revision 32968)
|+++ drupal/modules/views/civicrm.views.inc   (working copy)
--------------------------
o such file or directory
Skip this patch? [y]
Skipping patch.
patch unexpectedly ends in middle of line
4 out of 4 hunks ignored

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Full State/Province name in views?
March 15, 2011, 11:06:11 am

thanx to quint for his patches. Views now gives you the option of using either abbreviation or full name for both state and country. These patches are now part of 3.4 svn and will be in 3.4.alpha3 and 4.0.alpha3

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

puremetal

  • I’m new here
  • *
  • Posts: 10
  • Karma: 0
  • CiviCRM version: 3.3.6
  • CMS version: Joomla 1.5.23
  • MySQL version: 5.1.36
  • PHP version: 5.2.0
Re: Full State/Province name in views?
July 13, 2011, 04:29:09 am
Sorry to gravedig, but can I ask a dumb question: where can I find this option in 3.4? I'm looking around the Joomla demo site (planning to upgrade from 3.3.6) and can't find this option there at all  ???

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Full State/Province name in views?
July 13, 2011, 05:32:25 am
puremetal:
It is for drupal!
This topic is related to CiviCRM integration with views module (http://drupal.org/project/views) of drupal.

Rajan

puremetal

  • I’m new here
  • *
  • Posts: 10
  • Karma: 0
  • CiviCRM version: 3.3.6
  • CMS version: Joomla 1.5.23
  • MySQL version: 5.1.36
  • PHP version: 5.2.0
Re: Full State/Province name in views?
July 13, 2011, 07:15:43 am
ah, woops :P
I found this topic after searching for a way to this with the general address display for contacts - nobody uses the kind of short county/state names in the UK and my users are getting very annoyed with them! Still need to find a way to swap them out with the full county names :-\

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Full State/Province name in views?
October 04, 2011, 04:57:23 pm
not sure if this is best place to report this - but just found on a D7 site that when using civiContact and State i am now only getting the State ID (and not seeing any of above described options to specify if I want short or long)

has something regressed? this is a 4.0.6 and Views3 7.x-3.x-dev
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

david_de

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.2.9
Re: Full State/Province name in views?
October 23, 2011, 10:50:20 am
I have the same problem and so did another poster.  I just updated to 4.0.7 in hopes it had been fixed but there is no change.  The query code is
Code: [Select]
civicrm_address.state_province_id AS civicrm_address_state_province_id that can only produce an ID.

It looks like a bug to me but I am not sure how to go about reporting it.

This is another report on the same issue. http://forum.civicrm.org/index.php/topic,21311.0.html
« Last Edit: October 23, 2011, 10:54:39 am by david_de »

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Full State/Province name in views?

This forum was archived on 2017-11-26.