workflowsv2.php.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 1,695 行 · 第 1/5 页

SVN-BASE
1,695
字号
            	if($oTransition->getId() == $iCurrentId)            	{            		$res = KTWorkflowAdminUtil::saveTransitionSources($oTransition, $source_state_ids);            	}			}            if (PEAR::isError($res)) {                $this->errorRedirectTo('basic', sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage()));            }        }        $this->successRedirectTo('basic', _kt("Workflow process updated."));    }    function form_addstates() {        $oForm = new KTForm;        $oForm->setOptions(array(            'context' => $this,            'label' => _kt("Add New States"),            'submit_label' => _kt("Add States"),            'action' => 'createstates',            'cancel_action' => 'basic',            'fail_action' => 'addstates',        ));        $oForm->setWidgets(array(            array('ktcore.widgets.text',array(                'label' => _kt('New States'),                'description' => _kt('As documents progress through their lifecycle, they pass through a number of <strong>states</strong>.  These states describe a step in the process the document must follow.  Examples of states include "reviewed","submitted" or "pending".  Note that the first state you list is the one in which documents will start the workflow - this can be changed later on.'),                'important_description' => _kt('Please enter a list of states, one per line.  State names must be unique, and this includes states already in this workflow.'),                'required' => true,                'name' => 'states',                'rows' => 15,            )),        ));        $oForm->setValidators(array(            array('ktcore.validators.string', array(                'test' => 'states',                'output' => 'states',                'max_length' => 9999,            )),        ));        return $oForm;    }    function do_addstates() {        $oForm = $this->form_addstates();        $this->breadcrumbs_basic();        $this->oPage->setBreadcrumbDetails(_kt("Add States"));        $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/add_states');        $oTemplate->setData(array(            'context' => $this,            'form' => $oForm        ));        return $oTemplate->render();    }    function do_createstates() {        $oForm = $this->form_addstates();        $res = $oForm->validate();        $data = $res['results'];        $errors = $res['errors'];        $extra_errors = array();        // we want to check for duplicates, empties, etc.        $initial_states = (array) explode("\n", $data['states']);        $failed = array();        $old_states = array();        $states = array();        foreach ($initial_states as $sName) {            $state_name = trim($sName);            if (empty($state_name)) {                continue;            }            if ($states[$state_name]) {                $failed[] = $state_name;                continue;            }            // check for pre-existing states.            $exists = KTWorkflowState::nameExists($sName, $this->oWorkflow);            if ($exists) {                $old_states[] = $sName;            }            $states[$state_name] = $state_name;        }        if (empty($states)) {            $extra_errors['states'][] = _kt('You must provide at least one state name.');        }        if (!empty($failed)) {            $extra_errors['states'][] = sprintf(_kt("You cannot have duplicate state names: %s"), implode(', ', $failed));        }        if (!empty($old_states)) {            $extra_errors['states'][] = sprintf(_kt("You cannot use state names that are in use: %s"), implode(', ', $old_states));        }        // handle any errors.        if (!empty($errors) || !empty($extra_errors)) {            $oForm->handleError(null, $extra_errors);        }        $this->startTransaction();        // now act        foreach ($states as $state_name) {            $oState = KTWorkflowState::createFromArray(array(                'workflowid' => $this->oWorkflow->getId(),                'name' => $state_name,                'humanname' => $state_name,            ));            if (PEAR::isError($oState)) {                $oForm->handleError(sprintf(_kt("Unexpected failure creating state: %s"), $oState->getMessage()));            }        }        $this->successRedirectTo('basic', _kt("New States Created."));    }    function form_addtransitions() {        $oForm = new KTForm;        $oForm->setOptions(array(            'context' => $this,            'label' => _kt("Add New Transitions"),            'submit_label' => _kt("Add Transitions"),            'action' => 'createtransitions',            'cancel_action' => 'basic',            'fail_action' => 'addtransitions',        ));        $oForm->setWidgets(array(            array('ktcore.widgets.text',array(                'label' => _kt('Transitions'),                'description' => _kt('In order to move between states, users will cause "transitions" to occur.  These transitions represent processes followed, e.g. "review document", "distribute invoice" or "publish".  You\'ll assign transitions to states in the next step.'  ),                'important_description' => _kt('Please enter a list of transitions, one per line.  Transition names must be unique.'),                'required' => false,                'name' => 'transitions',            )),        ));        $oForm->setValidators(array(            array('ktcore.validators.string', array(                'test' => 'transitions',                'output' => 'transitions',                'max_length' => 9999,            )),        ));        return $oForm;    }    function do_addtransitions() {        $oForm = $this->form_addtransitions();        $this->breadcrumbs_basic();        $this->oPage->setBreadcrumbDetails(_kt("Add Transitions"));        $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/add_transitions');        $oTemplate->setData(array(            'context' => $this,            'form' => $oForm        ));        return $oTemplate->render();    }    function do_createtransitions() {        $oForm = $this->form_addtransitions();        $res = $oForm->validate();        $data = $res['results'];        $errors = $res['errors'];        $extra_errors = array();        // we want to check for duplicates, empties, etc.        $initial_transitions = (array) explode("\n", $data['transitions']);        $failed = array();        $old_transitions = array();        $transitions = array();        foreach ($initial_transitions as $sName) {            $transition_name = trim($sName);            if (empty($transition_name)) {                continue;            }            if ($transitions[$transition_name]) {                $failed[] = $transition_name;                continue;            }            // check for pre-existing states.            $exists = KTWorkflowTransition::nameExists($sName, $this->oWorkflow);            if ($exists) {                $old_transitions[] = $sName;            }            $transitions[$transition_name] = $transition_name;        }        if (empty($transitions)) {            $extra_errors['transitions'][] = _kt('You must provide at least one transition name.');        }        if (!empty($failed)) {            $extra_errors['transitions'][] = sprintf(_kt("You cannot have duplicate transition names: %s"), implode(', ', $failed));        }        if (!empty($old_states)) {            $extra_errors['transitions'][] = sprintf(_kt("You cannot use transition names that are in use: %s"), implode(', ', $old_transitions));        }        // handle any errors.        if (!empty($errors) || !empty($extra_errors)) {            $oForm->handleError(null, $extra_errors);        }        $this->startTransaction();        $transition_ids = array();        $oState = KTWorkflowState::get($this->oWorkflow->getStartStateId());        foreach ($transitions as $transition_name) {            $oTransition = KTWorkflowTransition::createFromArray(array(                "WorkflowId" => $this->oWorkflow->getId(),                "Name" => $transition_name,                "HumanName" => $transition_name,                "TargetStateId" => $oState->getId(),                "GuardPermissionId" => null,                "GuardGroupId" => null,                "GuardRoleId" => null,                "GuardConditionId" => null,            ));            if (PEAR::isError($oTransition)) {                $oForm->handleError(sprintf(_kt("Unexpected failure creating transition: %s"), $oTransition->getMessage()));            }            $transition_ids[] = $oTransition->getId();        }        $transition_ids_query = array();        foreach ($transition_ids as $id) {            $transition_ids_query[] = sprintf('transition_ids[%s]=%s',$id,  $id);        }        $transition_ids_query = implode('&', $transition_ids_query);        $this->successRedirectTo('transitionconnections', _kt("New Transitions Created."), $transition_ids_query);    }    function form_editstate($oState) {        $oForm = new KTForm;        $oForm->setOptions(array(            'context' => $this,            'label' => _kt('Edit State'),            'submit_label' => _kt('Update State'),            'action' => 'savestate',            'fail_action' => 'editstate',            'cancel_action' => 'basic',        ));        $oForm->setWidgets(array(            array('ktcore.widgets.string', array(                'name' => 'name',                'label' => _kt('State Name'),                'description' => _kt('As documents progress through their lifecycle, they pass through a number of <strong>states</strong>.  These states describe a step in the process the document must follow.  Examples of states include "reviewed","submitted" or "pending".  State names must be unique, and this includes states already in this workflow.'),                'required' => true,                'value' => sanitizeForHTML($oState->getName()),            )),        ));        $oForm->setValidators(array(            array('ktcore.validators.string', array(                'test' => 'name',                'output' => 'name',            )),        ));        return $oForm;    }    function do_editstate() {        $this->aBreadcrumbs[] = array(            'name' => $this->oState->getHumanName(),        );        // remember that we check for state,        // and its null if none or an error was passed.        if (is_null($this->oState)) {            $this->errorRedirectTo('basic', _kt("No state specified."));        }        $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_state');        $this->oPage->setBreadcrumbDetails(_kt('Manage State'));        $oForm = $this->form_editstate($this->oState);        $oTemplate->setData(array(            'context' => $this,            'edit_form' => $oForm,        ));        return $oTemplate->render();    }    function do_savestate() {        $oForm = $this->form_editstate($this->oState);        $res = $oForm->validate();        $data = $res['results'];        $errors = $res['errors'];        $extra_errors = array();        // check if any *other* states have this name.        if ($data['name'] == $this->oState->getName()) {            $this->successRedirectTo('editstate',_kt("No change in name."));        }        // otherwise we're looking for something different if there's a conflict.        if (KTWorkflowState::nameExists($data['name'], $this->oWorkflow)) {            $extra_errors['name'][] = _kt('There is already a state with that name in this workflow.');        }        if (!empty($errors) || !empty($extra_errors)) {            $oForm->handleError(null, $extra_errors);        }        $this->startTransaction();        $this->oState->setName($data['name']);        $this->oState->setHumanName($data['name']);        $res = $this->oState->update();        if (PEAR::isError($res)) {            $oForm->handleError(sprintf(_kt("Unable to update state: %s"), $res->getMessage()));        }        $this->successRedirectTo('basic', _kt("State updated."));    }    function form_edittransition($oTransition) {        $oForm = new KTForm;        $oForm->setOptions(array(            'context' => $this,            'label' => _kt('Edit Transition'),            'submit_label' => _kt('Update Transition'),            'action' => 'savetransition',

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?