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 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Controller_Dashboard_Workflow_List extends DashboardBaseController {
    
    public $helpers = array('form');
    

    public function delete($wfID = null, $token = null){
        try {
            $wf = Workflow::getByID($wfID); 
                
            if(!($wf instanceof Workflow)) {
                throw new Exception(t('Invalid workflow ID.'));
            }
    
            $valt = Loader::helper('validation/token');
            if (!$valt->validate('delete_workflow', $token)) {
                throw new Exception($valt->getErrorMessage());
            }
            
            $wf->delete();
            
            $this->redirect("/dashboard/workflow/list", 'workflow_deleted');
        } catch (Exception $e) {
            $this->error->add($e);
        }
        $this->view();
    }
    
    public function save_workflow_details() {
        if (!Loader::helper('validation/token')->validate('save_workflow_details')) {
            $this->error->add(Loader::helper('validation/token')->getErrorMessage());
        }
        $wfName = trim($this->post('wfName'));
        if (!$wfName) { 
            $this->error->add(t('You must give the workflow a name.'));
        }
        if (!Loader::helper('validation/strings')->alphanum($wfName, true)) {
            $this->error->add(t('Workflow Names must only include alphanumerics and spaces.'));
        }
        if (!$this->error->has()) {
            $wf = Workflow::getByID($this->post('wfID'));
            $wf->updateName($wfName);
            $wf->updateDetails($this->post());
            $this->redirect('/dashboard/workflow/list', 'view_detail', $this->post('wfID'), 'workflow_updated');
        } else {
            $this->view_detail($this->post('wfID'));
        }       
    }
    
    public function view() {
        $workflows = Workflow::getList();
        $this->set('workflows', $workflows);
    }
    
    public function add() {
        $types = array();
        $list = WorkflowType::getList();
        foreach($list as $wl) {
            $types[$wl->getWorkflowTypeID()] = $wl->getWorkflowTypeName();
        }
        $this->set('types', $types);
        $this->set('typeObjects', $list);
     }
    
    public function workflow_deleted() {
        $this->set("message", t('Workflow deleted successfully.'));
        $this->view();
    }
    
    public function submit_add() {
        if (!Loader::helper('validation/token')->validate('add_workflow')) {
            $this->error->add(Loader::helper('validation/token')->getErrorMessage());
        }
        $wfName = trim($this->post('wfName'));
        if (!$wfName) { 
            $this->error->add(t('You must give the workflow a name.'));
        }
        if (!Loader::helper('validation/strings')->alphanum($wfName, true)) {
            $this->error->add(t('Workflow Names must only include alphanumerics and spaces.'));
        }
        $db = Loader::db();
        $wfID = $db->getOne('SELECT wfID FROM Workflows WHERE wfName=?',array($wfName));
        if ($wfID) {
            $this->error->add(t('Workflow with that name already exists.'));
        }
        if (!$this->error->has()) { 
            $type = WorkflowType::getByID($this->post('wftID'));
            if (!is_object($type) || !($type instanceof WorkflowType)) {
                $this->error->add(t('Invalid Workflow Type.'));
                $this->add();
                return;
            }
            $wf = Workflow::add($type, $wfName);
            $wf->updateDetails($this->post());
            $this->redirect('/dashboard/workflow/list/', 'view_detail', $wf->getWorkflowID(), 'workflow_created');
        }
        $this->add();
    }
    
    public function edit_details($wfID = false) {
        $wf = Workflow::getByID($wfID);
        if (!is_object($wf)) {
            $this->redirect("/dashboard/workflow/list");
        }
        $this->set('wf', $wf);
    }

    
    public function view_detail($wfID = false, $message = false) {
        $wf = Workflow::getByID($wfID);
        if (!is_object($wf)) {
            $this->redirect("/dashboard/workflow/list");
        }
        switch($message) {
            case 'workflow_created':
                $this->set('message', t('Workflow created successfully. You may now modify its properties.'));
                break;
            case 'workflow_updated':
                $this->set('message', t('Workflow updated.'));
                break;
        }
        
        $this->set('wf', $wf);
    }
    
}