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 (Moderator: Dave Greenberg) »
  • Activity follow up dates
Pages: [1]

Author Topic: Activity follow up dates  (Read 1239 times)

alanms

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Activity follow up dates
September 30, 2010, 04:39:36 pm
Hey,

Follow up activity dates seem counter-intuitive. There's two parts to this post: below is a code fix, but first, I'm wondering if there's some wisdom to this that I've missed.

So say I create an activity with a follow-up. Say it's the 2nd October and I schedule a meeting with Bob for the 15th October. I expect I'll want to call Bob 3 days later for an update, so I schedule a follow-up activity, phone call, for + 3 days.

I end up with:-
5th October: Call Bob for post meeting update
15th October: Meet with Bob

Eh? After some hunting in the code (the date is calculated in the Activity/BAO/Activity.php function createFollowupActivity), this is clearly how it's intended to be - it calculates the followup date using "$currentDate".

I can't understand why? Is it assuming I'll only ever want to create follow up activities on or after the event has happened? In order to get what I wanted:-

15th October: Meet with Bob
18th October: Call Bob for post meeting update

...I need to do mental maths and calendar-checking to figure out how many days to add (in this case, +16 days). If I'm doing lots of these in a hurry, this looks like it could be headaches or mistakes waiting to happen. I'm sure there's a rational explanation for why it's like this, but I can't think what.

I've put together some working code to change this, which I'll post as a reply below. But I really want to know why it's set up like this? Is there some wisdom here that I'm not seeing?
« Last Edit: September 30, 2010, 05:45:44 pm by alanms »

alanms

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: Activity follow up dates
September 30, 2010, 05:25:05 pm
Here's code I'm using to change this. It makes activity follow up dates relative to the activity date, not the current date when the activity was created - UNLESS the activity's date is in the past, in which case it uses today's date.

(Why the two possibilities: I'm assuming that if someone creates a follow-up for an activity in the future, they want it to be after the activity in the future, and they're thinking relative to the activity in the future. e.g. "Must remember to call her after the interview - two days later seems best", or "We allow 2 weeks after each mailing before we start making follow up calls". However, if they're editing an event from the past and adding a follow-up, they've probably just done a task or received information that is relevant to that activity, and so they're more likely to be thinking relative to now - the date the activity was originally scheduled for is now a historical detail not a focus of attention)

If you want it to behave like this, here's the code (written for 3.2.3 Drupal).

In .../CRM/Activity/BAO/Activity.php around line 1730, change from:

Code: [Select]
       $currentDate  = implode( ' ', CRM_Utils_Date::setDateDefaults( ) );
        $followupDate = CRM_Utils_Date::intervalAdd( $params['interval_unit'], $params['interval'], $currentDate );

to:

Code: [Select]
       $currentDate  = implode( ' ', CRM_Utils_Date::setDateDefaults( ) );
        if ( strtotime($currentDate) > strtotime($params['activity_date_time']) ) {
          $useDate = $currentDate;
        } else {
          $useDate = $params['activity_date_time'];
        }
        $followupDate = CRM_Utils_Date::intervalAdd( $params['interval_unit'], $params['interval'], $useDate );

This works and puts same-format valid MySQL dates in the database. If it doesn't work for you, consider trying formatting $params['activity_date_time'] to match $currentDate (see http://php.net/manual/en/function.date.php - inserting print_r($currentDate); anywhere below where it's defined will show you how it's formatted)

If you want it always relative to activity date, you don't need $currentDate at all:

Code: [Select]
       $followupDate = CRM_Utils_Date::intervalAdd( $params['interval_unit'], $params['interval'], $params['activity_date_time'] );
« Last Edit: September 30, 2010, 05:41:03 pm by alanms »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Activity follow up dates
October 01, 2010, 10:58:24 am
Alan - Your proposed / patched behavior makes more sense to me than the current behavior. I've pinged some others who were involved in the development of this feature to see if there's some good reason for the current behavior. If there's agreement that your approach makes more sense - I'll post back here and ask you to file an issue with a patch against svn trunk. Thanks for being proactive and investigating and coming up with a solution!
Protect your investment in CiviCRM by  becoming a Member!

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Activity follow up dates
October 04, 2010, 07:22:34 am
The original use-case came from CiviCase, where you are completing an activity (now) and scheduling a followup.

I don't see an issue with changing it to be relative to activity-date.

But for past activities there's some question about whether having it automatically behave differently is in general a good UI design. I would argue for just being relative to activity-date regardless, especially since it would be rare to go back and edit a previous activity solely for the purpose of scheduling a followup - why not just create a new scheduled followup? And if, as you indicate "they've probably just done a task or received information", then, at least in CiviCase context, you would be creating a new activity to record that new task/information anyway, not editing a previous activity.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Activity follow up dates
October 04, 2010, 09:36:44 am
I agree w/ Dave that we should be consistent and set the f/up relative to the activity date in all cases.
Protect your investment in CiviCRM by  becoming a Member!

alanms

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: Activity follow up dates
October 05, 2010, 05:11:13 am
No problem, thanks in return for having a responsive community! Sadly I don't have time to put together a patch file right now (not least because in the 7 or 8 times in the past I've looked for good 'How to make a patch file' reference resources I've never yet found a practical one that made sense - any handy URLs would be gratefully received!) but it's a really simple change, dropping one line of code and mildly changing another.

On second thoughts I'd also agree that the consistent approach does make more sense - the main kind of scenarios I had in mind were where a task has been completed late and the user adds the follow-up task at the same time as changing the status of the original task to 'done' and adding any notes. If they're doing all this, they really should also be changing the date to the real date the activity happened, and as you say if it's not actually relative to the date it actually happened, it doesn't need to be a follow up event.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Activity follow up dates

This forum was archived on 2017-11-26.