Example #1
0
 /**
  * @param string $documentId - document id.
  * @return array - document fields array.
  */
 public function GetDocument($documentId)
 {
     $documentId = intval($documentId);
     if ($documentId <= 0) {
         throw new CBPArgumentNullException("documentId");
     }
     $result = null;
     $dbDocumentList = CIBlockElement::getList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y"));
     if ($objDocument = $dbDocumentList->getNextElement(false, true)) {
         $fields = $objDocument->getFields();
         $properties = $objDocument->getProperties();
         foreach ($fields as $fieldKey => $fieldValue) {
             if (substr($fieldKey, 0, 1) == "~") {
                 continue;
             }
             $result[$fieldKey] = $fieldValue;
             if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY"))) {
                 $result[$fieldKey] = "user_" . $fieldValue;
                 $result[$fieldKey . "_PRINTABLE"] = $fields[$fieldKey == "MODIFIED_BY" ? "USER_NAME" : "CREATED_USER_NAME"];
             } elseif (in_array($fieldKey, array("PREVIEW_TEXT", "DETAIL_TEXT"))) {
                 if ($fields[$fieldKey . "_TYPE"] == "html") {
                     $result[$fieldKey] = HTMLToTxt($fields["~" . $fieldKey]);
                 }
             }
         }
         foreach ($properties as $propertyKey => $propertyValue) {
             if (strlen($propertyValue["USER_TYPE"]) > 0) {
                 if ($propertyValue["USER_TYPE"] == "UserID" || $propertyValue["USER_TYPE"] == "employee" && COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
                     $propertyValueArray = $propertyValue["VALUE"];
                     $propertyKeyArray = isset($propertyValue["VALUE_ENUM_ID"]) ? $propertyValue["VALUE_ENUM_ID"] : $propertyValue["PROPERTY_VALUE_ID"];
                     if (!is_array($propertyValueArray)) {
                         $userQuery = CUser::getByID($propertyValueArray);
                         if ($userArray = $userQuery->getNext()) {
                             $result["PROPERTY_" . $propertyKey] = "user_" . intval($propertyValueArray);
                             $result["PROPERTY_" . $propertyKey . "_PRINTABLE"] = "(" . $userArray["LOGIN"] . ")" . (strlen($userArray["NAME"]) > 0 || strlen($userArray["LAST_NAME"]) > 0 ? " " : "") . $userArray["NAME"] . (strlen($userArray["NAME"]) > 0 && strlen($userArray["LAST_NAME"]) > 0 ? " " : "") . $userArray["LAST_NAME"];
                         }
                     } else {
                         for ($i = 0, $cnt = count($propertyValueArray); $i < $cnt; $i++) {
                             $userQuery = CUser::getByID($propertyValueArray[$i]);
                             if ($userArray = $userQuery->getNext()) {
                                 $result["PROPERTY_" . $propertyKey][$propertyKeyArray[$i]] = "user_" . intval($propertyValueArray[$i]);
                                 $result["PROPERTY_" . $propertyKey . "_PRINTABLE"][$propertyKeyArray[$i]] = "(" . $userArray["LOGIN"] . ")" . (strlen($userArray["NAME"]) > 0 || strlen($userArray["LAST_NAME"]) > 0 ? " " : "") . $userArray["NAME"] . (strlen($userArray["NAME"]) > 0 && strlen($userArray["LAST_NAME"]) > 0 ? " " : "") . $userArray["LAST_NAME"];
                             }
                         }
                     }
                 } else {
                     $result["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"];
                 }
             } elseif ($propertyValue["PROPERTY_TYPE"] == "L") {
                 $propertyValueArray = $propertyValue["VALUE"];
                 $propertyKeyArray = $propertyValue["VALUE_XML_ID"];
                 if (!is_array($propertyValueArray)) {
                     $propertyValueArray = array($propertyValueArray);
                     $propertyKeyArray = array($propertyKeyArray);
                 }
                 for ($i = 0, $cnt = count($propertyValueArray); $i < $cnt; $i++) {
                     $result["PROPERTY_" . $propertyKey][$propertyKeyArray[$i]] = $propertyValueArray[$i];
                 }
             } elseif ($propertyValue["PROPERTY_TYPE"] == "F") {
                 $propertyValueArray = $propertyValue["VALUE"];
                 if (!is_array($propertyValueArray)) {
                     $propertyValueArray = array($propertyValueArray);
                 }
                 foreach ($propertyValueArray as $v) {
                     $userArray = CFile::getFileArray($v);
                     if ($userArray) {
                         $result["PROPERTY_" . $propertyKey][intval($v)] = $userArray["SRC"];
                         $result["PROPERTY_" . $propertyKey . "_printable"][intval($v)] = "[url=/bitrix/tools/bizproc_show_file.php?f=" . htmlspecialcharsbx($userArray["FILE_NAME"]) . "&i=" . $v . "&h=" . md5($userArray["SUBDIR"]) . "]" . htmlspecialcharsbx($userArray["ORIGINAL_NAME"]) . "[/url]";
                     }
                 }
             } else {
                 $result["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"];
             }
         }
         $documentFields = static::getDocumentFields(static::getDocumentType($documentId));
         foreach ($documentFields as $fieldKey => $field) {
             if (!array_key_exists($fieldKey, $result)) {
                 $result[$fieldKey] = null;
             }
         }
     }
     return $result;
 }
