public function getWorkflowFor($item, $includeComplete = false)
    {
        $id = $item;

        if ($item instanceof WorkflowAction) {
            $id = $item->WorkflowID;
            return DataObject::get_by_id(WorkflowInstance::class, $id);
        } elseif (is_object($item) && ($item->hasExtension(WorkflowApplicable::class)
                || $item->hasExtension(FileWorkflowApplicable::class))
        ) {
            $filter = sprintf(
                '"TargetClass" = \'%s\' AND "TargetID" = %d',
                Convert::raw2sql(ClassInfo::baseDataClass($item)),
                $item->ID
            );
            $complete = $includeComplete ? 'OR "WorkflowStatus" = \'Complete\' ' : '';
            return DataObject::get_one(
                WorkflowInstance::class,
                $filter . ' AND ("WorkflowStatus" = \'Active\' OR "WorkflowStatus"=\'Paused\' ' . $complete . ')'
            );
        }
    }
public function getWorkflowFor($item, $includeComplete = false)
    {
        $id = $item;

        if ($item instanceof WorkflowAction) {
            $id = $item->WorkflowID;
            return DataObject::get_by_id(WorkflowInstance::class, $id);
        } elseif (is_object($item) && ($item->hasExtension(WorkflowApplicable::class)
                || $item->hasExtension(FileWorkflowApplicable::class))
        ) {
            $filter = sprintf(
                '"TargetClass" = \'%s\' AND "TargetID" = %d',
                Convert::raw2sql(ClassInfo::baseDataClass($item)),
                $item->ID
            );
            $complete = $includeComplete ? 'OR "WorkflowStatus" = \'Complete\' ' : '';
            return DataObject::get_one(
                WorkflowInstance::class,
                $filter . ' AND ("WorkflowStatus" = \'Active\' OR "WorkflowStatus"=\'Paused\' ' . $complete . ')'
            );
        }
    }
public function getWorkflowFor ( $ item , $ includeComplete = false ) { $ id = $ item ; if ( $ item instanceof WorkflowAction ) { $ id = $ item -> WorkflowID ; return DataObject :: get_by_id ( WorkflowInstance :: class , $ id ) ; } elseif ( is_object ( $ item ) && ( $ item -> hasExtension ( WorkflowApplicable :: class ) || $ item -> hasExtension ( FileWorkflowApplicable :: class ) ) ) { $ filter = sprintf ( '"TargetClass" = \'%s\' AND "TargetID" = %d' , Convert :: raw2sql ( ClassInfo :: baseDataClass ( $ item ) ) , $ item -> ID ) ; $ complete = $ includeComplete ? 'OR "WorkflowStatus" = \'Complete\' ' : '' ; return DataObject :: get_one ( WorkflowInstance :: class , $ filter . ' AND ("WorkflowStatus" = \'Active\' OR "WorkflowStatus"=\'Paused\' ' . $ complete . ')' ) ; } }
Gets the workflow for the given item

The item can be

a data object in which case the ActiveWorkflow will be returned,
an action, in which case the Workflow will be returned
an integer, in which case the workflow with that ID will be returned

@param mixed $item
@param bool $includeComplete
@return WorkflowInstance|null
Gets the workflow for the given item