public function executeComponent() { if ($this->arParams['SET_TITLE']) { $this->setPageTitle(Loc::getMessage('BPWI_PAGE_TITLE')); } if (!empty($_POST['ID']) && check_bitrix_sessid() && $this->isAdmin()) { foreach ((array) $_POST['ID'] as $id) { CBPDocument::killWorkflow($id); } } $selectFields = array('ID', 'MODIFIED', 'OWNER_ID', 'OWNED_UNTIL', 'WS_MODULE_ID' => $this->getFieldName('WS_MODULE_ID'), 'WS_ENTITY' => $this->getFieldName('WS_ENTITY'), 'WS_DOCUMENT_ID' => $this->getFieldName('WS_DOCUMENT_ID')); $gridColumns = $this->getGridOptions()->getVisibleColumns(); $this->arResult['HEADERS'] = $this->getGridHeaders(); $showDocumentName = false; foreach ($this->arResult['HEADERS'] as $h) { if ((count($gridColumns) <= 0 || in_array($h['id'], $gridColumns)) && !in_array($h['id'], $selectFields)) { if ($this->getFieldName($h['id'])) { $selectFields[$h['id']] = $this->getFieldName($h['id']); } elseif ($h['id'] == 'IS_LOCKED' && !in_array('OWNED_UNTIL', $selectFields)) { $selectFields['OWNED_UNTIL'] = $this->getFieldName('OWNED_UNTIL'); } elseif ($h['id'] == 'WS_DOCUMENT_NAME') { $showDocumentName = true; } } } if (isset($selectFields['WS_STARTED_BY'])) { $selectFields['WS_STARTED_USER_NAME'] = $this->getFieldName('WS_STARTED_USER_NAME'); $selectFields['WS_STARTED_USER_LAST_NAME'] = $this->getFieldName('WS_STARTED_USER_LAST_NAME'); $selectFields['WS_STARTED_USER_LOGIN'] = $this->getFieldName('WS_STARTED_USER_LOGIN'); } $filter = array(); $templatesFilter = array(); $this->arResult['DOCUMENT_TYPES'] = $this->getDocumentTypes(); if (!empty($_REQUEST['type']) && isset($this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']])) { $this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']]['ACTIVE'] = true; if (!empty($this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']]['MODULE_ID'])) { $filter = array('=' . $this->getFieldName('WS_MODULE_ID') => $this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']]['MODULE_ID']); $templatesFilter = array('MODULE_ID' => $filter[$this->getFieldName('WS_MODULE_ID')]); if (!empty($this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']]['ENTITY'])) { $filter['=' . $this->getFieldName('WS_ENTITY')] = $this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']]['ENTITY']; $templatesFilter['ENTITY'] = $this->arResult['DOCUMENT_TYPES'][$_REQUEST['type']]['ENTITY']; } } elseif ($_REQUEST['type'] == 'is_locked') { global $DB; $filter['<OWNED_UNTIL'] = date($DB->DateFormatToPHP(FORMAT_DATETIME), $this->getLockedTime()); } } else { $this->arResult['DOCUMENT_TYPES']['*']['ACTIVE'] = true; } $templatesList = array('' => Loc::getMessage('BPWI_WORKFLOW_ID_ANY')); $dbResTmp = \CBPWorkflowTemplateLoader::GetList(array('NAME' => 'ASC'), $templatesFilter, false, false, array('ID', 'NAME')); while ($arResTmp = $dbResTmp->GetNext()) { $templatesList[$arResTmp['ID']] = $arResTmp['NAME']; } $this->arResult['FILTER'] = $this->getFilter(); $this->arResult['FILTER'][] = array('id' => 'WS_WORKFLOW_TEMPLATE_ID', 'name' => Loc::getMessage('BPWI_WS_WORKFLOW_TEMPLATE_ID'), 'type' => 'list', 'items' => $templatesList); $gridFilter = $this->getGridOptions()->getFilter($this->arResult['FILTER']); $filter = $this->mergeFilters($filter, $gridFilter); if (!$this->isAdmin()) { global $USER; $filter['=' . $this->getFieldName('WS_STARTED_BY')] = $USER->getId(); } list($currentPage, $pageSize, $offset) = $this->getPaginationInfo(); $this->arResult['SORT'] = $this->getSorting(); $this->arResult['CURRENT_PAGE'] = $currentPage; $this->arResult['SHOW_NEXT_PAGE'] = false; $this->arResult['RECORDS'] = array(); $iterator = WorkflowInstanceTable::getList(array('order' => $this->arResult['SORT'], 'select' => $selectFields, 'filter' => $filter, 'limit' => $pageSize + 1, 'offset' => $offset)); $rowsCount = 0; while ($row = $iterator->fetch()) { $rowsCount++; if ($rowsCount > $pageSize) { $this->arResult['SHOW_NEXT_PAGE'] = true; break; } $row['WS_WORKFLOW_TEMPLATE_ID'] = $row['WS_WORKFLOW_TEMPLATE_ID'] ? $templatesList[$row['WS_WORKFLOW_TEMPLATE_ID']] : null; $row['IS_LOCKED'] = $row['OWNED_UNTIL'] && $row['OWNED_UNTIL']->getTimestamp() < $this->getLockedTime(); if (!empty($row['WS_STARTED_BY'])) { $row['WS_STARTED_BY'] = CUser::FormatName($this->arParams["NAME_TEMPLATE"], array('LOGIN' => $row['WS_STARTED_USER_LOGIN'], 'NAME' => $row['WS_STARTED_USER_NAME'], 'LAST_NAME' => $row['WS_STARTED_USER_LAST_NAME']), true) . " [" . $row['WS_STARTED_BY'] . "]"; } $row['DOCUMENT_URL'] = $row['WS_DOCUMENT_NAME'] = ''; if (!empty($row['WS_MODULE_ID'])) { $row['DOCUMENT_URL'] = CBPDocument::GetDocumentAdminPage(array($row['WS_MODULE_ID'], $row['WS_ENTITY'], $row['WS_DOCUMENT_ID'])); if ($showDocumentName) { $row['WS_DOCUMENT_NAME'] = CBPDocument::getDocumentName(array($row['WS_MODULE_ID'], $row['WS_ENTITY'], $row['WS_DOCUMENT_ID'])); } } $rowActions = array(array("ICONCLASS" => "edit", "DEFAULT" => true, "TEXT" => Loc::getMessage("BPWI_OPEN_DOCUMENT"), "ONCLICK" => $row['DOCUMENT_URL'] ? "window.open('" . $row["DOCUMENT_URL"] . "');" : 'alert(\'' . Loc::getMessage('BPWI_NO_DOCUMENT') . '\')')); if ($this->isAdmin()) { $rowActions[] = array("ICONCLASS" => "delete", "TEXT" => Loc::getMessage("BPWI_DELETE_LABEL"), "ONCLICK" => "bxGrid_" . static::GRID_ID . ".DeleteItem('" . $row['ID'] . "', '" . Loc::getMessage("BPWI_DELETE_CONFIRM") . "')"); } $this->arResult['RECORDS'][] = array('data' => $row, 'editable' => $this->isAdmin(), 'actions' => $rowActions); } $this->arResult['ROWS_COUNT'] = sizeof($this->arResult['RECORDS']); $this->arResult['GRID_ID'] = static::GRID_ID; $this->arResult['FILTER_PRESETS'] = $this->getFilterPresets(); $this->arResult['EDITABLE'] = $this->isAdmin(); $this->includeComponentTemplate(); }