Example #2
0
 protected function processActionCheckDelegateResponsible()
 {
     $this->checkRequiredPostParams(array('iblockId'));
     if (!Loader::includeModule('iblock')) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_IBLOCK'))));
     }
     $this->iblockId = intval($this->request->getPost('iblockId'));
     $this->iblockTypeId = COption::GetOptionString('lists', 'livefeed_iblock_type_id');
     $this->checkPermission();
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $rightObject = new CIBlockRights($this->iblockId);
     $rights = $rightObject->getRights();
     $rightsList = $rightObject->getRightsList(false);
     $idRight = array_search('iblock_full', $rightsList);
     $listUser = array();
     $nameTemplate = CSite::GetNameFormat(false);
     $count = 0;
     foreach ($rights as $right) {
         $res = strpos($right['GROUP_CODE'], 'U');
         if ($right['TASK_ID'] == $idRight && $res === 0) {
             $userId = substr($right['GROUP_CODE'], 1);
             $userGroups = CUser::getUserGroup($userId);
             if (!in_array(1, $userGroups)) {
                 $userQuery = CUser::getByID($userId);
                 if ($user = $userQuery->getNext()) {
                     $listUser[$count]['id'] = $right['GROUP_CODE'];
                     $listUser[$count]['name'] = CUser::formatName($nameTemplate, $user, false);
                 }
             }
         }
         $count++;
     }
     $this->sendJsonSuccessResponse(array('listUser' => $listUser));
 }
