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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Batch Update Contact Information Not Loading
Pages: [1]

Author Topic: Batch Update Contact Information Not Loading  (Read 1086 times)

theMusician

  • I post occasionally
  • **
  • Posts: 48
  • Karma: 3
  • CiviCRM version: 4.0 and 4.0.1
  • CMS version: Drupal 7.0
  • MySQL version: MySQL 5.x
  • PHP version: 5.2
Batch Update Contact Information Not Loading
June 07, 2011, 02:08:05 pm
I love the idea of batch updates for activities. What an excellent time-saver. I created an Activity profile that will allow me to update hours of leave used by each employee in our organization. Conducting an activity search for the custom activity of "Leave Hours" pulls up all of the requested leave activities.

Please see the first attachment. It lists the user that added the activity and who it was added to under the With column. When I select the batch update via profile option from the drop down, choose my profile, and click submit I get the result shown in attachment two. The name of the user who added the information, not the name of the person that the hours are associated with.

I have looked at batch.tpl, batch.php, selector.php, and several other files. I believe I understand how the table is populated but not why the name of the user does not transfer properly. I have read through the other threads of batch.tpl and they all say I have to hook into the details array, though the latest 4.0.2 version does not seem to use $details.

How do I achieve having the the user shown below the With column show up as the user under the Name column on the batch.php screen.

Thank you for any hints or tips. I apologize for the small images, I find it very hard to create two screenshots that total less than 64kb.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Batch Update Contact Information Not Loading
June 07, 2011, 03:49:32 pm
Hmm - played with this a bit and I frankly don't see how this feature can be very useful to folks as it currently behaves. I thought that the Progressive Tech Project folks were using it, but now I'm not sure. Basically, the current code is retrieving one "readOnly" field by default for the listings - which is the sort_name of the activity.source_contact_id (this column s/b labeled 'Added By' and not 'Name').

The code is NOT retrieving the Target ("With") or Assigned contact info at all.

I think we would welcome a patch which makes this feature more useful by including the With and Assigned contact sort names in the readOnly columns.

I think this involves modifying CRM/Activity/Form/Task/Batch.php to add 'target_sort_name' and 'assignee_sort_name' to the returnProperties requested. AND then modifying CRM/Contact/BAO/Contact/Utils.php contactDetails() function to handle those returnProperties (by modifying the query that is built when they are passed).

We probably need to make an assumption about WHICH contact to get the additional readOnly values for. These are defined in contact_autocomplete_options - by default it's primary email, but could be phone, street address ... . Currently we grab those for the source_contact_id for each activity row. I'd probably vote to grab them for the target contact instead IF target contact is in the returnProperties (which it would be in this revised call to the function).

The query would need to be modified to look something like this (assuming email is returned for the target contact):

Code: [Select]
SELECT  contact_source.id as contactId,
civicrm_activity.id as componentId,
contact_source.sort_name as source_sort_name,
contact_target.sort_name as target_sort_name,
email as target_email
FROM  civicrm_activity as civicrm_activity
INNER JOIN civicrm_contact  as contact_source ON ( contact_source.id = civicrm_activity.source_contact_id )
LEFT JOIN civicrm_activity_target ON (civicrm_activity_target.activity_id = civicrm_activity.id)
LEFT JOIN civicrm_contact  as contact_target ON ( contact_target.id = civicrm_activity_target.target_contact_id )
LEFT JOIN civicrm_email email ON ( contact_target.id = email.contact_id AND email.is_primary = 1 ) 
WHERE  civicrm_activity.id IN (572,573)
Group By  componentId
Protect your investment in CiviCRM by  becoming a Member!

theMusician

  • I post occasionally
  • **
  • Posts: 48
  • Karma: 3
  • CiviCRM version: 4.0 and 4.0.1
  • CMS version: Drupal 7.0
  • MySQL version: MySQL 5.x
  • PHP version: 5.2
Re: Batch Update Contact Information Not Loading
June 08, 2011, 08:30:24 am
+1 to Dave. It would have taken me forever to hunt down Contact/BAO/Contact/Utils.php I'll work on the patch as my org would find this feature extremely useful.

