This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
/**
 * @package Workflow
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2012 concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
abstract class Concrete5_Model_Workflow extends Object {  
    
    protected $wfID = 0;
    protected $allowedTasks = array('cancel', 'approve');
    protected $restrictedToPermissionKeyHandles = array();
    
    public function getAllowedTasks() {return $this->allowedTasks;}
    
    public function getWorkflowID() {return $this->wfID;}
    public function getWorkflowName() {return $this->wfName;}
    public function getWorkflowTypeObject() {
        return WorkflowType::getByID($this->wftID);
    }
    public function getRestrictedToPermissionKeyHandles() {
        return $this->restrictedToPermissionKeyHandles;
    }
    
    public function getPermissionObjectIdentifier() {
        return $this->getWorkflowID();
    }

    public function delete() {
        $db = Loader::db();
        $db->Execute('delete from Workflows where wfID = ?', array($this->wfID));

        foreach (
            $db->GetArray(
                'select wpID from WorkflowProgress where wfID = ?',
                array($this->wfID)
            )
            as $row
        ) {
            $wfp = WorkflowProgress::getByID($row['wpID']);
            if ($wfp) {
                $wfp->delete();
            }
        }

    }

    // by default the basic workflow just passes the status num from the request
    // we do this so that we can order things by most important, etc...
    public function getWorkflowProgressCurrentStatusNum(WorkflowProgress $wp) {
        $req = $wp->getWorkflowRequestObject();
        if (is_object($req)) { 
            return $req->getWorkflowRequestStatusNum();
        }
    }
    
    
    public static function getList() {
        $workflows = array();
        $db = Loader::db();
        $r = $db->Execute("select wfID from Workflows order by wfName asc");
        while ($row = $r->FetchRow()) {
            $wf = Workflow::getByID($row['wfID']);
            if (is_object($wf)) {
                $workflows[] = $wf;
            }   
        }
        return $workflows;
    }
    
    public static function add(WorkflowType $wt, $name) {
        $db = Loader::db();
        $wfID = $db->getOne('SELECT wfID FROM Workflows WHERE wfName=?',array($name));
        if (!$wfID) {
            $db->Execute('insert into Workflows (wftID, wfName) values (?, ?)', array($wt->getWorkflowTypeID(), $name));
            $wfID = $db->Insert_ID();
        }
        return self::getByID($wfID);
    }
    
    protected function load($wfID) {
        $db = Loader::db();
        $r = $db->GetRow('select Workflows.* from Workflows where Workflows.wfID = ?', array($wfID));
        $this->setPropertiesFromArray($r);
    }
    
    public static function getByID($wfID) {
        $db = Loader::db();
        $r = $db->GetRow('select WorkflowTypes.wftHandle, WorkflowTypes.pkgID from Workflows inner join WorkflowTypes on Workflows.wftID = WorkflowTypes.wftID where Workflows.wfID = ?', array($wfID));
        if ($r['wftHandle']) { 
            $class = Loader::helper('text')->camelcase($r['wftHandle']) . 'Workflow';
            if (!class_exists($class)) {
                exit;
            }
            $obj = new $class();
            $obj->load($wfID);
            if ($obj->getWorkflowID() > 0) { 
                $obj->loadDetails();
                return $obj;
            }
        }
    }

    public function getWorkflowToolsURL($task) {
        $type = $this->getWorkflowTypeObject();
        $uh = Loader::helper('concrete/urls');
        $url = $uh->getToolsURL('workflow/types/' . $type->getWorkflowTypeHandle(), $type->getPackageHandle());
        $url .= '?wfID=' . $this->getWorkflowID() . '&task=' . $task . '&' . Loader::helper('validation/token')->getParameter($task);
        return $url;
    }
    
    public function updateName($wfName) {
        $db = Loader::db();
        $db->Execute('update Workflows set wfName = ? where wfID = ?', array($wfName, $this->wfID));
    }
    
    abstract public function start(WorkflowProgress $wp);
    abstract public function getWorkflowProgressActions(WorkflowProgress $wp);
    abstract public function getWorkflowProgressCurrentDescription(WorkflowProgress $wp);
    abstract public function getWorkflowProgressStatusDescription(WorkflowProgress $wp);
    abstract public function canApproveWorkflowProgressObject(WorkflowProgress $wp);
    abstract public function updateDetails($vars);
    abstract public function loadDetails();
    
    public function getPermissionAccessObject() {
        return false;
    }
    public function validateTrigger(WorkflowRequest $req) {
        return true;
    }
}