Example #3
0
 public static function formatListsElement($fields, $params, $mail = false)
 {
     $element = array('EVENT' => $fields, 'CREATED_BY' => array(), 'ENTITY' => array(), 'EVENT_FORMATTED' => array());
     $userObject = CUser::getByID($fields['ENTITY_ID']);
     $user = $userObject->fetch();
     if ($user) {
         if (!$mail) {
             global $APPLICATION;
             $rights = array();
             $rightsQuery = CSocNetLogRights::getList(array(), array('LOG_ID' => $fields['ID']));
             while ($right = $rightsQuery->fetch()) {
                 $rights[] = $right['GROUP_CODE'];
             }
             if (defined('BX_COMP_MANAGED_CACHE')) {
                 $GLOBALS['CACHE_MANAGER']->registerTag('LISTS_ELEMENT_LIVE_FEED');
             }
             $componentResult = $APPLICATION->includeComponent('bitrix:bizproc.workflow.livefeed', '', array('WORKFLOW_ID' => $fields['MESSAGE']), null, array('HIDE_ICONS' => 'Y'));
             $siteDir = rtrim(SITE_DIR, '/');
             $url = CSocNetLogTools::formatEvent_GetURL($fields, true);
             $url = str_replace('#SITE_DIR#', $siteDir, $url);
             $url .= '' . $fields['ID'] . '/';
             $element = array('EVENT' => $fields, 'EVENT_FORMATTED' => array('TITLE_24' => '<a href="' . $fields['TITLE_TEMPLATE'] . '" class="bx-lists-live-feed-title-link">' . $fields['TITLE'] . '</a>', 'MESSAGE' => $fields['TEXT_MESSAGE'] . $componentResult['MESSAGE'], 'IS_IMPORTANT' => false, 'STYLE' => 'new-employee', 'AVATAR_STYLE' => 'avatar-info', 'DESTINATION' => CSocNetLogTools::formatDestinationFromRights($rights, array_merge($params, array('CREATED_BY' => $fields['USER_ID']))), 'URL' => $url), 'CREATED_BY' => CSocNetLogTools::formatEvent_GetCreatedBy($fields, $params, $mail), 'AVATAR_SRC' => CSocNetLog::formatEvent_CreateAvatar($fields, $params), 'CACHED_JS_PATH' => $componentResult['CACHED_JS_PATH'], 'CACHED_CSS_PATH' => $componentResult['CACHED_CSS_PATH']);
             if ($params['MOBILE'] == 'Y') {
                 $element['EVENT_FORMATTED']['TITLE_24'] = Loc::getMessage('LISTS_LF_MOBILE_DESTINATION');
                 $element['EVENT_FORMATTED']['TITLE_24_2'] = $fields['TITLE'];
             }
             if (CModule::IncludeModule('bizproc')) {
                 $workflowId = \CBPStateService::getWorkflowByIntegerId($element['EVENT']['SOURCE_ID']);
             }
             if ($workflowId) {
                 $element['EVENT']['SOURCE_ID'] = $workflowId;
             }
         }
         return $element;
     }
 }
Example #4
0
 /**
  * @param Main\Event $event
  *
  * @return Main\EventResult
  * @throws Main\ObjectNotFoundException
  */
 public static function onShipmentTrackingNumberChange(Main\Event $event)
 {
     $parameters = $event->getParameters();
     /** @var Sale\Shipment $basketItem */
     $shipment = $parameters['ENTITY'];
     $oldValues = $parameters['VALUES'];
     if (!$shipment instanceof Sale\Shipment) {
         return new Main\EventResult(Main\EventResult::ERROR, new Sale\ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_COMPATIBILITY_SHIPMENT_TRACKING_NUMBER_CHANGE_WRONG_BASKET'), 'SALE_EVENT_COMPATIBILITY_SHIPMENT_TRACKING_NUMBER_CHANGE_WRONG_BASKET'), 'sale');
     }
     /** @var Sale\ShipmentCollection $shipmentCollection */
     if (!($shipmentCollection = $shipment->getCollection())) {
         throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found');
     }
     /** @var Sale\Order $order */
     if (!($order = $shipmentCollection->getOrder())) {
         throw new Main\ObjectNotFoundException('Entity "Order" not found');
     }
     foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ON_TRACKING_NUMBER_CHANGE, true) as $oldEvent) {
         ExecuteModuleEventEx($oldEvent, array($order->getId(), $shipment->getField('TRACKING_NUMBER')));
     }
     if (array_key_exists('TRACKING_NUMBER', $oldValues) && strval($shipment->getField('TRACKING_NUMBER')) != '' && $oldValues["TRACKING_NUMBER"] != $shipment->getField('TRACKING_NUMBER')) {
         $accountNumber = $order->getField("ACCOUNT_NUMBER");
         $userId = $order->getField("USER_ID");
         $payerName = "";
         $payerEMail = '';
         $userRes = \CUser::getByID($userId);
         if ($userData = $userRes->fetch()) {
             if (strval($payerName) == '') {
                 $payerName = $userData["NAME"] . (strval($userData["NAME"]) == '' || strval($userData["LAST_NAME"]) == '' ? "" : " ") . $userData["LAST_NAME"];
             }
             if (strval($payerEMail) == '') {
                 $payerEMail = $userData["EMAIL"];
             }
         }
         $emailFields = array("ORDER_ID" => $accountNumber, "ORDER_DATE" => $order->getDateInsert()->toString(), "ORDER_USER" => $payerName, "ORDER_TRACKING_NUMBER" => $shipment->getField('TRACKING_NUMBER'), "BCC" => Main\Config\Option::get("sale", "order_email", "order@" . $_SERVER['SERVER_NAME']), "EMAIL" => $payerEMail, "SALE_EMAIL" => Main\Config\Option::get("sale", "order_email", "order@" . $_SERVER['SERVER_NAME']));
         $event = new \CEvent();
         $event->send("SALE_ORDER_TRACKING_NUMBER", $order->getField("LID"), $emailFields, "N");
     }
     return new Main\EventResult(Main\EventResult::SUCCESS, null, 'sale');
 }