Where would I upload a patch too? Should I create a ticket for this? Thanks again for looking into this as I just wasn't sure if I was missing something obvious.


theMusician

  • I post occasionally
  • **
  • Posts: 48
  • Karma: 3
  • CiviCRM version: 4.0 and 4.0.1
  • CMS version: Drupal 7.0
  • MySQL version: MySQL 5.x
  • PHP version: 5.2
Re: Batch Update Contact Information Not Loading
June 08, 2011, 10:07:58 am
Ok. I am a little bit confused as to where some of the information is pulled. Batch.php was easy to modify, and I now have the new target and assignee columns appearing, albeit blank.

Line 81 of batch.php
Code: [Select]
$readOnlyFields = array_merge( array( 'sort_name' => ts( 'Name' ), 'target_sort_name' => ts('Target Name'), 'assignee_sort_name' => ts('Assignee') ),
In Utils.php the query is built by a switch. Here is what I do not understand. The property $returnProperties is populated by an array originally containing sort_name, and this is where I figured I would add target_sort_name and assignee_sort_name. Doing so and adding a case for the target_sort_name as a test fails because the case 'target_sort_name' is not defined anywhere.

Line 692 of Utils.php
Code: [Select]
    $returnProperties = array_fill_keys( array_merge( array( 'sort_name', 'target_sort_name', 'assignee_sort_name'),
My new case, line 720
Code: [Select]
            case 'target_sort_name' :
            $select[] = "$property as $property";
                if ( $componentName == 'Activity' )  {
                    $from[$value] = "INNER JOIN civicrm_activity_target ON ( civicrm_activity_target_id = $compTable.id )"; 
                }   
                break;

Doing it this way I receive a fatal error "DB Error: no such field." Ok, so if I change the case to contact_target.sort_name the page loads but throws a Notice: Undefined property: CRM_Core_DAO::$target_sort_name in CRM_Contact_BAO_Contact_Utils::contactDetails() (line 762 of /vpfa-dev/fa-drupal7/fmlaProject/sites/all/modules/civicrm/CRM/Contact/BAO/Contact/Utils.php).

I agree that the target_sort_name property is not defined but I do not know where to define the property.

I am a little bit lost, I will keep working at it but any other ideas would be greatly appreciated.

theMusician

  • I post occasionally
  • **
  • Posts: 48
  • Karma: 3
  • CiviCRM version: 4.0 and 4.0.1
  • CMS version: Drupal 7.0
  • MySQL version: MySQL 5.x
  • PHP version: 5.2
Re: Batch Update Contact Information Not Loading
June 08, 2011, 06:06:28 pm
Okay. I just about have it sorted out. The target name and e-mail now appear! The creator name is dropped in this version but it is closer.

However in the query I am still needing to add contact_target.sort_name as target_sort_name to the select clause rather than have it dynamically populated via $selectClause.

I really do not understand how the returnProperties array functions. I have added target_sort_name to the array but it cries wolf if I do not explicitly put the above line in the select clause.

Modified sort_name case beginning on line 711 and ending on 714
Code: [Select]
             case 'sort_name' :
                $select[] = "contact_source.$property as source_$property";
                if ( $componentName == 'Activity' )  {
                    $from[$value] = "INNER JOIN civicrm_contact contact_source ON ( contact_source.id = $compTable.source_contact_id ) LEFT JOIN civicrm_activity_target ON (civicrm_activity_target.activity_id = $compTable.id) LEFT JOIN civicrm_contact as contact_target ON ( contact_target.id = civicrm_activity_target.target_contact_id )"; 


modified email case line 726
Code: [Select]
                $from[$value] = "LEFT JOIN civicrm_{$value} {$value} ON ( contact_target.id = {$value}.contact_id AND {$value}.is_primary = 1 ) ";
modified select clause of $query line 746
Code: [Select]
  SELECT  contact_source.id as contactId, $compTable.id as componentId, contact_target.sort_name as target_sort_name, $selectClause
I'll try some more tomorrow. Thanks again. Once it is proper I will submit via Jira.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Batch Update Contact Information Not Loading

This forum was archived on 2017-11-26.