BxForumModule.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxForumModule extends BxBaseModTextModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. public function sortParticipants ($aParticipants, $iProfileIdLastComment, $iProfileIdAuthor, $iProfileIdCurrent = 0)
  18. {
  19. if (!$iProfileIdCurrent)
  20. $iProfileIdCurrent = bx_get_logged_profile_id();
  21. $aMoveUp = array($iProfileIdCurrent, $iProfileIdLastComment, $iProfileIdAuthor);
  22. asort($aParticipants, SORT_NUMERIC);
  23. foreach ($aMoveUp as $iProfileId) {
  24. if (!isset($aParticipants[$iProfileId]))
  25. continue;
  26. $a = array($iProfileId => $aParticipants[$iProfileId]);
  27. unset($aParticipants[$iProfileId]);
  28. $aParticipants = $a + $aParticipants;
  29. }
  30. return $aParticipants;
  31. }
  32. /**
  33. * Action methods
  34. */
  35. public function actionUpdateStatus($sAction = '', $iContentId = 0)
  36. {
  37. if(empty($sAction) && bx_get('action') !== false)
  38. $sAction = bx_process_input(bx_get('action'));
  39. if(empty($iContentId) && bx_get('id') !== false)
  40. $iContentId = (int)bx_get('id');
  41. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  42. if(empty($aContentInfo) || !is_array($aContentInfo))
  43. return echoJson(array('code' => 1, 'message' => _t('_bx_forum_err_not_found')));
  44. $sMethodCheck = 'checkAllowed' . bx_gen_method_name($sAction) . 'AnyEntry';
  45. $sResult = $this->$sMethodCheck($aContentInfo);
  46. if($sResult !== CHECK_ACTION_RESULT_ALLOWED)
  47. return echoJson(array('code' => 2, 'message' => $sResult));
  48. bx_audit(
  49. $iContentId,
  50. $this->getName(),
  51. '_sys_audit_action_' . $sAction,
  52. $this->_prepareAuditParams($aContentInfo, false)
  53. );
  54. if(!$this->_oDb->updateStatus($sAction, $aContentInfo))
  55. return echoJson(array('code' => 3, 'message' => _t('_error occured')));
  56. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  57. $this->alertAfterEdit($aContentInfo);
  58. echoJson(array('code' => 0, 'id' => $iContentId, 'reload' => 1));
  59. }
  60. public function actionAjaxGetAuthors()
  61. {
  62. $aResult = BxDolService::call('system', 'profiles_search', array(bx_get('term')), 'TemplServiceProfiles');
  63. header('Content-Type:text/javascript; charset=utf-8');
  64. echo json_encode($aResult);
  65. }
  66. /**
  67. * Service methods
  68. */
  69. public function serviceGetSafeServices()
  70. {
  71. $a = parent::serviceGetSafeServices();
  72. return array_merge($a, array (
  73. 'BrowseNew' => '',
  74. 'BrowseLatest' => '',
  75. 'BrowseTop' => '',
  76. 'BrowsePopular' => '',
  77. 'BrowseUpdated' => '',
  78. 'BrowsePartaken' => '',
  79. 'BrowseIndex' => '',
  80. 'Search' => '',
  81. ));
  82. }
  83. /**
  84. * @page service Service Calls
  85. * @section bx_forum Discussions
  86. * @subsection bx_forum-other Other
  87. * @subsubsection bx_forum-get_searchable_fields get_searchable_fields
  88. *
  89. * @code bx_srv('bx_forum', 'get_searchable_fields', [...]); @endcode
  90. *
  91. * Get searchable fields for Studio settings.
  92. *
  93. * @return an array with key-value pairs to be used in settings dropdown field.
  94. *
  95. * @see BxForumModule::serviceGetSearchableFields
  96. */
  97. /**
  98. * @ref bx_forum-get_searchable_fields "get_searchable_fields"
  99. */
  100. public function serviceGetSearchableFields ($aInputsAdd = array())
  101. {
  102. $CNF = &$this->_oConfig->CNF;
  103. $aResult = parent::serviceGetSearchableFields($aInputsAdd);
  104. $aResult[$CNF['FIELD_TEXT_COMMENTS']] = _t('_bx_forum_form_entry_input_text_comments');
  105. return $aResult;
  106. }
  107. /**
  108. * Service methods
  109. */
  110. /**
  111. * @page service Service Calls
  112. * @section bx_forum Discussions
  113. * @subsection bx_forum-other Other
  114. * @subsubsection bx_forum-get_info get_info
  115. *
  116. * @code bx_srv('bx_forum', 'get_info', [...]); @endcode
  117. *
  118. * Get content info by content ID. Is used in "Content Info Objects" system.
  119. *
  120. * @param $iContentId integer value with content ID.
  121. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  122. * @return an array with content info. Empty array is returned if something is wrong.
  123. *
  124. * @see BxForumModule::serviceGetInfo
  125. */
  126. /**
  127. * @ref bx_forum-get_info "get_info"
  128. */
  129. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  130. {
  131. $aContentInfo = $this->_getFields($iContentId);
  132. if(empty($aContentInfo))
  133. return array();
  134. return $aContentInfo;
  135. }
  136. /**
  137. * @page service Service Calls
  138. * @section bx_forum Discussions
  139. * @subsection bx_forum-page_blocks Page Blocks
  140. * @subsubsection bx_forum-categories_list categories_list
  141. *
  142. * @code bx_srv('bx_forum', 'categories_list', [...]); @endcode
  143. *
  144. * Get reviews rating for particular content
  145. * @param $aParams additional params array, such as 'show_empty'
  146. *
  147. * @see BxForumModule::serviceCategoriesList
  148. */
  149. /**
  150. * @ref bx_forum-categories_list "categories_list"
  151. */
  152. public function serviceCategoriesList($aParams = array())
  153. {
  154. $aCategoriest = bx_srv('system', 'categories_list', ['bx_forum_cats', ['show_empty' => true]],'TemplServiceCategory');
  155. $bShowEmpty = isset($aParams['show_empty']) ? (bool)$aParams['show_empty'] : false;
  156. $bShowEmptyCategories = isset($aParams['show_empty_categories']) ? (bool)$aParams['show_empty_categories'] : false;
  157. if (!($o = BxDolCategory::getObjectInstance('bx_forum_cats')))
  158. return $bShowEmpty ? MsgBox(_t('_Empty')) : '';
  159. $aCategories = $o->getCategoriesList($bShowEmptyCategories, true);
  160. if(!isset($aCategories['bx_repeat:cats']))
  161. return $bShowEmpty ? MsgBox(_t('_Empty')) : '';
  162. foreach ($aCategories['bx_repeat:cats'] as $sKey => $aCategory) {
  163. $aCategories['bx_repeat:cats'][$sKey]['icon'] = '';
  164. $aCategories['bx_repeat:cats'][$sKey]['class'] = $aCategory['value'] == bx_get('category') ? 'bx-forum-category-list-item-selected' : '';
  165. $aCategoryData = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $aCategory['value']));
  166. if(isset($aCategoryData['icon']))
  167. $aCategories['bx_repeat:cats'][$sKey]['icon'] = $this->_oTemplate->getImage($aCategoryData['icon'], array('class' => 'sys-icon sys-colored'));
  168. if(isset($aCategoryData['visible_for_levels']) && $aCategoryData['visible_for_levels'] != '' && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategoryData['visible_for_levels'])){
  169. unset($aCategories['bx_repeat:cats'][$sKey]);
  170. }
  171. }
  172. return $this->_oTemplate->parseHtmlByName('category_list.html', $aCategories);
  173. }
  174. /**
  175. * @page service Service Calls
  176. * @section bx_forum Discussions
  177. * @subsection bx_forum-page_blocks Page Blocks
  178. * @subsubsection bx_forum-browse_new browse_new
  179. *
  180. * @code bx_srv('bx_forum', 'browse_new', [...]); @endcode
  181. *
  182. * Get page block with a list of items ordered by newness and represented as table.
  183. *
  184. * @param $sUnitView (optional) string with unit view type.
  185. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  186. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  187. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  188. *
  189. * @see BxForumModule::serviceBrowseNew
  190. */
  191. /**
  192. * @ref bx_forum-browse_new "browse_new"
  193. */
  194. public function serviceBrowseNew ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  195. {
  196. $sType = 'new';
  197. if($sUnitView != 'table')
  198. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  199. return $this->_serviceBrowseTable(array(
  200. 'type' => $sType,
  201. 'empty_message' => $bEmptyMessage,
  202. 'ajax_paginate' => $bAjaxPaginate
  203. ), $bShowHeader);
  204. }
  205. /**
  206. * @page service Service Calls
  207. * @section bx_forum Discussions
  208. * @subsection bx_forum-page_blocks Page Blocks
  209. * @subsubsection bx_forum-browse_latest browse_latest
  210. *
  211. * @code bx_srv('bx_forum', 'browse_latest', [...]); @endcode
  212. *
  213. * Get page block with a list of items ordered by Recent Posts in them and represented as table.
  214. *
  215. * @param $sUnitView (optional) string with unit view type.
  216. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  217. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  218. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  219. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  220. *
  221. * @see BxForumModule::serviceBrowseNew
  222. */
  223. /**
  224. * @ref bx_forum-browse_latest "browse_latest"
  225. */
  226. public function serviceBrowseLatest($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = true)
  227. {
  228. $sType = 'latest';
  229. if($sUnitView != 'table')
  230. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  231. return $this->_serviceBrowseTable(array(
  232. 'type' => $sType,
  233. 'empty_message' => $bEmptyMessage,
  234. 'ajax_paginate' => $bAjaxPaginate
  235. ), $bShowHeader);
  236. }
  237. /**
  238. * @page service Service Calls
  239. * @section bx_forum Discussions
  240. * @subsection bx_forum-page_blocks Page Blocks
  241. * @subsubsection bx_forum-browse_featured browse_featured
  242. *
  243. * @code bx_srv('bx_forum', 'browse_featured', [...]); @endcode
  244. *
  245. * Get page block with a list of featured items represented as table.
  246. *
  247. * @param $sUnitView (optional) string with unit view type.
  248. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  249. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  250. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  251. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  252. *
  253. * @see BxForumModule::serviceBrowseFeatured
  254. */
  255. /**
  256. * @ref bx_forum-browse_featured "browse_featured"
  257. */
  258. public function serviceBrowseFeatured($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true, $bShowHeader = false)
  259. {
  260. $CNF = &$this->_oConfig->CNF;
  261. $sType = 'featured';
  262. if($sUnitView != 'table')
  263. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  264. return $this->_serviceBrowseTable(array(
  265. 'grid' => $CNF['OBJECT_GRID_FEATURE'],
  266. 'type' => $sType,
  267. 'where' => array('fld' => 'featured', 'val' => 0, 'opr' => '<>'),
  268. 'empty_message' => $bEmptyMessage,
  269. 'ajax_paginate' => $bAjaxPaginate
  270. ), $bShowHeader);
  271. }
  272. /**
  273. * @page service Service Calls
  274. * @section bx_forum Discussions
  275. * @subsection bx_forum-page_blocks Page Blocks
  276. * @subsubsection bx_forum-browse_top browse_top
  277. *
  278. * @code bx_srv('bx_forum', 'browse_top', [...]); @endcode
  279. *
  280. * Get page block with a list of items ordered by a number of comments and represented as table.
  281. *
  282. * @param $sUnitView (optional) string with unit view type.
  283. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  284. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  285. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  286. *
  287. * @see BxForumModule::serviceBrowseTop
  288. */
  289. /**
  290. * @ref bx_forum-browse_top "browse_top"
  291. */
  292. public function serviceBrowseTop($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = true)
  293. {
  294. $sType = 'top';
  295. if($sUnitView != 'table')
  296. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  297. return $this->_serviceBrowseTable(array(
  298. 'type' => $sType,
  299. 'empty_message' => $bEmptyMessage,
  300. 'ajax_paginate' => $bAjaxPaginate
  301. ), $bShowHeader);
  302. }
  303. /**
  304. * @page service Service Calls
  305. * @section bx_forum Discussions
  306. * @subsection bx_forum-page_blocks Page Blocks
  307. * @subsubsection bx_forum-browse_popular browse_popular
  308. *
  309. * @code bx_srv('bx_forum', 'browse_popular', [...]); @endcode
  310. *
  311. * Get page block with a list of items ordered by a number of views and represented as table.
  312. *
  313. * @param $sUnitView (optional) string with unit view type.
  314. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  315. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  316. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  317. *
  318. * @see BxForumModule::serviceBrowsePopular
  319. */
  320. /**
  321. * @ref bx_forum-browse_popular "browse_popular"
  322. */
  323. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  324. {
  325. $sType = 'popular';
  326. if($sUnitView != 'table')
  327. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  328. return $this->_serviceBrowseTable(array(
  329. 'type' => $sType,
  330. 'empty_message' => $bEmptyMessage,
  331. 'ajax_paginate' => $bAjaxPaginate
  332. ), $bShowHeader);
  333. }
  334. /**
  335. * @page service Service Calls
  336. * @section bx_forum Discussions
  337. * @subsection bx_forum-page_blocks Page Blocks
  338. * @subsubsection bx_forum-browse_updated browse_updated
  339. *
  340. * @code bx_srv('bx_forum', 'browse_updated', [...]); @endcode
  341. *
  342. * Get page block with a list of updated items represented as table.
  343. *
  344. * @param $sUnitView (optional) string with unit view type.
  345. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  346. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  347. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  348. *
  349. * @see BxForumModule::serviceBrowseUpdated
  350. */
  351. /**
  352. * @ref bx_forum-browse_updated "browse_updated"
  353. */
  354. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  355. {
  356. $sType = 'updated';
  357. if($sUnitView != 'table')
  358. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  359. return $this->_serviceBrowseTable(array(
  360. 'type' => $sType,
  361. 'empty_message' => $bEmptyMessage,
  362. 'ajax_paginate' => $bAjaxPaginate
  363. ), $bShowHeader);
  364. }
  365. /**
  366. * @page service Service Calls
  367. * @section bx_forum Discussions
  368. * @subsection bx_forum-page_blocks Page Blocks
  369. * @subsubsection bx_forum-browse_partaken browse_partaken
  370. *
  371. * @code bx_srv('bx_forum', 'browse_partaken', [...]); @endcode
  372. *
  373. * Get page block with a list of partaken items represented as table.
  374. *
  375. * @param $sUnitView (optional) string with unit view type.
  376. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  377. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  378. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  379. *
  380. * @see BxForumModule::serviceBrowsePartaken
  381. */
  382. /**
  383. * @ref bx_forum-browse_partaken "browse_partaken"
  384. */
  385. public function serviceBrowsePartaken ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  386. {
  387. $sType = 'partaken';
  388. if($sUnitView != 'table')
  389. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  390. $aSelect = array(
  391. 'tbla' => 'tco',
  392. 'fld' => 'cmt_author_id',
  393. );
  394. $aJoin = array(
  395. 'tp' => 'INNER',
  396. 'tbl1' => 'bx_forum_cmts',
  397. 'tbl1a' => 'tco',
  398. 'fld1' => 'cmt_object_id',
  399. 'tbl2' => 'bx_forum_discussions',
  400. 'fld2' => 'id'
  401. );
  402. $aWhere = array(
  403. 'tbl' => 'tco',
  404. 'fld' => 'cmt_author_id',
  405. 'val' => bx_get_logged_profile_id(),
  406. 'opr' => '='
  407. );
  408. $aGroupBy = array(
  409. 'tbl' => 'bx_forum_discussions',
  410. 'fld' => 'id',
  411. );
  412. return $this->_serviceBrowseTable(array(
  413. 'type' => $sType,
  414. 'select' => $aSelect,
  415. 'join' => $aJoin,
  416. 'where' => $aWhere,
  417. 'group_by' => $aGroupBy,
  418. 'empty_message' => $bEmptyMessage,
  419. 'ajax_paginate' => $bAjaxPaginate
  420. ), $bShowHeader);
  421. }
  422. /**
  423. * @page service Service Calls
  424. * @section bx_forum Discussions
  425. * @subsection bx_forum-page_blocks Page Blocks
  426. * @subsubsection bx_forum-browse_index browse_index
  427. *
  428. * @code bx_srv('bx_forum', 'browse_index', [...]); @endcode
  429. *
  430. * Get page block for Site's Home page with a list of items ordered by newness and represented as table.
  431. *
  432. * @param $sUnitView (optional) string with unit view type.
  433. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  434. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  435. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  436. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  437. *
  438. * @see BxForumModule::serviceBrowseIndex
  439. */
  440. /**
  441. * @ref bx_forum-browse_index "browse_index"
  442. */
  443. public function serviceBrowseIndex($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  444. {
  445. $sType = 'index';
  446. if($sUnitView != 'table')
  447. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  448. return $this->_serviceBrowseTable(array(
  449. 'type' => $sType,
  450. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_index'),
  451. 'empty_message' => $bEmptyMessage,
  452. 'ajax_paginate' => $bAjaxPaginate
  453. ), $bShowHeader);
  454. }
  455. /**
  456. * @page service Service Calls
  457. * @section bx_forum Discussions
  458. * @subsection bx_forum-page_blocks Page Blocks
  459. * @subsubsection bx_forum-browse_author browse_author
  460. *
  461. * @code bx_srv('bx_forum', 'browse_author', [...]); @endcode
  462. *
  463. * Get page block with a list of items filtered by Author and represented as table.
  464. *
  465. * @param $iProfileId (optional) integer value with author ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  466. * @param $aParams (optional) an array of additional params. It's not used for now.
  467. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  468. *
  469. * @see BxForumModule::serviceBrowseAuthor
  470. */
  471. /**
  472. * @ref bx_forum-browse_author "browse_author"
  473. */
  474. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  475. {
  476. if(!$iProfileId)
  477. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  478. if(!$iProfileId)
  479. return '';
  480. $bEmptyMessage = true;
  481. if(isset($aParams['empty_message'])) {
  482. $bEmptyMessage = (bool)$aParams['empty_message'];
  483. unset($aParams['empty_message']);
  484. }
  485. $bAjaxPaginate = true;
  486. if(isset($aParams['ajax_paginate'])) {
  487. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  488. unset($aParams['ajax_paginate']);
  489. }
  490. if(isset($aParams['unit_view']) && $aParams['unit_view'] != 'table')
  491. return $this->_serviceBrowse('author', array_merge(array('author' => $iProfileId), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  492. return $this->_serviceBrowseTable(array(
  493. 'type' => 'author',
  494. 'author' => $iProfileId,
  495. 'where' => array('fld' => 'author', 'val' => $iProfileId, 'opr' => '='),
  496. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_profile'),
  497. 'empty_message' => $bEmptyMessage,
  498. 'ajax_paginate' => $bAjaxPaginate
  499. ), false);
  500. }
  501. /**
  502. * @page service Service Calls
  503. * @section bx_forum Discussions
  504. * @subsection bx_forum-page_blocks Page Blocks
  505. * @subsubsection bx_forum-browse_favorite browse_favorite
  506. *
  507. * @code bx_srv('bx_forum', 'browse_favorite', [...]); @endcode
  508. *
  509. * Get page block with a list of favorited items by some profile and represented as table.
  510. *
  511. * @param $iProfileId (optional) integer value with profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  512. * @param $aParams (optional) an array of additional params. It's not used for now.
  513. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  514. *
  515. * @see BxForumModule::serviceBrowseFavorite
  516. */
  517. /**
  518. * @ref bx_forum-browse_favorite "browse_favorite"
  519. */
  520. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  521. {
  522. $CNF = &$this->_oConfig->CNF;
  523. $oProfile = null;
  524. if((int)$iProfileId)
  525. $oProfile = BxDolProfile::getInstance($iProfileId);
  526. if(!$oProfile && bx_get('profile_id') !== false)
  527. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  528. if(!$oProfile)
  529. $oProfile = BxDolProfile::getInstance();
  530. if(!$oProfile)
  531. return '';
  532. $iProfileAuthor = $oProfile->id();
  533. $oFavorite = $this->getObjectFavorite();
  534. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  535. return '';
  536. $bEmptyMessage = false;
  537. if(isset($aParams['empty_message'])) {
  538. $bEmptyMessage = (bool)$aParams['empty_message'];
  539. unset($aParams['empty_message']);
  540. }
  541. $bAjaxPaginate = true;
  542. if(isset($aParams['ajax_paginate'])) {
  543. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  544. unset($aParams['ajax_paginate']);
  545. }
  546. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor);
  547. if(empty($aConditions) || !is_array($aConditions))
  548. return '';
  549. $aJoinGroup = array('grp' => true, 'cnds' => array());
  550. if(!empty($aConditions['join']))
  551. foreach($aConditions['join'] as $aCondition)
  552. $aJoinGroup['cnds'][] = array(
  553. 'tp' => $aCondition['type'],
  554. 'tbl1' => $aCondition['table'],
  555. 'fld1' => $aCondition['onField'],
  556. 'tbl2' => $aCondition['mainTable'],
  557. 'fld2' => $aCondition['mainField']
  558. );
  559. $aWhereGroup = array('grp' => true, 'opr' => 'AND', 'cnds' => array());
  560. if(!empty($aConditions['restriction']))
  561. foreach($aConditions['restriction'] as $aCondition)
  562. $aWhereGroup['cnds'][] = array(
  563. 'tbl' => (!empty($aCondition['table']) ? $aCondition['table'] : ''),
  564. 'fld' => $aCondition['field'],
  565. 'val' => $aCondition['value'],
  566. 'opr' => $aCondition['operator']
  567. );
  568. return $this->_serviceBrowseTable(array(
  569. 'grid' => $CNF['OBJECT_GRID_FAVORITE'],
  570. 'type' => 'favorite',
  571. 'author' => $iProfileId,
  572. 'join' => $aJoinGroup,
  573. 'where' => $aWhereGroup,
  574. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_profile'),
  575. 'empty_message' => $bEmptyMessage,
  576. 'ajax_paginate' => $bAjaxPaginate
  577. ), false);
  578. }
  579. /**
  580. * @page service Service Calls
  581. * @section bx_forum Discussions
  582. * @subsection bx_forum-page_blocks Page Blocks
  583. * @subsubsection bx_forum-browse_category browse_category
  584. *
  585. * @code bx_srv('bx_forum', 'browse_category', [...]); @endcode
  586. *
  587. * Get page block with a list of items filter by some category and represented as table.
  588. *
  589. * @param $sUnitView (optional) string with unit view type.
  590. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  591. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  592. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  593. *
  594. * @see BxForumModule::serviceBrowseCategory
  595. */
  596. /**
  597. * @ref bx_forum-browse_category "browse_category"
  598. */
  599. public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = true)
  600. {
  601. $sType = 'category';
  602. $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
  603. $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
  604. if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
  605. return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
  606. if($sUnitView != 'table') {
  607. $aParams = array('category' => $iCategory);
  608. if ($sUnitView)
  609. $aParams['unit_view'] = $sUnitView;
  610. return $this->_serviceBrowse($sType, $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  611. }
  612. return $this->_serviceBrowseTable(array(
  613. 'type' => $sType,
  614. 'where' => array('fld' => 'cat', 'val' => $iCategory, 'opr' => '='),
  615. 'empty_message' => $bEmptyMessage,
  616. 'ajax_paginate' => $bAjaxPaginate
  617. ), $bShowHeader);
  618. }
  619. /**
  620. * @page service Service Calls
  621. * @section bx_forum Discussions
  622. * @subsection bx_forum-page_blocks Page Blocks
  623. * @subsubsection bx_forum-browse_keyword browse_keyword
  624. *
  625. * @code bx_srv('bx_forum', 'browse_keyword', [...]); @endcode
  626. *
  627. * Get page block with a list of items filter by some keyword and represented as table.
  628. *
  629. * @param $sUnitView (optional) string with unit view type.
  630. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  631. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  632. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  633. *
  634. * @see BxForumModule::serviceBrowseKeyword
  635. */
  636. /**
  637. * @ref bx_forum-browse_keyword "browse_keyword"
  638. */
  639. public function serviceBrowseKeyword($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  640. {
  641. $sType = 'keyword';
  642. $sKeyword = bx_process_input(bx_get('keyword'));
  643. if($sUnitView != 'table')
  644. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  645. return $this->_serviceBrowseTable(array(
  646. 'type' => $sType,
  647. 'where' => $this->_getSearchKeywordDescriptor('#' . $sKeyword),
  648. 'empty_message' => $bEmptyMessage,
  649. 'ajax_paginate' => $bAjaxPaginate
  650. ), $bShowHeader);
  651. }
  652. /**
  653. * @page service Service Calls
  654. * @section bx_forum Discussions
  655. * @subsection bx_forum-page_blocks Page Blocks
  656. * @subsubsection bx_forum-browse_search_results browse_search_results
  657. *
  658. * @code bx_srv('bx_forum', 'browse_search_results', [...]); @endcode
  659. *
  660. * Get page block with search results by Author(s), Category, Keyword represented as table.
  661. *
  662. * @param $sUnitView (optional) string with unit view type.
  663. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  664. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  665. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  666. *
  667. * @see BxForumModule::serviceBrowseSearchResults
  668. */
  669. /**
  670. * @ref bx_forum-browse_search_results "browse_search_results"
  671. */
  672. public function serviceBrowseSearchResults($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  673. {
  674. $sType = 'search';
  675. $aAuthors = bx_process_input(bx_get('author'));
  676. $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
  677. $sKeyword = bx_process_input(bx_get('keyword'));
  678. $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
  679. if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
  680. return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
  681. if($sUnitView != 'table')
  682. return $this->_serviceBrowse('', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  683. $aWhereGroupAnd = array('grp' => true, 'opr' => 'AND', 'cnds' => array());
  684. if(!empty($aAuthors) && is_array($aAuthors))
  685. $aWhereGroupAnd['cnds'][] = $this->_getSearchAuthorDescriptor($aAuthors);
  686. if(!empty($iCategory))
  687. $aWhereGroupAnd['cnds'][] = array('fld' => 'cat', 'val' => $iCategory, 'opr' => '=');
  688. if(!empty($sKeyword))
  689. $aWhereGroupAnd['cnds'][] = $this->_getSearchKeywordDescriptor($sKeyword);
  690. return $this->_serviceBrowseTable(array(
  691. 'type' => $sType,
  692. 'where' => $aWhereGroupAnd,
  693. 'empty_message' => $bEmptyMessage,
  694. 'ajax_paginate' => $bAjaxPaginate
  695. ), false);
  696. }
  697. /**
  698. * @page service Service Calls
  699. * @section bx_forum Discussions
  700. * @subsection bx_forum-other Other
  701. * @subsubsection bx_forum-get_discussions_num get_discussions_num
  702. *
  703. * @code bx_srv('bx_forum', 'get_discussions_num', [...]); @endcode
  704. *
  705. * Get number of discussions for some profile.
  706. *
  707. * @param $iProfileId (optional) profile to get discussions for, if omitted then currently logged in profile is used.
  708. * @return integer value with a number of discussions.
  709. *
  710. * @see BxForumModule::serviceGetDiscussionsNum
  711. */
  712. /**
  713. * @ref bx_forum-get_discussions_num "get_discussions_num"
  714. */
  715. public function serviceGetDiscussionsNum ($iProfileId = 0)
  716. {
  717. if (!$iProfileId)
  718. $iProfileId = bx_get_logged_profile_id();
  719. return $this->_oDb->getEntriesNumByAuthor((int)$iProfileId);
  720. }
  721. /**
  722. * @page service Service Calls
  723. * @section bx_forum Discussions
  724. * @subsection bx_forum-other Other
  725. * @subsubsection bx_forum-get_unreplied_discussions_num get_unreplied_discussions_num
  726. *
  727. * @code bx_srv('bx_forum', 'get_unreplied_discussions_num', [...]); @endcode
  728. *
  729. * Get number of unreplied discussions for some profile.
  730. *
  731. * @param $iProfileId (optional) profile to get unreplied discussions for, if omitted then currently logged is profile is used.
  732. * @return integer value with a number of discussions.
  733. *
  734. * @see BxForumModule::serviceGetUnrepliedDiscussionsNum
  735. */
  736. /**
  737. * @ref bx_forum-get_unreplied_discussions_num "get_unreplied_discussions_num"
  738. */
  739. public function serviceGetUnrepliedDiscussionsNum ($iProfileId = 0)
  740. {
  741. if (!$iProfileId)
  742. $iProfileId = bx_get_logged_profile_id();
  743. return $this->_oDb->getUnrepliedDiscussionsNum((int)$iProfileId);
  744. }
  745. /**
  746. *
  747. */
  748. /**
  749. * @page service Service Calls
  750. * @section bx_forum Discussions
  751. * @subsection bx_forum-other Other
  752. * @subsubsection bx_forum-trigger_comment_post trigger_comment_post
  753. *
  754. * @code bx_srv('bx_forum', 'trigger_comment_post', [...]); @endcode
  755. *
  756. * Update last comment time and author when new comment was added in the discussion.
  757. *
  758. * @param $iContentId integer value with content ID.
  759. * @param $iProfileId integer value with profile ID.
  760. * @param $iCommentId integer value with comment ID.
  761. * @param $iTimestamp (optional) date in UNIX Timestamp format, if omitted then current date is used.
  762. * @param $sCommentText (optional) string value with text of comment.
  763. * @return boolean value determining where the operation is successful or not.
  764. *
  765. * @see BxForumModule::serviceTriggerCommentPost
  766. */
  767. /**
  768. * @ref bx_forum-trigger_comment_post "trigger_comment_post"
  769. */
  770. public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '')
  771. {
  772. $CNF = $this->_oConfig->CNF;
  773. $iContentId = (int)$iContentId;
  774. if(!$iContentId)
  775. return false;
  776. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  777. if(!$aContentInfo)
  778. return false;
  779. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  780. if(!$oCmts)
  781. return false;
  782. if(!$iTimestamp)
  783. $iTimestamp = time();
  784. if(!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iCommentId, $iTimestamp))
  785. return false;
  786. // send notification to author
  787. if($iProfileId != $aContentInfo[$CNF['FIELD_AUTHOR']]) {
  788. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  789. if($oProfile)
  790. sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  791. 'SenderDisplayName' => $oProfile->getDisplayName(),
  792. 'SenderUrl' => $oProfile->getUrl(),
  793. 'PageUrl' => $oCmts->getItemUrl($iCommentId),
  794. 'PageTitle' => $oCmts->getObjectTitle(),
  795. 'Message' => $sCommentText,
  796. ), BX_EMAIL_NOTIFY);
  797. }
  798. return true;
  799. }
  800. /**
  801. * @page service Service Calls
  802. * @section bx_forum Discussions
  803. * @subsection bx_forum-page_blocks Page Blocks
  804. * @subsubsection bx_forum-entity_participants entity_participants
  805. *
  806. * @code bx_srv('bx_forum', 'entity_participants', [...]); @endcode
  807. *
  808. * Get page block with discussion's collaborators.
  809. *
  810. * @param $iContentId (optional) content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  811. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  812. *
  813. * @see BxForumModule::serviceEntityParticipants
  814. */
  815. /**
  816. * @ref bx_forum-entity_participants "entity_participants"
  817. */
  818. public function serviceEntityParticipants ($iContentId = 0)
  819. {
  820. if (!$iContentId)
  821. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  822. if (!$iContentId)
  823. return false;
  824. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  825. if (!$aContentInfo)
  826. return false;
  827. return $this->_oTemplate->entryParticipants ($aContentInfo, 5, 'right');
  828. }
  829. /**
  830. * @page service Service Calls
  831. * @section bx_forum Discussions
  832. * @subsection bx_forum-page_blocks Page Blocks
  833. * @subsubsection bx_forum-search search
  834. *
  835. * @code bx_srv('bx_forum', 'search', [...]); @endcode
  836. *
  837. * Get page block with search form.
  838. *
  839. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  840. *
  841. * @see BxForumModule::serviceSearch
  842. */
  843. /**
  844. * @ref bx_forum-search "search"
  845. */
  846. public function serviceSearch()
  847. {
  848. $CNF = $this->_oConfig->CNF;
  849. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SEARCH'], $CNF['OBJECT_FORM_SEARCH_DISPLAY_FULL'], $this->_oTemplate);
  850. $oForm->initChecker();
  851. return $oForm->getCode();
  852. }
  853. public function checkAllowedSubscribe(&$aDataEntry, $isPerformAction = false)
  854. {
  855. $CNF = &$this->_oConfig->CNF;
  856. $sMsg = $this->checkAllowedView($aDataEntry);
  857. if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
  858. return $sMsg;
  859. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $CNF['OBJECT_CONNECTION_SUBSCRIBERS'], false, false);
  860. }
  861. public function checkAllowedUnsubscribe(&$aDataEntry, $isPerformAction = false)
  862. {
  863. $CNF = &$this->_oConfig->CNF;
  864. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $CNF['OBJECT_CONNECTION_SUBSCRIBERS'], false, true);
  865. }
  866. public function checkAllowedStickAnyEntry($aDataEntry, $isPerformAction = false)
  867. {
  868. $CNF = &$this->_oConfig->CNF;
  869. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 0)
  870. return false;
  871. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  872. }
  873. public function checkAllowedUnstickAnyEntry($aDataEntry, $isPerformAction = false)
  874. {
  875. $CNF = $this->_oConfig->CNF;
  876. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 1)
  877. return false;
  878. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  879. }
  880. public function checkAllowedResolveAnyEntry($aDataEntry, $isPerformAction = false)
  881. {
  882. $CNF = &$this->_oConfig->CNF;
  883. if((int)$aDataEntry[$CNF['FIELD_RESOLVABLE']] != 1 || (int)$aDataEntry[$CNF['FIELD_RESOLVE']] != 0)
  884. return false;
  885. if($aDataEntry[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  886. return true;
  887. return $this->_checkAllowedAction('resolve any entry', $aDataEntry, $isPerformAction);
  888. }
  889. public function checkAllowedUnresolveAnyEntry($aDataEntry, $isPerformAction = false)
  890. {
  891. $CNF = $this->_oConfig->CNF;
  892. if((int)$aDataEntry[$CNF['FIELD_RESOLVABLE']] != 1 || (int)$aDataEntry[$CNF['FIELD_RESOLVE']] != 1)
  893. return false;
  894. if($aDataEntry[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  895. return true;
  896. return $this->_checkAllowedAction('resolve any entry', $aDataEntry, $isPerformAction);
  897. }
  898. public function checkAllowedLockAnyEntry($aDataEntry, $isPerformAction = false)
  899. {
  900. $CNF = $this->_oConfig->CNF;
  901. if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 0)
  902. return false;
  903. return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
  904. }
  905. public function checkAllowedUnlockAnyEntry($aDataEntry, $isPerformAction = false)
  906. {
  907. $CNF = $this->_oConfig->CNF;
  908. if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 1)
  909. return false;
  910. return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
  911. }
  912. public function checkAllowedHideAnyEntry($aDataEntry, $isPerformAction = false)
  913. {
  914. $CNF = $this->_oConfig->CNF;
  915. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] == 'hidden')
  916. return false;
  917. return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
  918. }
  919. public function checkAllowedUnhideAnyEntry($aDataEntry, $isPerformAction = false)
  920. {
  921. $CNF = &$this->_oConfig->CNF;
  922. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != 'hidden')
  923. return false;
  924. return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
  925. }
  926. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult)
  927. {
  928. $CNF = &$this->_oConfig->CNF;
  929. if(!$this->_iProfileId)
  930. return _t('_sys_txt_access_denied');
  931. $isConnected = BxDolConnection::getObjectInstance($sObjConnection)->isConnected($this->_iProfileId, $aDataEntry[$CNF['FIELD_ID']], $isMutual);
  932. if($isInvertResult)
  933. $isConnected = !$isConnected;
  934. return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
  935. }
  936. /**
  937. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  938. */
  939. protected function _checkAllowedAction($sAction, $aDataEntry, $isPerformAction = false)
  940. {
  941. if($this->_isModerator($isPerformAction))
  942. return CHECK_ACTION_RESULT_ALLOWED;
  943. $aCheck = checkActionModule($this->_iProfileId, $sAction, $this->getName(), $isPerformAction);
  944. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  945. return CHECK_ACTION_RESULT_ALLOWED;
  946. return _t('_sys_txt_access_denied');
  947. }
  948. protected function _serviceBrowseTable($aParams, $isDisplayHeader = true)
  949. {
  950. $sGrid = $this->_oConfig->CNF['OBJECT_GRID'];
  951. if(!empty($aParams['grid'])) {
  952. $sGrid = $aParams['grid'];
  953. unset($aParams['grid']);
  954. }
  955. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  956. if(!$oGrid)
  957. return false;
  958. $oGrid->setBrowseParams($aParams);
  959. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  960. $this->_oTemplate->addCss(array('grid_tools.css'));
  961. return $oGrid->getCode($isDisplayHeader);
  962. }
  963. protected function _getSearchAuthorDescriptor($aAutor)
  964. {
  965. return array('grp' => true, 'opr' => 'OR', 'cnds' => array(
  966. array('fld' => 'author', 'val' => $aAutor, 'opr' => 'IN'),
  967. array('fld' => 'author_comment', 'val' => $aAutor, 'opr' => 'IN'),
  968. ));
  969. }
  970. protected function _getSearchKeywordDescriptor($sKeyword)
  971. {
  972. return array('grp' => true, 'opr' => 'OR', 'cnds' => array(
  973. array('fld' => 'title', 'val' => $sKeyword, 'opr' => 'LIKE'),
  974. array('fld' => 'text', 'val' => $sKeyword, 'opr' => 'LIKE'),
  975. array('fld' => 'text_comments', 'val' => $sKeyword, 'opr' => 'LIKE')
  976. ));
  977. }
  978. }
  979. /** @} */