Пример #1
0
 /**
  * @param array $params Input params.
  * @param int $n Offset.
  * @param \CRestServer $server Rest server instance.
  * @return array
  * @throws AccessException
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function getWorkflowInstances($params, $n, $server)
 {
     self::checkAdminPermissions();
     $params = array_change_key_case($params, CASE_UPPER);
     $fields = array('ID' => 'ID', 'MODIFIED' => 'MODIFIED', 'OWNED_UNTIL' => 'OWNED_UNTIL', 'MODULE_ID' => 'STATE.MODULE_ID', 'ENTITY' => 'STATE.ENTITY', 'DOCUMENT_ID' => 'STATE.DOCUMENT_ID', 'STARTED' => 'STATE.STARTED', 'STARTED_BY' => 'STATE.STARTED_BY', 'TEMPLATE_ID' => 'STATE.WORKFLOW_TEMPLATE_ID');
     $select = static::getSelect($params['SELECT'], $fields, array('ID', 'MODIFIED', 'OWNED_UNTIL'));
     $filter = static::getFilter($params['FILTER'], $fields);
     $order = static::getOrder($params['ORDER'], $fields);
     $iterator = WorkflowInstanceTable::getList(array('select' => $select, 'filter' => $filter, 'order' => $order, 'limit' => static::LIST_LIMIT, 'offset' => (int) $n));
     $result = array();
     while ($row = $iterator->fetch()) {
         if (isset($row['MODIFIED'])) {
             $row['MODIFIED'] = \CRestUtil::convertDateTime($row['MODIFIED']);
         }
         if (isset($row['OWNED_UNTIL'])) {
             $row['OWNED_UNTIL'] = \CRestUtil::convertDateTime($row['OWNED_UNTIL']);
         }
         $result[] = $row;
     }
     return $result;
 }
Пример #2
0
 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();
 }
Пример #3
0
 public static function onAfterTMDayStart($data)
 {
     global $DB;
     if (!CModule::IncludeModule("im")) {
         return;
     }
     $userId = (int) $data['USER_ID'];
     $iterator = \Bitrix\Bizproc\WorkflowInstanceTable::getList(array('select' => array(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(\'x\')')), 'filter' => array('=STATE.STARTED_BY' => $userId, '<OWNED_UNTIL' => date($DB->DateFormatToPHP(FORMAT_DATETIME), time() - \Bitrix\Bizproc\WorkflowInstanceTable::LOCKED_TIME_INTERVAL))));
     $row = $iterator->fetch();
     if (!empty($row['CNT'])) {
         CIMNotify::Add(array('FROM_USER_ID' => 0, 'TO_USER_ID' => $userId, "NOTIFY_TYPE" => IM_NOTIFY_SYSTEM, "NOTIFY_MODULE" => "bizproc", "NOTIFY_EVENT" => "wi_locked", 'TITLE' => GetMessage('BPCGDOC_WI_LOCKED_NOTICE_TITLE'), 'MESSAGE' => GetMessage('BPCGDOC_WI_LOCKED_NOTICE_MESSAGE', array('#PATH#' => \Bitrix\Main\Config\Option::get("bizproc", "locked_wi_path", "/services/bp/instances.php?type=is_locked"), '#CNT#' => $row['CNT']))));
     }
 }