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 
<?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_WorkflowRequest extends Object {  
    
    protected $currentWP;
    protected $uID;
    protected $wrStatusNum = 0;
    
    public function __construct($pk) {
        $this->pkID = $pk->getPermissionKeyID();
    }
    
    public function getWorkflowRequestStatusNum() {
        return $this->wrStatusNum;
    }
    
    public function getWorkflowRequestID() { return $this->wrID;}
    public function getWorkflowRequestPermissionKeyID() {return $this->pkID;}
    public function getWorkflowRequestPermissionKeyObject() {
        return PermissionKey::getByID($this->pkID);
    }
    public function setCurrentWorkflowProgressObject(WorkflowProgress $wp) {
        $this->currentWP = $wp;
    }
    public function getCurrentWorkflowProgressObject() {
        return $this->currentWP;
    }
    public function setRequesterUserID($uID) {
        $this->uID = $uID;
    }
    public function getRequesterUserID() {
        return $this->uID;
    }
    
    public static function getByID($wrID) {
        $db = Loader::db();
        $wrObject = $db->getOne('select wrObject from WorkflowRequestObjects where wrID = ?', array($wrID));
        if ($wrObject) {
            $wr = unserialize($wrObject);
            return $wr;
        }
    }
    
    public function delete() {
        $db = Loader::db();
        $db->Execute('delete from WorkflowRequestObjects where wrID = ?', array($this->wrID));
    }
    
    public function save() {
        $db = Loader::db();
        if (!$this->wrID) {
            $wrObject = '';
            $db->Execute('insert into WorkflowRequestObjects (wrObject) values (?)', array($wrObject));
            $this->wrID = $db->Insert_ID();
        }
        $wrObject = serialize($this);
        $db->Execute('update WorkflowRequestObjects set wrObject = ? where wrID = ?', array($wrObject, $this->wrID));
    }

        
    /** 
     * Triggers a workflow request, queries a permission key to see what workflows are attached to it
     * and initiates them
     * @return optional WorkflowProgress
     */
    protected function trigger($pk) {
        if (!$this->wrID) {
            $this->save();
        }
        
        if (!$pk->canPermissionKeyTriggerWorkflow()) { 
            throw new Exception(t('This permission key cannot start a workflow.'));
        }
        
        $pa = $pk->getPermissionAccessObject();
        $workflows = array();
        $workflowsStarted = 0;
        if (is_object($pa)) {
            $workflows = $pa->getWorkflows();   
            foreach($workflows as $wf) {
                if ($wf->validateTrigger($this)) {
                    $this->addWorkflowProgress($wf);
                    $workflowsStarted++;
                }
            }
        }

        if ($workflowsStarted == 0) {
            $defaultWorkflow = new EmptyWorkflow();
            $wp = $this->addWorkflowProgress($defaultWorkflow);
            return $wp->getWorkflowProgressResponseObject();
        }
        
    }
    
    abstract public function addWorkflowProgress(Workflow $wf);
    abstract public function getWorkflowRequestDescriptionObject();
    abstract public function getWorkflowRequestStyleClass();
    abstract public function getWorkflowRequestApproveButtonText();
    abstract public function getWorkflowRequestApproveButtonClass();
    abstract public function getWorkflowRequestApproveButtonInnerButtonRightHTML();

    public function getWorkflowRequestAdditionalActions(WorkflowProgress $wp) {
        return array();
    }
    
    public function runTask($task, WorkflowProgress $wp) {
        if (method_exists($this, $task)) {
            if ($task == 'approve') {
                // we check to see if any other outstanding workflowprogress requests have this id
                // if they don't we proceed
                $db = Loader::db();
                $num = $db->GetOne('select count(wpID) as total from WorkflowProgress where wpID <> ? and wrID = ? and wpIsCompleted = 0', array(
                    $wp->getWorkflowProgressID(), $this->getWorkflowRequestID()
                ));
                if ($num == 0) {
                    $wpr = call_user_func_array(array($this, $task), array($wp));
                    return $wpr;
                }
            }
        }
    }

}