The attached patch allows one to display the date a node entered a certain workflow state within a view. An example case for this would be a site that may have a "Completed" workflow state defined. In a particular view, they need to display the date a node was completed if it is in the "Completed" state.

I would entertain other suggestions on how to format the date, since the option view field is currently being used to define which workflow state to display the date. This patch defines some basic date formats as individual handlers... (short date, small, medium, large date).

Comments

viil’s picture

Version: 5.x-2.3 » 6.x-1.4
Priority: Normal » Major

Unfortunately the patch shared by v1nce is outdated as it was developed for an older version of workflow.

I have the same problem: the node's current workflow state time stamp (which is found in the "workflow_node" table in the db as "stamp") is not accessible as a field in views.

Making the current workflow state's time stamp accessible to views could also help fix the issues of duplicates that so many others have been reporting, as the only workflow time stamps currently available to views are the ones from workflow revisions and scheduled workflows. See workflow: Previous time views field results in duplicate nodes, Adding workflow: previous comment to fields duplicates nodes in view results

viil’s picture

Status: Needs review » Patch (to be ported)

I've patched my workflow.views.inc file so that views can access the stamp field data in the workflow_node table to get the time stamp of the current workflow state.

after the following lines of code:

  // state
  $data['workflow_node']['sid'] = array(
    'title' => t('Current state'), // Appears in views UI.
    'help' => t('The current workflow state that the node is in.'),
    'field' => array(
      'handler' => 'workflow_views_handler_field_sid',
      'click sortable' => TRUE,
     ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'click sortable' => TRUE,
      'numeric' => TRUE,
    ),
    'filter' => array(
      'handler' => 'workflow_views_handler_filter_sid',
      'numeric' => TRUE,
    ),
  );

I added the following lines of code:

  // time
  $data['workflow_node']['stamp'] = array(
    'title' => t('Current time'), // appears in views ui.
    'help' => t('the time at which the node moved to the current state.'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => true,
     ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
      'numeric' => true,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
  );
zroger’s picture

Title: Views Field For Workflow Node Stamp » Views integration for current workflow timestamp
Status: Patch (to be ported) » Needs review
StatusFileSize
new919 bytes

Here's a patch that adds workflow_node.stamp in a similar manner as workflow_node_history.stamp, like viil did in #2.

jvandyk’s picture

Status: Needs review » Fixed

The patch in #3 was straightforward and worked well in the views I created and tested. Committed. Will appear in 6.x-1.5.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

telegraph’s picture

I'm trying to build on this patch a little further. I would need the workflow node stamp available as an argument in views. Inspiring myself from the patch above I came up with this:

  // time
  $data['workflow_node']['stamp'] = array(
    'title' => t('Current time'), // Appears in views UI.
    'help' => t('The time at which the node moved to the current state.'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
     ),
  'argument' => array(
      'field' => 'stamp',
      'handler' => 'views_handler_argument_node_created_year_month',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
      'numeric' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
  );

So far, so good, the argument works, but the record count that is supposed to go with the functionality only ever returns '1' ( as opposed to the amount of entries it finds with regards to the argument).
Would someone have an idea of how I can get it to return the proper count?

Cheers,

telegraph’s picture

Status: Needs review » Closed (fixed)
StatusFileSize
new605 bytes

Yay, I got it! I even created a patch for it :). #6 is actually the wrong place to add code, so please disregard. The solution is to create a new entry in that file, which is:

  // time
  $data['workflow_node']['workflow_transition_year_month'] = array(
    'title' => t('Workflow transition year + month'),
    'help' => t('In the form of YYYYMM.'),
    'argument' => array(
      'field' => 'stamp',
      'handler' => 'views_handler_argument_node_created_year_month',
    ),
  );

This patch lets you pass an argument for the workflow transition date (stamp) in the form of YYYYMM.
I've never submitted a patch before, so here goes.

telegraph’s picture

Status: Closed (fixed) » Needs review
johnv’s picture

Component: Code » Views
Status: Closed (fixed) » Needs review
johnv’s picture

Issue summary: View changes
Status: Needs review » Fixed

This issue was already fixed.
@telegraph, I opened a follow-up issue #2147471: Add views argument for "Workflow: current time" with your patch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.