PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/components/bitrix/lists.user.processes/class.php

https://gitlab.com/alexprowars/bitrix
PHP | 301 lines | 268 code | 33 blank | 0 comment | 30 complexity | 3e60753c77fcea93995fa004f0d597df MD5 | raw file
  1. <? if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();
  2. use Bitrix\Main\Loader;
  3. use Bitrix\Main\Localization\Loc;
  4. Loc::loadMessages(__FILE__);
  5. class ListsSelectElementComponent extends CBitrixComponent
  6. {
  7. public function onPrepareComponentParams($arParams)
  8. {
  9. $arParams['ERROR'] = array();
  10. if (!Loader::includeModule('lists'))
  11. {
  12. $arParams['ERROR'][] = Loc::getMessage('CC_BLL_MODULE_NOT_INSTALLED');
  13. return $arParams;
  14. }
  15. $arParams['IBLOCK_TYPE_ID'] = COption::GetOptionString("lists", "livefeed_iblock_type_id");
  16. if (!Loader::includeModule('bizproc') || !CLists::isBpFeatureEnabled($arParams["IBLOCK_TYPE_ID"]))
  17. {
  18. $arParams['ERROR'][] = Loc::getMessage('CC_BLL_BIZPROC_MODULE_NOT_INSTALLED');
  19. return $arParams;
  20. }
  21. global $USER;
  22. $arParams['LIST_PERM'] = CListPermissions::CheckAccess(
  23. $USER,
  24. COption::GetOptionString("lists", "livefeed_iblock_type_id"),
  25. false
  26. );
  27. if($arParams['LIST_PERM'] < 0)
  28. {
  29. switch($arParams['LIST_PERM'])
  30. {
  31. case CListPermissions::WRONG_IBLOCK_TYPE:
  32. $arParams['ERROR'][] = Loc::getMessage("CC_BLL_WRONG_IBLOCK_TYPE");
  33. break;
  34. case CListPermissions::WRONG_IBLOCK:
  35. $arParams['ERROR'][] = Loc::getMessage("CC_BLL_WRONG_IBLOCK");
  36. break;
  37. case CListPermissions::LISTS_FOR_SONET_GROUP_DISABLED:
  38. $arParams['ERROR'][] = Loc::getMessage("CC_BLL_LISTS_FOR_SONET_GROUP_DISABLED");
  39. break;
  40. default:
  41. $arParams['ERROR'][] = Loc::getMessage("CC_BLL_UNKNOWN_ERROR");
  42. break;
  43. }
  44. }
  45. elseif($arParams['LIST_PERM'] <= CListPermissions::ACCESS_DENIED)
  46. {
  47. $arParams['ERROR'][] = Loc::getMessage("CC_BLL_ACCESS_DENIED");
  48. }
  49. return $arParams;
  50. }
  51. public function executeComponent()
  52. {
  53. if($this->arParams['SET_TITLE'] == 'Y')
  54. $this->getApplication()->setTitle(Loc::getMessage('CC_BLL_TITLE'));
  55. if(!empty($this->arParams['ERROR']))
  56. {
  57. ShowError(array_shift($this->arParams['ERROR']));
  58. return;
  59. }
  60. $this->arResult['USER_ID'] = $this->arParams['USER_ID'];
  61. $this->arResult['GRID_ID'] = 'lists_processes';
  62. $this->arResult['FILTER_ID'] = 'lists_processes';
  63. $selectFields = array('ID', 'IBLOCK_TYPE_ID', 'IBLOCK_ID', 'NAME');
  64. $gridOptions = new CGridOptions($this->arResult['GRID_ID']);
  65. $gridSort = $gridOptions->getSorting(array('sort' => array('ID' => 'desc')));
  66. $this->arResult['HEADERS'] = array(
  67. array(
  68. "id" => "ID",
  69. "name" => "ID",
  70. "default" => false,
  71. "sort" => "ID"
  72. ),
  73. array(
  74. 'id' => 'DOCUMENT_NAME',
  75. 'name' => Loc::getMessage('CC_BLL_DOCUMENT_NAME'),
  76. 'default' => true, 'sort' => 'DOCUMENT_NAME'
  77. ),
  78. array(
  79. 'id' => 'COMMENTS',
  80. 'name' => Loc::getMessage('CC_BLL_COMMENTS'),
  81. 'default' => true,
  82. 'sort' => '',
  83. 'hideName' => true,
  84. 'iconCls' => 'bp-comments-icon'
  85. ),
  86. array(
  87. 'id' => 'WORKFLOW_PROGRESS',
  88. 'name' => Loc::getMessage('CC_BLL_WORKFLOW_PROGRESS'),
  89. 'default' => true,
  90. 'sort' => ''
  91. ),
  92. array(
  93. 'id' => 'WORKFLOW_STATE',
  94. 'name' => Loc::getMessage('CC_BLL_WORKFLOW_STATE'),
  95. 'default' => true,
  96. 'sort' => ''
  97. ),
  98. );
  99. $this->arResult['FILTER'] = array(
  100. array(
  101. "id" => "NAME",
  102. "name" => Loc::getMessage("BPATL_NAME"),
  103. "type" => "string",
  104. 'default' => true
  105. ),
  106. array(
  107. 'id' => 'TIMESTAMP_X',
  108. 'name' => Loc::getMessage('CC_BLL_MODIFIED'),
  109. 'type' => 'date',
  110. 'default' => true
  111. ),
  112. array(
  113. 'id' => 'DATE_CREATE',
  114. 'name' => Loc::getMessage('CC_BLL_CREATED'),
  115. 'type' => 'date',
  116. 'default' => true
  117. ),
  118. );
  119. $filterOption = new Bitrix\Main\UI\Filter\Options($this->arResult['FILTER_ID']);
  120. $filterData = $filterOption->getFilter($this->arResult['FILTER']);
  121. foreach($filterData as $key => $value)
  122. {
  123. if(empty($value))
  124. continue;
  125. if(mb_substr($key, -5) == "_from")
  126. {
  127. $op = ">=";
  128. $new_key = mb_substr($key, 0, -5);
  129. }
  130. elseif(mb_substr($key, -3) == "_to")
  131. {
  132. $op = "<=";
  133. $new_key = mb_substr($key, 0, -3);
  134. $newKey = mb_substr($key, 0, -3);
  135. if(in_array($newKey, array("TIMESTAMP_X", 'DATE_CREATE')))
  136. {
  137. global $DB;
  138. $dateFormat = $DB->dateFormatToPHP(Csite::getDateFormat());
  139. $dateParse = date_parse_from_format($dateFormat, $value);
  140. if(!mb_strlen($dateParse["hour"]) && !mb_strlen($dateParse["minute"]) && !mb_strlen($dateParse["second"]))
  141. {
  142. $timeFormat = $DB->dateFormatToPHP(CSite::getTimeFormat());
  143. $value .= " ".date($timeFormat, mktime(23, 59, 59, 0, 0, 0));
  144. }
  145. }
  146. }
  147. elseif($key == "NAME")
  148. {
  149. $op = "?";
  150. $new_key = $key;
  151. }
  152. else
  153. {
  154. $op = "";
  155. $new_key = $key;
  156. }
  157. $filter[$op.$new_key] = $value;
  158. if($key == "FIND")
  159. {
  160. $op = "?";
  161. $filter[$op."SEARCHABLE_CONTENT"] = $value;
  162. }
  163. }
  164. $this->arResult['SORT'] = $gridSort['sort'];
  165. $useComments = (bool)CModule::includeModule("forum");
  166. $workflows = array();
  167. $this->arResult['DATA'] = array();
  168. $this->arResult["COMMENTS_COUNT"] = array();
  169. $filter['CREATED_BY'] = $this->arParams['USER_ID'];
  170. $iblockTypeId = COption::GetOptionString("lists", "livefeed_iblock_type_id");
  171. $filter['=IBLOCK_TYPE'] = $iblockTypeId;
  172. $filter['CHECK_PERMISSIONS'] = ($this->arParams['LIST_PERM'] >= CListPermissions::CAN_READ ? "N": "Y");
  173. $elementObject = CIBlockElement::getList(
  174. $gridSort['sort'],
  175. $filter,
  176. false,
  177. $gridOptions->getNavParams(),
  178. $selectFields
  179. );
  180. $documentStates = true;
  181. $path = rtrim(SITE_DIR, '/');
  182. while($element = $elementObject->fetch())
  183. {
  184. $documentStates = CBPDocument::GetDocumentStates(
  185. BizprocDocument::generateDocumentComplexType($iblockTypeId, $element['IBLOCK_ID']),
  186. BizprocDocument::getDocumentComplexId($iblockTypeId, $element['ID'])
  187. );
  188. if(!empty($documentStates))
  189. {
  190. foreach($documentStates as $documentState)
  191. {
  192. if(empty($documentState['ID']))
  193. continue;
  194. $this->arResult['DATA'][$documentState['ID']]['ID'] = $element['ID'];
  195. $this->arResult['DATA'][$documentState['ID']]['DOCUMENT_NAME'] = $element['NAME'];
  196. $this->arResult['DATA'][$documentState['ID']]['DOCUMENT_URL'] = $path.COption::GetOptionString('lists', 'livefeed_url').'?livefeed=y&list_id='.$element["IBLOCK_ID"].'&element_id='.$element['ID'];
  197. $this->arResult['DATA'][$documentState['ID']]['DOCUMENT_STATE'] = true;
  198. $this->arResult['DATA'][$documentState['ID']]['WORKFLOW_ID'] = $documentState['ID'];
  199. $this->arResult['DATA'][$documentState['ID']]["WORKFLOW_NAME"] = $documentState["TEMPLATE_NAME"];
  200. $this->arResult['DATA'][$documentState['ID']]["WORKFLOW_STATE"] = htmlspecialcharsbx($documentState["STATE_TITLE"]);
  201. $this->arResult['DATA'][$documentState['ID']]["WORKFLOW_STARTED"] = FormatDateFromDB($documentState["STARTED_FORMATTED"]);
  202. $this->arResult['DATA'][$documentState['ID']]["WORKFLOW_STARTED_BY"] = "";
  203. if (intval($documentState["STARTED_BY"]) > 0)
  204. {
  205. $dbUserTmp = CUser::getByID($documentState["STARTED_BY"]);
  206. $arUserTmp = $dbUserTmp->fetch();
  207. $this->arResult['DATA'][$documentState['ID']]["WORKFLOW_STARTED_BY"] = CUser::FormatName($this->arParams["NAME_TEMPLATE"], $arUserTmp, true);
  208. $this->arResult['DATA'][$documentState['ID']]["WORKFLOW_STARTED_BY"] .= " [".$documentState["STARTED_BY"]."]";
  209. }
  210. $this->arResult['DATA'][$documentState['ID']]['MODULE_ID'] = $documentState["DOCUMENT_ID"][0];
  211. $this->arResult['DATA'][$documentState['ID']]['ENTITY'] = $documentState["DOCUMENT_ID"][1];
  212. $this->arResult['DATA'][$documentState['ID']]['DOCUMENT_ID'] = $documentState["DOCUMENT_ID"][2];
  213. }
  214. }
  215. }
  216. foreach ($this->arResult['DATA'] as $data)
  217. {
  218. if($documentStates)
  219. {
  220. if ($useComments)
  221. $workflows[] = 'WF_'.$data['WORKFLOW_ID'];
  222. }
  223. $actions = array();
  224. if ($data["DOCUMENT_URL"] <> '')
  225. $actions[] = array('ICONCLASS'=>'', 'DEFAULT' => true, 'TEXT'=>Loc::getMessage('CC_BLL_C_DOCUMENT'),
  226. 'ONCLICK'=>'window.open("'.$data["DOCUMENT_URL"].'");');
  227. $this->arResult['RECORDS'][] = array('data' => $data, 'actions' => $actions);
  228. }
  229. if ($useComments && $documentStates)
  230. {
  231. $workflows = array_unique($workflows);
  232. if ($workflows)
  233. {
  234. $iterator = CForumTopic::getList(array(), array("@XML_ID" => $workflows));
  235. while ($row = $iterator->fetch())
  236. {
  237. $this->arResult["COMMENTS_COUNT"][$row['XML_ID']] = $row['POSTS'];
  238. }
  239. }
  240. }
  241. $this->arResult['COUNTERS'] = array('all' => 0);
  242. $this->arResult["NAV_OBJECT"] = $elementObject;
  243. $componentObject = null;
  244. $this->arResult["GRID_ENABLE_NEXT_PAGE"] = ($elementObject->PAGEN < $elementObject->NavPageCount);
  245. $this->arResult["NAV_STRING"] = $elementObject->getPageNavStringEx(
  246. $componentObject, "", "grid", false, null, $gridOptions->getNavParams());
  247. $this->arResult["GRID_PAGE_SIZES"] = array(
  248. array("NAME" => "5", "VALUE" => "5"),
  249. array("NAME" => "10", "VALUE" => "10"),
  250. array("NAME" => "20", "VALUE" => "20"),
  251. array("NAME" => "50", "VALUE" => "50"),
  252. array("NAME" => "100", "VALUE" => "100"),
  253. array("NAME" => "200", "VALUE" => "200"),
  254. array("NAME" => "500", "VALUE" => "500")
  255. );
  256. $this->includeComponentTemplate();
  257. }
  258. protected function getApplication()
  259. {
  260. global $APPLICATION;
  261. return $APPLICATION;
  262. }
  263. protected function getUser()
  264. {
  265. global $USER;
  266. return $USER;
  267. }
  268. }