Example #5
0
 public function executeComponent()
 {
     if (!empty($this->arParams['ERROR'])) {
         ShowError(array_shift($this->arParams['ERROR']));
         return;
     }
     $this->arResult['USER_ID'] = $this->arParams['USER_ID'];
     $this->arResult['GRID_ID'] = 'lists_processes';
     $selectFields = array('ID', 'IBLOCK_TYPE_ID', 'IBLOCK_ID', 'NAME');
     $gridOptions = new CGridOptions($this->arResult['GRID_ID']);
     $gridColumns = $gridOptions->getVisibleColumns();
     $gridSort = $gridOptions->getSorting(array('sort' => array('ID' => 'desc')));
     $this->arResult['HEADERS'] = array(array("id" => "ID", "name" => "ID", "default" => false, "sort" => "ID"), array('id' => 'DOCUMENT_NAME', 'name' => Loc::getMessage('CC_BLL_DOCUMENT_NAME'), 'default' => true, 'sort' => 'DOCUMENT_NAME'), array('id' => 'COMMENTS', 'name' => Loc::getMessage('CC_BLL_COMMENTS'), 'default' => true, 'sort' => '', 'hideName' => true, 'iconCls' => 'bp-comments-icon'), array('id' => 'WORKFLOW_PROGRESS', 'name' => Loc::getMessage('CC_BLL_WORKFLOW_PROGRESS'), 'default' => true, 'sort' => ''), array('id' => 'WORKFLOW_STATE', 'name' => Loc::getMessage('CC_BLL_WORKFLOW_STATE'), 'default' => false, 'sort' => ''));
     $this->arResult['FILTER'] = array(array("id" => "NAME", "name" => GetMessage("BPATL_NAME"), "type" => "string"), array('id' => 'TIMESTAMP_X', 'name' => Loc::getMessage('CC_BLL_MODIFIED'), 'type' => 'date'), array('id' => 'DATE_CREATE', 'name' => Loc::getMessage('CC_BLL_CREATED'), 'type' => 'date', 'default' => true));
     $gridFilter = $gridOptions->getFilter($this->arResult['FILTER']);
     foreach ($gridFilter as $key => $value) {
         if (substr($key, -5) == "_from") {
             $op = ">=";
             $newKey = substr($key, 0, -5);
         } elseif (substr($key, -3) == "_to") {
             $op = "<=";
             $newKey = substr($key, 0, -3);
             if (in_array($newKey, array("TIMESTAMP_X", 'DATE_CREATE'))) {
                 if (!preg_match("/\\d\\d:\\d\\d:\\d\\d\$/", $value)) {
                     $value .= " 23:59:59";
                 }
             }
         } else {
             $op = "";
             $newKey = $key;
         }
         $filter[$op . $newKey] = $value;
     }
     $this->arResult['SORT'] = $gridSort['sort'];
     $useComments = (bool) CModule::includeModule("forum");
     $workflows = array();
     $this->arResult['DATA'] = array();
     $this->arResult["COMMENTS_COUNT"] = array();
     $filter['CREATED_BY'] = $this->arParams['USER_ID'];
     $iblockTypeId = COption::GetOptionString("lists", "livefeed_iblock_type_id");
     $filter['IBLOCK_TYPE'] = $iblockTypeId;
     $filter['CHECK_PERMISSIONS'] = $this->arParams['LIST_PERM'] >= CListPermissions::CAN_READ ? "N" : "Y";
     $elementObject = CIBlockElement::getList($gridSort['sort'], $filter, false, $gridOptions->getNavParams(), $selectFields);
     $documentState = true;
     $path = rtrim(SITE_DIR, '/');
     while ($element = $elementObject->fetch()) {
         $documentState = CBPDocument::GetDocumentStates(BizprocDocument::generateDocumentComplexType($iblockTypeId, $element['IBLOCK_ID']), BizprocDocument::getDocumentComplexId($iblockTypeId, $element['ID']));
         $this->arResult['DATA'][$element['ID']]['ID'] = $element['ID'];
         $this->arResult['DATA'][$element['ID']]['DOCUMENT_NAME'] = $element['NAME'];
         $this->arResult['DATA'][$element['ID']]['DOCUMENT_URL'] = $path . COption::GetOptionString('lists', 'livefeed_url') . '?livefeed=y&list_id=' . $element["IBLOCK_ID"] . '&element_id=' . $element['ID'];
         if (!empty($documentState)) {
             $this->arResult['DATA'][$element['ID']]['DOCUMENT_STATE'] = true;
             $documentState = current($documentState);
             $this->arResult['DATA'][$element['ID']]['WORKFLOW_ID'] = $documentState['ID'];
             $this->arResult['DATA'][$element['ID']]["WORKFLOW_NAME"] = $documentState["TEMPLATE_NAME"];
             $this->arResult['DATA'][$element['ID']]["WORKFLOW_STATE"] = $documentState["STATE_TITLE"];
             $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED"] = FormatDateFromDB($documentState["STARTED_FORMATTED"]);
             $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED_BY"] = "";
             if (intval($documentState["STARTED_BY"]) > 0) {
                 $dbUserTmp = CUser::getByID($documentState["STARTED_BY"]);
                 $arUserTmp = $dbUserTmp->fetch();
                 $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED_BY"] = CUser::FormatName($this->arParams["NAME_TEMPLATE"], $arUserTmp, true);
                 $this->arResult['DATA'][$element['ID']]["WORKFLOW_STARTED_BY"] .= " [" . $documentState["STARTED_BY"] . "]";
             }
             $this->arResult['DATA'][$element['ID']]['MODULE_ID'] = $documentState["DOCUMENT_ID"][0];
             $this->arResult['DATA'][$element['ID']]['ENTITY'] = $documentState["DOCUMENT_ID"][1];
             $this->arResult['DATA'][$element['ID']]['DOCUMENT_ID'] = $documentState["DOCUMENT_ID"][2];
         } else {
             $documentState = false;
             $this->arResult['DATA'][$element['ID']]['DOCUMENT_STATE'] = false;
         }
     }
     foreach ($this->arResult['DATA'] as $data) {
         if ($documentState) {
             if ($useComments) {
                 $workflows[] = 'WF_' . $data['WORKFLOW_ID'];
             }
         }
         $actions = array();
         if (strlen($data["DOCUMENT_URL"]) > 0) {
             $actions[] = array('ICONCLASS' => '', 'DEFAULT' => false, 'TEXT' => Loc::getMessage('CC_BLL_C_DOCUMENT'), 'ONCLICK' => 'window.open("' . $data["DOCUMENT_URL"] . '");');
         }
         $this->arResult['RECORDS'][] = array('data' => $data, 'actions' => $actions);
     }
     if ($useComments && $documentState) {
         $workflows = array_unique($workflows);
         if ($workflows) {
             $iterator = CForumTopic::getList(array(), array("@XML_ID" => $workflows));
             while ($row = $iterator->fetch()) {
                 $this->arResult["COMMENTS_COUNT"][$row['XML_ID']] = $row['POSTS'];
             }
         }
     }
     $this->arResult['COUNTERS'] = array('all' => 0);
     $this->arResult["ROWS_COUNT"] = $elementObject->selectedRowsCount();
     $this->arResult["NAV_RESULT"] = $elementObject;
     if ($this->arParams['SET_TITLE'] == 'Y') {
         $this->getApplication()->setTitle(Loc::getMessage('CC_BLL_TITLE'));
     }
     $this->includeComponentTemplate();
 }
