workflowsv2.php.tmp
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 1,695 行 · 第 1/5 页
TMP
1,695 行
'fail_action' => 'edittransition', 'cancel_action' => 'basic', )); $oForm->setWidgets(array( array('ktcore.widgets.string', array( 'name' => 'name', 'label' => _kt('Transition Name'), '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". Transition names must be unique within the workflow (e.g. within this workflow, you can only have one transition called "publish")'), 'required' => true, 'value' => sanitizeForHTML($oTransition->getName()), )), )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'name', 'output' => 'name', )), )); return $oForm; } function do_edittransition() { $this->aBreadcrumbs[] = array( 'name' => $this->oTransition->getHumanName(), ); // remember that we check for state, // and its null if none or an error was passed. if (is_null($this->oTransition)) { $this->errorRedirectTo('basic', _kt("No transition specified.")); } $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/edit_transition'); $this->oPage->setBreadcrumbDetails(_kt('Manage Transition')); $oForm = $this->form_edittransition($this->oTransition); $oTemplate->setData(array( 'context' => $this, 'edit_form' => $oForm, )); return $oTemplate->render(); } function do_savetransition() { $oForm = $this->form_edittransition($this->oTransition); $res = $oForm->validate(); $data = $res['results']; $errors = $res['errors']; $extra_errors = array(); // check if any *other* states have this name. if ($data['name'] == $this->oTransition->getName()) { $this->successRedirectTo('edittransition',_kt("No change in name.")); } // otherwise we're looking for something different if there's a conflict. if (KTWorkflowTransition::nameExists($data['name'], $this->oWorkflow)) { $extra_errors['name'][] = _kt('There is already a transition with that name in this workflow.'); } if (!empty($errors) || !empty($extra_errors)) { $oForm->handleError(null, $extra_errors); } $this->startTransaction(); $this->oTransition->setName($data['name']); $this->oTransition->setHumanName($data['name']); $res = $this->oTransition->update(); if (PEAR::isError($res)) { $oForm->handleError(sprintf(_kt("Unable to update transition: %s"), $res->getMessage())); } $this->successRedirectTo('basic', _kt("Transition updated.")); } function do_deletetransition() { $this->startTransaction(); if (is_null($this->oTransition)) { return $this->errorRedirectTo("basic", _kt("No transition selected")); } // grab all the triggers $aTriggers = KTWorkflowTriggerInstance::getByTransition($this->oTransition); foreach ($aTriggers as $oTrigger) { $res = $oTrigger->delete(); if (PEAR::isError($res)) { $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear trigger: %s"), $res->getMessage())); } } $res = $this->oTransition->delete(); if (PEAR::isError($res)) { $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear transition: %s"), $res->getMessage())); } $this->successRedirectTo('basic', _kt("Transition deleted.")); } function form_deletestate() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt("Delete Existing State"), 'identifier' => 'ktcore.workflow.deletestate', 'action' => 'deletestate', 'cancel_action' => 'basic', 'fail_action' => 'replacestate', 'submit_label' => _kt("Delete State"), 'context' => $this, )); $other_states = sprintf('id != %d', $this->oState->getId()); $other_states .= sprintf(' AND workflow_id = %d', $this->oWorkflow->getId()); $oForm->setWidgets(array( array('ktcore.widgets.entityselection', array( 'vocab' => KTWorkflowState::getList($other_states), 'label' => _kt("Replacement State"), 'description' => _kt("In order to remove this state from the system, please select a new state which will take its place. All references to the state you are deleting will be replaced by this new state."), 'important_description' => _kt("All references will be changed, including on old documents."), 'label_method' => 'getName', 'name' => 'replacement', 'required' => true, )), )); $oForm->setValidators(array( array('ktcore.validators.entity', array( 'test' => 'replacement', 'output' => 'replacement', 'class' => 'KTWorkflowState', )), )); return $oForm; } function do_replacestate() { $this->breadcrumbs_basic(); $this->oPage->setBreadcrumbDetails(_kt("Delete State")); $oForm = $this->form_deletestate(); return $oForm->renderPage(_kt("Delete State")); } function do_deletestate() { $oForm = $this->form_deletestate(); $res = $oForm->validate(); $errors = $res['errors']; $data = $res['results']; if (!empty($errors)) { return $oForm->handleError(); } $this->startTransaction(); if (is_null($this->oState)) { return $this->errorRedirectTo("basic", _kt("No state selected")); } $replacement = $data['replacement']; KTWorkflowUtil::replaceState($this->oState, $replacement); if ($this->oWorkflow->getStartStateId() == $this->oState->getId()) { $this->oWorkflow->setStartStateId($replacement->getId()); $res = $this->oWorkflow->update(); if (PEAR::isError($res)) { $this->errorRedirectTo("basic", sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); } } $res = $this->oState->delete(); if (PEAR::isError($res)) { $this->errorRedirectTo("basic", sprintf(_kt("Failed to delete state: %s"), $res->getMessage())); } $this->successRedirectTo('basic', _kt("State deleted.")); } function breadcrumbs_security() { $this->aBreadcrumbs[] = array( 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("fTransitionId=&fStateId=","security", true)), 'name' => _kt("Security"), ); } // ----------------- Security --------------------- function do_security() { $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/security_overview'); $this->breadcrumbs_security(); $oTemplate->setData(array( 'context' => $this, 'workflow_name' => $this->oWorkflow->getName(), )); return $oTemplate->render(); } // == PERMISSIONS function do_permissionsoverview() { $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/permissions_overview'); $this->breadcrumbs_security(); $this->oPage->setBreadcrumbDetails(_kt("Permissions Overview")); // we want to give a complete overview. // this involves a grid of: // permission permissions // state x - // state - x $aStates = KTWorkflowState::getByWorkflow($this->oWorkflow); $aUsefulPermissions = KTPermission::getDocumentRelevantList(); $aPermissionGrid = array(); $aControllers = array(); foreach ($aStates as $oState) { $perms = array(); $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($oState); $aControllers[$oState->getId()] = (!empty($aStatePermAssigns)); foreach ($aStatePermAssigns as $oPermAssign) { $perms[$oPermAssign->getPermissionId()] = $oPermAssign; // we only care about non-null in *this* map. } $aPermissionGrid[$oState->getId()] = $perms; } $oTemplate->setData(array( 'context' => $this, 'controllers' => $aControllers, 'perm_grid' => $aPermissionGrid, 'perms' => $aUsefulPermissions, 'states' => $aStates, )); return $oTemplate->render(); } function form_managepermissions() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt("Controlled Permissions"), 'submit_label' => _kt("Set controlled permissions"), 'action' => 'setcontrolledpermissions', 'fail_action' => 'managepermissions', 'cancel_action' => 'permissionsoverview', 'context' => $this, )); return $oForm; } // == PERMISSIONS function do_managepermissions() { $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/managepermissions'); $oForm = $this->form_managepermissions(); $this->breadcrumbs_security(); $this->aBreadcrumbs[] = array( 'name' => _kt("Document Permissions"), 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("fStateId=","permissionsoverview",true)), ); $this->aBreadcrumbs[] = array( 'name' => $this->oState->getHumanName(), 'url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managepermissions",true)), ); $this->oPage->setBreadcrumbDetails(_kt("Manage Permissions")); $aUsefulPermissions = KTPermission::getDocumentRelevantList(); $aPermissionGrid = array(); $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState); foreach ($aStatePermAssigns as $oPermAssign) { $aPermissionGrid[$oPermAssign->getPermissionId()] = $oPermAssign; } $oTemplate->setData(array( 'context' => $this, 'perm_grid' => $aPermissionGrid, 'perms' => $aUsefulPermissions, 'form' => $oForm, )); return $oTemplate->render(); } function do_setcontrolledpermissions() { $active = (array) KTUtil::arrayGet($_REQUEST, 'fControlled'); $aUsefulPerms = KTPermission::getDocumentRelevantList(); $aStatePermAssigns = KTWorkflowStatePermissionAssignment::getByState($this->oState); $aStatePermAssigns = KTUtil::keyArray($aStatePermAssigns, 'getPermissionId'); $assigns = array(); $this->startTransaction(); // delete those who don't know want // create those we don't have. foreach ($aStatePermAssigns as $perm_id => $assign) { if (!$active[$perm_id]) { $assign->delete(); } } $emptydescriptor = KTPermissionUtil::getOrCreateDescriptor(array()); if (PEAR::isError($emptydescriptor)) { $this->errorRedirectTo("managepermissions", sprintf(_kt("Failed to create assignment: %s"), $emptydescriptor->getMessage())); } foreach ($active as $perm_id => $discard) { if (!$aStatePermAssigns[$perm_id]) { $assign = KTWorkflowStatePermissionAssignment::createFromArray(array( "iStateId" => $this->oState->getId(), "iPermissionId" => $perm_id, "iDescriptorId" => $emptydescriptor->getId(), )); if (PEAR::isError($assign)) { $this->errorRedirectTo("managepermissions", sprintf(_kt("Failed to create assignment: %s"), $assign->getMessage())); } } } $this->successRedirectTo("managepermissions", _kt("Controlled permission updated.")); } // == PERMISSIONS function do_allocatepermissions() { $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/allocate_permissions'); $oForm = $this->form_managepermissions(); $this->breadcrumbs_security(); $this->aBreadcrumbs[] = array( 'name' => _kt("Document Permissions"),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?