Example #1
0
/**
 * Get an array of timeline events
 * Events for which the skip() method returns true will be excluded
 * @param integer $p_start_time Timestamp representing start time of the period.
 * @param integer $p_end_time   Timestamp representing end time of the period.
 * @param integer $p_max_events The maximum number of events to return or 0 for unlimited.
 * @return array
 */
function timeline_events($p_start_time, $p_end_time, $p_max_events)
{
    $t_timeline_events = array();
    $t_result = history_get_range_result(null, $p_start_time, $p_end_time, 'DESC');
    $t_count = 0;
    while ($t_history_event = history_get_event_from_row($t_result, auth_get_current_user_id(), true)) {
        $t_event = null;
        $t_user_id = $t_history_event['userid'];
        $t_timestamp = $t_history_event['date'];
        $t_issue_id = $t_history_event['bug_id'];
        switch ($t_history_event['type']) {
            case NEW_BUG:
                $t_event = new IssueCreatedTimelineEvent($t_timestamp, $t_user_id, $t_issue_id);
                break;
            case BUGNOTE_ADDED:
                $t_bugnote_id = $t_history_event['old_value'];
                $t_event = new IssueNoteCreatedTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, $t_bugnote_id);
                break;
            case BUG_MONITOR:
                # Skip monitors added for others due to reminders, only add monitor events where added
                # user is the same as the logged in user.
                if ((int) $t_history_event['old_value'] == (int) $t_history_event['userid']) {
                    $t_event = new IssueMonitorTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, true);
                }
                break;
            case BUG_UNMONITOR:
                $t_event = new IssueMonitorTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, false);
                break;
            case TAG_ATTACHED:
                $t_event = new IssueTagTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, $t_history_event['old_value'], true);
                break;
            case TAG_DETACHED:
                $t_event = new IssueTagTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, $t_history_event['old_value'], false);
                break;
            case NORMAL_TYPE:
                switch ($t_history_event['field']) {
                    case 'status':
                        $t_event = new IssueStatusChangeTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, $t_history_event['old_value'], $t_history_event['new_value']);
                        break;
                    case 'handler_id':
                        $t_event = new IssueAssignedTimelineEvent($t_timestamp, $t_user_id, $t_issue_id, $t_history_event['new_value']);
                        break;
                }
                break;
        }
        # Do not include skipped events
        if ($t_event != null && !$t_event->skip()) {
            $t_timeline_events[] = $t_event;
            $t_count++;
            if ($p_max_events > 0 && $t_count >= $p_max_events) {
                break;
            }
        }
    }
    return $t_timeline_events;
}
Example #2
0
/**
 * Retrieves the raw history events for the specified bug id and returns it in an array
 * The array is indexed from 0 to N-1.  The second dimension is: 'date', 'userid', 'username',
 * 'field','type','old_value','new_value'
 * @param integer $p_bug_id  A valid bug identifier or null to not filter by bug.  If no bug id is specified,
 *                           then returned array will have a field for bug_id, otherwise it won't.
 * @param integer $p_user_id A valid user identifier.
 * @param integer $p_start_time The start time to filter by, or null for all.
 * @param integer $p_end_time   The end time to filter by, or null for all.
 * @return array
 */
function history_get_raw_events_array($p_bug_id, $p_user_id = null, $p_start_time = null, $p_end_time = null)
{
    $t_user_id = null === $p_user_id ? auth_get_current_user_id() : $p_user_id;
    # grab history and display by date_modified then field_name
    # @@@ by MASC I guess it's better by id then by field_name. When we have more history lines with the same
    # date, it's better to respect the storing order otherwise we should risk to mix different information
    # I give you an example. We create a child of a bug with different custom fields. In the history of the child
    # bug we will find the line related to the relationship mixed with the custom fields (the history is creted
    # for the new bug with the same timestamp...)
    $t_result = history_get_range_result($p_bug_id, $p_start_time, $p_end_time);
    $t_raw_history = array();
    $j = 0;
    while (true) {
        $t_event = history_get_event_from_row($t_result, $t_user_id, true);
        if ($t_event === false) {
            break;
        }
        $t_raw_history[$j] = $t_event;
        $j++;
    }
    # end for loop
    return $t_raw_history;
}