PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/subs/MessageIndex.subs.php

https://github.com/Arantor/Elkarte
PHP | 93 lines | 59 code | 13 blank | 21 comment | 12 complexity | 3ec24ff9bc9a5ec5c21978926410dd94 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. */
  16. if (!defined('ELKARTE'))
  17. die('No access...');
  18. /**
  19. * Generates the query to determine the list of available boards for a user
  20. * Executes the query and returns the list
  21. *
  22. * @param type $boardListOptions
  23. * @return type
  24. */
  25. function getBoardList($boardListOptions = array())
  26. {
  27. global $smcFunc, $user_info;
  28. if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards']))
  29. trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR);
  30. $where = array();
  31. $where_parameters = array();
  32. if (isset($boardListOptions['excluded_boards']))
  33. {
  34. $where[] = 'b.id_board NOT IN ({array_int:excluded_boards})';
  35. $where_parameters['excluded_boards'] = $boardListOptions['excluded_boards'];
  36. }
  37. if (isset($boardListOptions['included_boards']))
  38. {
  39. $where[] = 'b.id_board IN ({array_int:included_boards})';
  40. $where_parameters['included_boards'] = $boardListOptions['included_boards'];
  41. }
  42. if (!empty($boardListOptions['ignore_boards']))
  43. $where[] = '{query_wanna_see_board}';
  44. elseif (!empty($boardListOptions['use_permissions']))
  45. $where[] = '{query_see_board}';
  46. if (!empty($boardListOptions['not_redirection']))
  47. {
  48. $where[] = 'b.redirect = {string:blank_redirect}';
  49. $where_parameters['blank_redirect'] = '';
  50. }
  51. $request = $smcFunc['db_query']('messageindex_fetch_boards', '
  52. SELECT c.name AS cat_name, c.id_cat, b.id_board, b.name AS board_name, b.child_level
  53. FROM {db_prefix}boards AS b
  54. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' . (empty($where) ? '' : '
  55. WHERE ' . implode('
  56. AND ', $where)),
  57. $where_parameters
  58. );
  59. $return_value = array();
  60. if ($smcFunc['db_num_rows']($request) !== 0)
  61. {
  62. while ($row = $smcFunc['db_fetch_assoc']($request))
  63. {
  64. if (!isset($return_value[$row['id_cat']]))
  65. $return_value[$row['id_cat']] = array(
  66. 'id' => $row['id_cat'],
  67. 'name' => $row['cat_name'],
  68. 'boards' => array(),
  69. );
  70. $return_value[$row['id_cat']]['boards'][] = array(
  71. 'id' => $row['id_board'],
  72. 'name' => $row['board_name'],
  73. 'child_level' => $row['child_level'],
  74. 'selected' => isset($boardListOptions['selected_board']) && $boardListOptions['selected_board'] == $row['id_board'],
  75. );
  76. }
  77. }
  78. $smcFunc['db_free_result']($request);
  79. return $return_value;
  80. }