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) »
  • Glossary of Civi Records?
Pages: [1]

Author Topic: Glossary of Civi Records?  (Read 1469 times)

mariagwyn

  • I post frequently
  • ***
  • Posts: 149
  • Karma: 4
  • CiviCRM version: CiviCRM 3.3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.2.14
  • PHP version: 5.0.91-50-log
Glossary of Civi Records?
September 14, 2009, 03:05:20 pm
Drupal Views 2 has a glossary view attached to the argument 'node: title'.  Is there any way to create a similar view to contact: last name?  The glossary view groups node titles by letter, it would be helpful if a glossary of last names was available.  Has anyone done this?

The views file which controls this in Views is: views_handler_argument_string.inc, and modifies fields that are text strings.  Any way to hook into this?
« Last Edit: September 14, 2009, 03:46:26 pm by mariagwyn »

DanilaD

  • I post occasionally
  • **
  • Posts: 93
  • Karma: 11
Re: Glossary of Civi Records?
September 20, 2009, 08:01:34 am
I created this kind of glossary by using PHP-controlled field and writing custom module to fill that field with first letter of last name on contact change. Then I use this field as a filter for a view. For contacts already in base I filled that field by SQL command.

Regards,
Danila

DanilaD

  • I post occasionally
  • **
  • Posts: 93
  • Karma: 11
Re: Glossary of Civi Records?
September 20, 2009, 08:10:32 am
In the custom module:

Code: [Select]
// This function is called after a db write on some objects
// Should be able to get Last Name in English here
function modulename_civicrm_post( $op, $objectName, $objectId, &$objectRef) {
        if ( $op != 'create' && $op != 'edit') {
                return;
        }
 
        if ( $objectName != 'Individual') {
                // we work only with Individuals here
                return;
        }
       
        // Cool! The individual name is already in the $objectRef, [0...30], last_name
       
        if ( isset ($objectRef->last_name)) {
            $lastname_en = $objectRef->last_name;
            $letter_en = $lastname_en[0];
       
            $groupID = 1; // constituent_information
            $needs_update = false;
            $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
                                                                $groupID,
                                                                'table_name');
                                                               
            $sql = "SELECT last_name_letter__en__71 from $tableName WHERE entity_id = $objectId";
            $dao = CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
                                                               
            if (! $dao->fetch()) {
                $needs_update = true;
            }
           
            if (! $dao->last_name_letter__en__71) {
                //value may also be empty... Copied this from example, will test how it works
                $needs_update = true;
            }
            else {
                if ( $dao->last_name_letter__en__71 != $letter_en) {
                    $needs_update = true;
                }
            }
           
           
            if ($needs_update) {
                $sql = "UPDATE $tableName SET last_name_letter__en__71 = \"$letter_en\" WHERE entity_id = $objectId";
                CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray);
            }               
        }
}

Comments and suggestions are welcomed.

mariagwyn

  • I post frequently
  • ***
  • Posts: 149
  • Karma: 4
  • CiviCRM version: CiviCRM 3.3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.2.14
  • PHP version: 5.0.91-50-log
Re: Glossary of Civi Records?
September 21, 2009, 12:58:37 pm
Danila,

This looks very very promising, but as a Civi neophyte, can you detail the process?  It sounds like ...

1.  You created a field (named: last_name_letter__en__71).  How is it controlled by php?  Is this what the checkbox "View" is?  So I just create an alpha-text field, check this box.
2.  Custom module: where did you put this, in a typical drupal custom module?  I have one of those, just want to make sure I am putting it in the right place. 
3.  What does this refer to: "CRM_Core_DAO_CustomGroup"?  Is this the name of the group the new field is in?  Just making sure so I can edit properly.
4.  Anything else you can tell me?

I will test this and get back to you.  Thanks!!!!!

DanilaD

  • I post occasionally
  • **
  • Posts: 93
  • Karma: 11
Re: Glossary of Civi Records?
September 22, 2009, 05:18:00 am
Hello, Mariagwyn.

1. I created a field named "Last Name Letter (En)", view only, and checked the internal name of the field somewhere in tables of CiviCRM (please read documentation on where to do that, it should be in a table corresponding to your Custom Fields group). The internal name occured to be last_name_letter__en__71.

2. Yes, it's a custom module where I put all custom written hooks.

3. CRM_Core_DAO_CustomGroup is a name of some internal CiviCRM constant, I think. You should not rename it. I found this particular line in some example in the Documentations area (don't remeber which one).

4. Debug on test server (or local machine) first. It's easy to put all site to a WSOD by a simple misprint in the custom module :)

Regards,
Danila

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Glossary of Civi Records?

This forum was archived on 2017-11-26.