Example #6
0
 protected function showBizProc($documentData)
 {
     $this->arResult['BIZPROC_PERMISSION'] = array();
     $this->arResult['BIZPROC_PERMISSION']['START'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']);
     $this->arResult['BIZPROC_PERMISSION']['VIEW'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']);
     $this->arResult['BIZPROC_PERMISSION']['STOP'] = $this->arResult['BIZPROC_PERMISSION']['START'];
     $this->arResult['BIZPROC_PERMISSION']['DROP'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::CreateWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']);
     foreach ($documentData as $nameModuleId => $data) {
         $temporary[$nameModuleId] = CBPDocument::getDocumentStates($data['DOCUMENT_TYPE'], $data['DOCUMENT_ID']);
     }
     if (isset($temporary['OLD_FILE'])) {
         $allBizProcArray = array_merge($temporary['DISK'], $temporary['WEBDAV'], $temporary['OLD_FILE']);
     } else {
         $allBizProcArray = array_merge($temporary['DISK'], $temporary['WEBDAV']);
     }
     if (!empty($allBizProcArray)) {
         $userGroup = $this->getUser()->getUserGroupArray();
         $userGroup[] = 'author';
         if ($this->request->isPost() && intval($this->request->getPost('bizproc_index')) > 0) {
             $bizProcWorkflowId = array();
             $bizprocIndex = intval($this->request->getPost('bizproc_index'));
             for ($i = 1; $i <= $bizprocIndex; $i++) {
                 $bpId = trim($this->request->getPost("bizproc_id_" . $i));
                 $bpTemplateId = intval($this->request->getPost("bizproc_template_id_" . $i));
                 $bpEvent = trim($this->request->getPost("bizproc_event_" . $i));
                 if (strlen($bpId) > 0) {
                     if (!array_key_exists($bpId, $allBizProcArray)) {
                         continue;
                     }
                 } else {
                     if (!array_key_exists($bpTemplateId, $allBizProcArray)) {
                         continue;
                     }
                     $bpId = $bizProcWorkflowId[$bpTemplateId];
                 }
                 if (strlen($bpEvent) > 0) {
                     $errors = array();
                     CBPDocument::sendExternalEvent($bpId, $bpEvent, array("Groups" => $userGroup, "User" => $this->getUser()->getId()), $errors);
                 } else {
                     $errors = array();
                     foreach ($allBizProcArray as $idBizProc => $bizProcArray) {
                         if ($idBizProc == $bpId) {
                             CBPDocument::TerminateWorkflow($bpId, $bizProcArray['DOCUMENT_ID'], $errors);
                         }
                     }
                 }
                 if (!empty($errors)) {
                     foreach ($errors as $error) {
                         $this->arResult['ERROR_MESSAGE'] = $error['message'];
                     }
                 } else {
                     LocalRedirect($this->arResult['PATH_TO_FILE_VIEW'] . "#tab-bp");
                 }
             }
         }
         $this->arResult['BIZPROC_LIST'] = array();
         $count = 1;
         foreach ($allBizProcArray as $idBizProc => $bizProcArray) {
             if (intVal($bizProcArray["WORKFLOW_STATUS"]) < 0 || $idBizProc <= 0) {
                 continue;
             } else {
                 if (!CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID'], array("DocumentStates" => $bizProcArray, "WorkflowId" => $bizProcArray["ID"] > 0 ? $bizProcArray["ID"] : $bizProcArray["TEMPLATE_ID"]))) {
                     continue;
                 }
             }
             $groups = CBPDocument::getAllowableUserGroups($documentData['DISK']['DOCUMENT_TYPE']);
             foreach ($groups as $key => $val) {
                 $groups[strtolower($key)] = $val;
             }
             $users = array();
             $dmpWorkflow = CBPTrackingService::getList(array("ID" => "DESC"), array("WORKFLOW_ID" => $idBizProc, "TYPE" => array(CBPTrackingType::Report, CBPTrackingType::Custom, CBPTrackingType::FaultActivity)), false, array("nTopCount" => 5), array("ID", "TYPE", "MODIFIED", "ACTION_NOTE", "ACTION_TITLE", "ACTION_NAME", "EXECUTION_STATUS", "EXECUTION_RESULT"));
             while ($track = $dmpWorkflow->getNext()) {
                 $messageTemplate = "";
                 switch ($track["TYPE"]) {
                     case 1:
                         $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_1");
                         break;
                     case 2:
                         $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_2");
                         break;
                     case 3:
                         $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_3");
                         break;
                     case 4:
                         $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_4");
                         break;
                     case 5:
                         $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_5");
                         break;
                     default:
                         $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_6");
                 }
                 $name = strlen($track["ACTION_TITLE"]) > 0 ? $track["ACTION_TITLE"] : $track["ACTION_NAME"];
                 switch ($track["EXECUTION_STATUS"]) {
                     case CBPActivityExecutionStatus::Initialized:
                         $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_1");
                         break;
                     case CBPActivityExecutionStatus::Executing:
                         $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_2");
                         break;
                     case CBPActivityExecutionStatus::Canceling:
                         $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_3");
                         break;
                     case CBPActivityExecutionStatus::Closed:
                         $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_4");
                         break;
                     case CBPActivityExecutionStatus::Faulting:
                         $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_5");
                         break;
                     default:
                         $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_6");
                 }
                 switch ($track["EXECUTION_RESULT"]) {
                     case CBPActivityExecutionResult::None:
                         $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_1");
                         break;
                     case CBPActivityExecutionResult::Succeeded:
                         $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_2");
                         break;
                     case CBPActivityExecutionResult::Canceled:
                         $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_3");
                         break;
                     case CBPActivityExecutionResult::Faulted:
                         $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_4");
                         break;
                     case CBPActivityExecutionResult::Uninitialized:
                         $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_5");
                         break;
                     default:
                         $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_6");
                 }
                 $note = strlen($track["ACTION_NOTE"]) > 0 ? ": " . $track["ACTION_NOTE"] : "";
                 $pattern = array("#ACTIVITY#", "#STATUS#", "#RESULT#", "#NOTE#");
                 $replaceArray = array($name, $status, $result, $note);
                 if (!empty($track["ACTION_NAME"]) && !empty($track["ACTION_TITLE"])) {
                     $pattern[] = $track["ACTION_NAME"];
                     $replaceArray[] = $track["ACTION_TITLE"];
                 }
                 $messageTemplate = str_replace($pattern, $replaceArray, $messageTemplate);
                 if (preg_match_all("/(?<=\\{\\=user\\:)([^\\}]+)(?=\\})/is", $messageTemplate, $arMatches)) {
                     $pattern = array();
                     $replacement = array();
                     foreach ($arMatches[0] as $user) {
                         $user = preg_quote($user);
                         if (in_array("/\\{\\=user\\:" . $user . "\\}/is", $pattern)) {
                             continue;
                         }
                         $replace = "";
                         if (array_key_exists(strtolower($user), $groups)) {
                             $replace = $groups[strtolower($user)];
                         } elseif (array_key_exists(strtoupper($user), $groups)) {
                             $replace = $groups[strtoupper($user)];
                         } else {
                             $id = intVal(str_replace("user_", "", $user));
                             if (!array_key_exists($id, $users)) {
                                 $dbRes = \CUser::getByID($id);
                                 $users[$id] = false;
                                 if ($dbRes && ($arUser = $dbRes->getNext())) {
                                     $name = \CUser::formatName($this->arParams["NAME_TEMPLATE"], $arUser);
                                     $arUser["FULL_NAME"] = empty($name) ? $arUser["LOGIN"] : $name;
                                     $users[$id] = $arUser;
                                 }
                             }
                             if (!empty($users[$id])) {
                                 $replace = "<a href=\"" . \CComponentEngine::makePathFromTemplate('/company/personal/user/#USER_ID#/', array("USER_ID" => $id)) . "\">" . $users[$id]["FULL_NAME"] . "</a>";
                             }
                         }
                         if (!empty($replace)) {
                             $pattern[] = "/\\{\\=user\\:" . $user . "\\}/is";
                             $pattern[] = "/\\{\\=user\\:user\\_" . $user . "\\}/is";
                             $replacement[] = $replace;
                             $replacement[] = $replace;
                         }
                     }
                     $messageTemplate = preg_replace($pattern, $replacement, $messageTemplate);
                 }
                 $this->arResult['BIZPROC_LIST'][$count]['DUMP_WORKFLOW'][] = $messageTemplate;
             }
             $tasks = CBPDocument::getUserTasksForWorkflow($this->getUser()->getId(), $idBizProc);
             $events = CBPDocument::getAllowableEvents($this->getUser()->getId(), $userGroup, $bizProcArray);
             if (!empty($tasks)) {
                 foreach ($tasks as $task) {
                     $urlTaskBizproc = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_DISK_TASK'], array("ID" => $task['ID']));
                     $urlTaskBizproc .= "?back_url=" . urlencode($this->getApplication()->getCurPage()) . "&file=" . $this->file->getName();
                     $this->arResult['BIZPROC_LIST'][$count]['TASK']['URL'] = $urlTaskBizproc;
                     $this->arResult['BIZPROC_LIST'][$count]['TASK']['TASK_ID'] = $task['ID'];
                     $this->arResult['BIZPROC_LIST'][$count]['TASK']['TASK_NAME'] = $task['NAME'];
                 }
             }
             $this->arResult['BIZPROC_LIST'][$count]['ID'] = $bizProcArray['ID'];
             $this->arResult['BIZPROC_LIST'][$count]['WORKFLOW_STATUS'] = $bizProcArray["WORKFLOW_STATUS"];
             $this->arResult['BIZPROC_LIST'][$count]['TEMPLATE_ID'] = $bizProcArray['TEMPLATE_ID'];
             $this->arResult['BIZPROC_LIST'][$count]['TEMPLATE_NAME'] = $bizProcArray['TEMPLATE_NAME'];
             $this->arResult['BIZPROC_LIST'][$count]['STATE_MODIFIED'] = $bizProcArray['STATE_MODIFIED'];
             $this->arResult['BIZPROC_LIST'][$count]['STATE_TITLE'] = $bizProcArray['STATE_TITLE'];
             $this->arResult['BIZPROC_LIST'][$count]['STATE_NAME'] = $bizProcArray['STATE_NAME'];
             $this->arResult['BIZPROC_LIST'][$count]['EVENTS'] = $events;
             $count++;
         }
     }
 }
Example #7
0
 public static function getUser($userId, $photo = false)
 {
     global $USER;
     if (is_object($USER) && intVal($userId) == $USER->GetId() && !$photo) {
         $user = array('ID' => $USER->GetId(), 'NAME' => $USER->GetFirstName(), 'LAST_NAME' => $USER->GetLastName(), 'SECOND_NAME' => $USER->GetParam('SECOND_NAME'), 'LOGIN' => $USER->GetLogin());
     } else {
         $user = CUser::getByID(intval($userId))->Fetch();
     }
     return $user;
 }