Documentation » Classes

\Groundhogg\Classes\Task

Published · Last updated

extends Note

Represents a CRM task — a to-do item associated with a contact or other object. Tasks extend Note with a due date and completion state. They appear in the contact record and the tasks dashboard.

Methods #

MethodReturnsDescription
complete()boolMarks the task as complete and records the completion timestamp.
incomplete()boolMarks the task as incomplete.
is_complete()boolReturns true if the task has been marked complete.
is_overdue()boolReturns true if the due date has passed and the task is not complete.
is_due_today()boolReturns true if the task is due today.
is_due_soon()boolReturns true if the task is due within the configured threshold.
days_till_due()intReturns the number of days until the task is due.
get_due_date()stringReturns the due date as a formatted string.
get_date_completed()stringReturns the completion date as a formatted string.
is_for_contact()boolReturns true if the task is associated with a contact.
get_associated_data()arrayReturns the data of the object this task is associated with.

Usage #

Here’s a pseudo code example for a hypothetical CRM task automation integration.

<?php

add_action( 'groundhogg/contact/tag_applied', 'my_plugin_create_follow_up_task', 10, 2 );

/**
 * Create a follow-up task when the "hot-lead" tag is applied.
 *
 * @param \Groundhogg\Contact $contact
 * @param int                  $tag_id
 *
 * @return void
 */
function my_plugin_create_follow_up_task( $contact, $tag_id ) {

    if ( $tag_id !== MY_PLUGIN_HOT_LEAD_TAG_ID ) {
        return;
    }

    $task = new \Groundhogg\Classes\Task( [
        'object_id'   => $contact->get_id(),
        'object_type' => 'contact',
        'user_id'     => $contact->get_owner_id(),
        'content'     => 'Follow up with ' . $contact->get_full_name(),
        'due_date'    => date( 'Y-m-d', strtotime( '+1 day' ) ),
    ] );

    $task->create();
}