/** * @param FieldType $fieldType * @return array */ private static function getDocumentSelectFields(FieldType $fieldType) { $runtime = \CBPRuntime::getRuntime(); $runtime->startRuntime(); $documentService = $runtime->getService("DocumentService"); $result = array(); $fields = $documentService->getDocumentFields($fieldType->getDocumentType()); foreach ($fields as $key => $field) { if ($field['Type'] == 'select' && substr($key, -10) != '_PRINTABLE') { $result[$key] = $field; } } return $result; }
protected function getBizprocData() { $userId = $this->getUser()->getID(); $currentUserGroups = $this->getUser()->getUserGroupArray(); if (!$this->lists['ELEMENT_FIELDS'] || $this->lists['ELEMENT_FIELDS']['CREATED_BY'] == $userId) { $currentUserGroups[] = 'Author'; } $documentType = 'iblock_' . $this->iblockId; CBPDocument::addShowParameterInit('lists', 'only_users', $documentType); $this->lists['BIZPROC_FIELDS'] = array(); $bizprocIndex = 0; $documentStates = CBPDocument::getDocumentStates(array('lists', 'BizprocDocument', $documentType), null); $runtime = CBPRuntime::getRuntime(); $runtime->startRuntime(); $documentService = $runtime->getService('DocumentService'); foreach ($documentStates as $documentState) { $bizprocIndex++; $viewWorkflow = CBPDocument::CanUserOperateDocumentType(CBPCanUserOperateOperation::StartWorkflow, $userId, array('lists', 'BizprocDocument', $documentType), array('sectionId' => 0, 'AllUserGroups' => $currentUserGroups, 'DocumentStates' => $documentStates, 'WorkflowId' => $documentState['ID'] > 0 ? $documentState['ID'] : $documentState['TEMPLATE_ID'])); if ($viewWorkflow) { $templateId = intval($documentState['TEMPLATE_ID']); $workflowParameters = $documentState['TEMPLATE_PARAMETERS']; if (!is_array($workflowParameters)) { $workflowParameters = array(); } if (strlen($documentState["ID"]) <= 0 && $templateId > 0) { $parametersValues = array(); $keys = array_keys($workflowParameters); foreach ($keys as $key) { $value = $workflowParameters[$key]["Default"]; if (!is_array($value)) { $parametersValues[$key] = htmlspecialcharsbx($value); } else { $keys1 = array_keys($value); foreach ($keys1 as $key1) { $parametersValues[$key][$key1] = htmlspecialcharsbx($value[$key1]); } } } foreach ($workflowParameters as $parameterKey => $arParameter) { $parameterKeyExt = "bizproc" . $templateId . "_" . $parameterKey; $html = $documentService->GetFieldInputControl(array('lists', 'BizprocDocument', $documentType), $arParameter, array("Form" => "start_workflow_form1", "Field" => $parameterKeyExt), $parametersValues[$parameterKey], false, true); $this->lists['BIZPROC_FIELDS'][$parameterKeyExt . $bizprocIndex] = array("id" => $parameterKeyExt . $bizprocIndex, "required" => $arParameter["Required"], "name" => $arParameter["Name"], "title" => $arParameter["Description"], "type" => "custom", "value" => $html, 'show' => 'Y'); } } } } }
public static function onTaskChange($documentId, $taskId, $taskData, $status) { CListsLiveFeed::setMessageLiveFeed($taskData['USERS'], $documentId, $taskData['WORKFLOW_ID'], false); if ($status == CBPTaskChangedStatus::Delegate) { $runtime = CBPRuntime::getRuntime(); /** * @var CBPAllStateService $stateService */ $stateService = $runtime->getService('StateService'); $stateService->setStatePermissions($taskData['WORKFLOW_ID'], array('R' => array('user_' . $taskData['USERS'][0])), array('setMode' => CBPSetPermissionsMode::Hold, 'setScope' => CBPSetPermissionsMode::ScopeDocument)); } }
protected function getData() { $this->arResult['SHOW_MODE'] = 'SelectWorkflow'; $this->arResult['TEMPLATES'] = array(); $this->arResult['PARAMETERS_VALUES'] = array(); $this->arResult['ERROR_MESSAGE'] = ''; $runtime = CBPRuntime::getRuntime(); $runtime->startRuntime(); $this->arResult['DocumentService'] = $runtime->getService('DocumentService'); foreach ($this->arResult['DOCUMENT_DATA'] as $nameModule => $data) { $workflowTemplateObject = CBPWorkflowTemplateLoader::getList(array(), array('DOCUMENT_TYPE' => $data['DOCUMENT_TYPE'], 'ACTIVE' => 'Y'), false, false, array('ID', 'NAME', 'DESCRIPTION', 'MODIFIED', 'USER_ID', 'PARAMETERS')); while ($workflowTemplate = $workflowTemplateObject->getNext()) { if (!CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getID(), $data['DOCUMENT_ID'], array())) { continue; } if ($nameModule == 'DISK') { $this->arResult['TEMPLATES'][$workflowTemplate['ID']] = $workflowTemplate; $this->arResult['TEMPLATES'][$workflowTemplate['ID']]['URL'] = htmlspecialcharsex($this->getApplication()->getCurPageParam('workflow_template_id=' . $workflowTemplate['ID'] . '&' . bitrix_sessid_get(), array('workflow_template_id', 'sessid'))); } else { $this->arResult['TEMPLATES_OLD'][$workflowTemplate['ID']] = $workflowTemplate; $this->arResult['TEMPLATES_OLD'][$workflowTemplate['ID']]['URL'] = htmlspecialcharsex($this->getApplication()->getCurPageParam('workflow_template_id=' . $workflowTemplate['ID'] . '&old=1&' . bitrix_sessid_get(), array('workflow_template_id', 'sessid'))); } } } if ($this->arParams['TEMPLATE_ID'] > 0 && strlen($this->request->getPost('CancelStartParamWorkflow')) <= 0 && (array_key_exists($this->arParams['TEMPLATE_ID'], $this->arResult['TEMPLATES']) || array_key_exists($this->arParams['TEMPLATE_ID'], $this->arResult['TEMPLATES_OLD']))) { if (array_key_exists($this->arParams['TEMPLATE_ID'], $this->arResult['TEMPLATES'])) { $templates = $this->arResult['TEMPLATES']; $documentParameters = $this->arResult['DOCUMENT_DATA']['DISK']; $this->arResult['CHECK_TEMPLATE'] = 'DISK'; } else { $templates = $this->arResult['TEMPLATES_OLD']; $documentParameters = $this->arResult['DOCUMENT_DATA']['WEBDAV']; $this->arResult['CHECK_TEMPLATE'] = 'WEBDAV'; } $workflowTemplate = $templates[$this->arParams['TEMPLATE_ID']]; $arWorkflowParameters = array(); $canStartWorkflow = false; if (count($workflowTemplate['PARAMETERS']) <= 0) { $canStartWorkflow = true; } elseif ($this->request->isPost() && strlen($this->request->getPost('DoStartParamWorkflow')) > 0 && check_bitrix_sessid()) { $errorsTemporary = array(); $request = $this->request->getPostList()->toArray(); foreach ($_FILES as $key => $value) { if (array_key_exists('name', $value)) { if (is_array($value['name'])) { $keys = array_keys($value['name']); for ($i = 0, $cnt = count($keys); $i < $cnt; $i++) { $array = array(); foreach ($value as $k1 => $v1) { $array[$k1] = $v1[$keys[$i]]; } $request[$key][] = $array; } } else { $request[$key] = $value; } } } $arWorkflowParameters = CBPWorkflowTemplateLoader::checkWorkflowParameters($workflowTemplate['PARAMETERS'], $request, $documentParameters['DOCUMENT_TYPE'], $errorsTemporary); if (count($errorsTemporary) > 0) { $canStartWorkflow = false; foreach ($errorsTemporary as $e) { $this->errorCollection->add(array(new Error($e['message']))); } } else { $canStartWorkflow = true; } } if ($canStartWorkflow) { $errorsTemporary = array(); $workflowId = CBPDocument::startWorkflow($this->arParams['TEMPLATE_ID'], $documentParameters['DOCUMENT_ID'], array_merge($arWorkflowParameters, array('TargetUser' => 'user_' . intval($this->getUser()->getID()))), $errorsTemporary); if (count($errorsTemporary) > 0) { $this->arResult['SHOW_MODE'] = 'StartWorkflowError'; foreach ($errorsTemporary as $e) { $this->errorCollection->add(array(new Error('[' . $e['code'] . '] ' . $e['message']))); } } else { $this->arResult['SHOW_MODE'] = 'StartWorkflowSuccess'; if (strlen($this->arResult['back_url']) > 0) { LocalRedirect(str_replace('#WF#', $workflowId, $this->request->getQuery('back_url'))); $this->end(true); } } } else { $doStartParam = $this->request->isPost() && strlen($this->request->getPost('DoStartParamWorkflow') && check_bitrix_sessid()) > 0; $keys = array_keys($workflowTemplate['PARAMETERS']); foreach ($keys as $key) { $value = $doStartParam ? $this->request->getQuery($key) : $workflowTemplate['PARAMETERS'][$key]['Default']; if (!is_array($value)) { $this->arResult['PARAMETERS_VALUES'][$key] = CBPHelper::convertParameterValues($value); } else { $keys1 = array_keys($value); foreach ($keys1 as $key1) { $this->arResult['PARAMETERS_VALUES'][$key][$key1] = CBPHelper::convertParameterValues($value[$key1]); } } } $this->arResult['SHOW_MODE'] = 'WorkflowParameters'; } if ($this->errorCollection->hasErrors()) { $error = array_shift($this->getErrors()); ShowError($error->getMessage()); } } else { $this->arResult['SHOW_MODE'] = 'SelectWorkflow'; } }
protected function processActionDefault() { $this->arResult['ACTIVITY_GROUPS'] = array('document' => Loc::getMessage('BIZPROC_WFEDIT_CATEGORY_DOC'), 'logic' => Loc::getMessage('BIZPROC_WFEDIT_CATEGORY_CONSTR'), 'interaction' => Loc::getMessage('BIZPROC_WFEDIT_CATEGORY_INTER'), 'other' => Loc::getMessage('BIZPROC_WFEDIT_CATEGORY_OTHER')); $runtime = CBPRuntime::getRuntime(); $this->arResult['ACTIVITIES'] = $runtime->searchActivitiesByType('activity'); if ($this->arResult['ID'] > 0) { $this->getApplication()->setTitle(Loc::getMessage('BIZPROC_WFEDIT_TITLE_EDIT')); } else { $this->getApplication()->setTitle(Loc::getMessage('BIZPROC_WFEDIT_TITLE_ADD')); } $defUserParamsStr = serialize(array('groups' => array())); $userParamsStr = CUserOptions::getOption('~bizprocdesigner', 'activity_settings', $defUserParamsStr); if (empty($userParamsStr) || !CheckSerializedData($userParamsStr)) { $userParamsStr = $defUserParamsStr; } $this->arResult['USER_PARAMS'] = unserialize($userParamsStr); $this->includeComponentTemplate(); }