PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/socialnetwork/lib/integration/main/uiselector/entities.php

https://gitlab.com/alexprowars/bitrix
PHP | 345 lines | 306 code | 33 blank | 6 comment | 63 complexity | 24834a3367dd5a7e0c94594253b668f4 MD5 | raw file
  1. <?php
  2. /**
  3. * Bitrix Framework
  4. * @package bitrix
  5. * @subpackage socialnetwork
  6. * @copyright 2001-2017 Bitrix
  7. */
  8. namespace Bitrix\Socialnetwork\Integration\Main\UISelector;
  9. use Bitrix\Main\Localization\Loc;
  10. use Bitrix\Main\Loader;
  11. use Bitrix\Main\ModuleManager;
  12. Loc::loadMessages(__FILE__);
  13. class Entities
  14. {
  15. const EXTRANET_CONTEXT_EXTERNAL = 'E';
  16. const EXTRANET_CONTEXT_INTERNAL = 'I';
  17. public static function getData($options = array())
  18. {
  19. $result = array(
  20. 'ITEMS' => array(),
  21. 'ITEMS_LAST' => array(),
  22. 'DEST_SORT' => array(),
  23. 'ADDITIONAL_INFO' => array()
  24. );
  25. $filterParams = array(
  26. "DEST_CONTEXT" => $options["context"],
  27. "ALLOW_EMAIL_INVITATION" => (isset($options["allowEmailInvitation"]) && $options["allowEmailInvitation"] == "Y")
  28. );
  29. if (!empty($options['contextCode']))
  30. {
  31. $filterParams["CODE_TYPE"] = $options['contextCode'];
  32. }
  33. $dataAdditional = array();
  34. $destSortData = \CSocNetLogDestination::getDestinationSort($filterParams, $dataAdditional);
  35. $result["DEST_SORT"] = $destSortData;
  36. $lastItems = $items = array();
  37. \CSocNetLogDestination::fillLastDestination(
  38. $destSortData,
  39. $lastItems,
  40. array(
  41. "EMAILS" => (
  42. (
  43. isset($options["allowAddUser"])
  44. && $options["allowAddUser"] == 'Y'
  45. )
  46. || (
  47. isset($options["allowSearchEmailUsers"])
  48. && $options["allowSearchEmailUsers"] == 'Y'
  49. )
  50. || (
  51. isset($options["allowEmailInvitation"])
  52. && $options["allowEmailInvitation"] == 'Y'
  53. )
  54. ? 'Y'
  55. : 'N'
  56. ),
  57. "DATA_ADDITIONAL" => $dataAdditional
  58. )
  59. );
  60. if (
  61. !Handler::isExtranetUser()
  62. && \Bitrix\Socialnetwork\ComponentHelper::getAllowToAllDestination()
  63. && (!isset($options["enableAll"]) || $options["enableAll"] != 'N')
  64. )
  65. {
  66. $lastItems['GROUPS'] = array(
  67. 'UA' => true
  68. );
  69. $items['GROUPS'] = array(
  70. 'UA' => array(
  71. 'id' => 'UA',
  72. 'name' => (
  73. ModuleManager::isModuleInstalled('intranet')
  74. ? Loc::getMessage("MPF_DESTINATION_3")
  75. : Loc::getMessage("MPF_DESTINATION_4")
  76. )
  77. )
  78. );
  79. }
  80. $result["ITEMS_LAST"] = $lastItems;
  81. if ($options["enableSonetgroups"] != 'N')
  82. {
  83. $limitReached = false;
  84. $sonetGroupsList = \Bitrix\Socialnetwork\ComponentHelper::getSonetGroupAvailable(array(
  85. 'limit' => 100
  86. ), $limitReached);
  87. $result["SONETGROUPS_LIMITED"] = ($limitReached ? 'Y' : 'N');
  88. if(
  89. !empty($lastItems['SONETGROUPS'])
  90. && !empty($sonetGroupsList)
  91. )
  92. {
  93. $lastSonetGroupsList = array();
  94. foreach ($lastItems['SONETGROUPS'] as $value)
  95. {
  96. if (!array_key_exists($value, $sonetGroupsList))
  97. {
  98. $lastSonetGroupsList[] = intval(mb_substr($value, 2));
  99. }
  100. }
  101. if (!empty($lastSonetGroupsList))
  102. {
  103. $sonetGroupsAdditionalList = \CSocNetLogDestination::getSocnetGroup(array(
  104. 'features' => array("blog", array("premoderate_post", "moderate_post", "write_post", "full_post")),
  105. 'id' => $lastSonetGroupsList
  106. ));
  107. if (!empty($sonetGroupsAdditionalList))
  108. {
  109. $sonetGroupsList = array_merge($sonetGroupsList, $sonetGroupsAdditionalList);
  110. }
  111. }
  112. }
  113. $items['SONETGROUPS'] = $sonetGroupsList;
  114. }
  115. if (Handler::isExtranetUser())
  116. {
  117. $result['EXTRANET_USER'] = 'Y';
  118. $items['USERS'] = \CSocNetLogDestination::getExtranetUser();
  119. }
  120. else
  121. {
  122. $lastUserList = array();
  123. if(!empty($lastItems['USERS']))
  124. {
  125. foreach ($lastItems['USERS'] as $value)
  126. {
  127. $lastUserList[] = str_replace('U', '', $value);
  128. }
  129. }
  130. $result['EXTRANET_USER'] = 'N';
  131. if (!empty($lastUserList))
  132. {
  133. $items['USERS'] = \CSocNetLogDestination::getUsers(array(
  134. 'id' => $lastUserList,
  135. 'CRM_ENTITY' => ModuleManager::isModuleInstalled('crm')
  136. ));
  137. if (
  138. isset($options['extranetContext'])
  139. && in_array($options['extranetContext'], array(self::EXTRANET_CONTEXT_INTERNAL, self::EXTRANET_CONTEXT_EXTERNAL))
  140. )
  141. {
  142. foreach($items['USERS'] as $key => $value)
  143. {
  144. if (isset($value["isExtranet"]))
  145. {
  146. if (
  147. (
  148. $value["isExtranet"] == 'Y'
  149. && $options['extranetContext'] == self::EXTRANET_CONTEXT_INTERNAL
  150. )
  151. || (
  152. $value["isExtranet"] == 'N'
  153. && $options['extranetContext'] == self::EXTRANET_CONTEXT_EXTERNAL
  154. )
  155. )
  156. {
  157. unset($items['USERS'][$key]);
  158. }
  159. }
  160. }
  161. }
  162. }
  163. if (
  164. (
  165. isset($options["allowAddUser"])
  166. && $options["allowAddUser"] == 'Y'
  167. )
  168. || (
  169. isset($options["allowSearchEmailUsers"])
  170. && $options["allowSearchEmailUsers"] == 'Y'
  171. )
  172. || (
  173. isset($options["allowEmailInvitation"])
  174. && $options["allowEmailInvitation"] == 'Y'
  175. )
  176. )
  177. {
  178. $items['LAST'] = $result["ITEMS_LAST"];
  179. \CSocNetLogDestination::fillEmails($items);
  180. $result["ITEMS_LAST"] = $items['LAST'];
  181. unset($items['LAST']);
  182. }
  183. }
  184. if (
  185. $options["enableDepartments"] == "Y"
  186. && ModuleManager::isModuleInstalled('intranet')
  187. && !Handler::isExtranetUser()
  188. )
  189. {
  190. $structure = \CSocNetLogDestination::getStucture(array("LAZY_LOAD" => true));
  191. $items['DEPARTMENT'] = $structure['department'];
  192. $items['DEPARTMENT_RELATION'] = $structure['department_relation'];
  193. $result['ADDITIONAL_INFO']['DEPARTMENT'] = array(
  194. 'PREFIX' => 'DR',
  195. 'TYPE' => 'tree'
  196. );
  197. }
  198. $result["ITEMS"] = $items;
  199. $lastItems = array();
  200. foreach($result["ITEMS_LAST"] as $group => $items)
  201. {
  202. $i = 0;
  203. foreach($result["ITEMS_LAST"][$group] as $key => $value)
  204. {
  205. $lastItems[$group][$key] = ++$i;
  206. }
  207. }
  208. $result["ITEMS_LAST"] = $lastItems;
  209. return $result;
  210. }
  211. public static function getList($params = array())
  212. {
  213. $itemsSelected = $params['itemsSelected'];
  214. $entities = array(
  215. 'USERS' => array(),
  216. 'SONETGROUPS' => array(),
  217. 'GROUPS' => array(),
  218. 'DEPARTMENTS' => array()
  219. );
  220. $sonetGroupIdList = $userIdList = $departmentIdList = array();
  221. foreach ($itemsSelected as $code => $entityGroup)
  222. {
  223. if ($entityGroup == 'users')
  224. {
  225. $userIdList[] = str_replace('U', '', $code);
  226. }
  227. elseif ($entityGroup == 'sonetgroups')
  228. {
  229. $sonetGroupIdList[] = str_replace('SG', '', $code);
  230. }
  231. elseif ($entityGroup == 'department')
  232. {
  233. $departmentIdList[] = str_replace('DR', '', $code);
  234. }
  235. }
  236. if (!empty($userIdList))
  237. {
  238. $entities['USERS'] = self::getUsers(array('id' => $userIdList));
  239. }
  240. if (!empty($sonetGroupIdList))
  241. {
  242. $entities['SONETGROUPS'] = self::getSonetgroups(array('id' => $sonetGroupIdList));
  243. }
  244. if (!empty($departmentIdList))
  245. {
  246. $entities['DEPARTMENTS'] = self::getDepartments(array('id' => $departmentIdList));
  247. }
  248. if (
  249. !Handler::isExtranetUser()
  250. && \Bitrix\Socialnetwork\ComponentHelper::getAllowToAllDestination()
  251. )
  252. {
  253. $entities['GROUPS'] = array(
  254. 'UA' => array(
  255. 'id' => 'UA',
  256. 'name' => (
  257. ModuleManager::isModuleInstalled('intranet')
  258. ? Loc::getMessage("MPF_DESTINATION_3")
  259. : Loc::getMessage("MPF_DESTINATION_4")
  260. )
  261. )
  262. );
  263. }
  264. else
  265. {
  266. $entities['GROUPS'] = array();
  267. }
  268. return $entities;
  269. }
  270. protected static function getUsers($params = array())
  271. {
  272. return \CSocNetLogDestination::getUsers($params);
  273. }
  274. protected static function getSonetgroups($params = array())
  275. {
  276. return \CSocNetLogDestination::getSocnetGroup($params);
  277. }
  278. protected static function getDepartments($params = array())
  279. {
  280. $result = array();
  281. if (
  282. !empty($params['id'])
  283. && is_array($params['id'])
  284. && Loader::includeModule('intranet')
  285. )
  286. {
  287. $departmentsList = \CIntranetUtils::getDepartmentsData($params['id']);
  288. foreach($departmentsList as $id => $name)
  289. {
  290. $result['DR'.$id] = array(
  291. 'id' => 'DR'.$id,
  292. 'entityId' => $id,
  293. 'name' => htmlspecialcharsbx($name),
  294. 'parent' => false
  295. );
  296. }
  297. }
  298. return $result;
  299. }
  300. public static function getDepartmentData($requestFields = []): array
  301. {
  302. $allowSearchSelf = (!isset($requestFields['allowSearchSelf']) || $requestFields['allowSearchSelf'] !== 'N');
  303. return [
  304. 'USERS' => \CSocNetLogDestination::getUsers([
  305. 'deportament_id' => $requestFields['DEPARTMENT_ID'],
  306. 'NAME_TEMPLATE' => Handler::getNameTemplate($requestFields),
  307. ], $allowSearchSelf),
  308. 'leafEntityType' => 'USERS',
  309. 'dataOnly' => true,
  310. ];
  311. }
  312. }