live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
My fixes to Subs-Boards
« on May 11th, 2012, 09:22 AM »

@@ -649,6 +649,18 @@
       $boardUpdateParameters['language'] = $boardOptions['language'];
    }
 
+   if (isset($boardOptions['board_type']))
+   {
+      $boardUpdates[] = 'board_type = {string:board_type}';
+      $boardUpdateParameters['board_type'] = $boardOptions['board_type'];
+   }
+
+   if (isset($boardOptions['id_owner']))
+   {
+      $boardUpdates[] = 'id_owner = {int:id_owner}';
+      $boardUpdateParameters['id_owner'] = $boardOptions['id_owner'];
+   }
+
    // Do the updates (if any).
    if (!empty($boardUpdates))
       wesql::query('
@@ -1100,12 +1112,12 @@
 
 // Load a lot of useful information regarding the boards and categories.
 // Restrict to their own boards anyone who's not an admin
-function getBoardTree($restrict = false)
+function getBoardTree($restrict = false, $id_owner = null)
 {
-   global $cat_tree, $boards, $boardList, $txt, $settings, $user_info;
+   global $cat_tree, $boards, $boardList, $txt, $settings;
 
-   $restriction = $user_info['is_admin'] || !$restrict ? '' : '
-            AND b.id_owner = ' . (int) $user_info['id'];
+   $restriction = $id_owner && $restrict ? '
+            AND b.id_owner = ' . (int) $id_owner : '';
 
    // Getting all the board and category information you'd ever wanted.
    $request = wesql::query('
@@ -1115,7 +1127,7 @@
          b.redirect_newtab, b.num_posts, b.language, b.num_topics, c.id_cat, c.name AS cat_name, c.cat_order, c.can_collapse
       FROM {db_prefix}categories AS c
          LEFT JOIN {db_prefix}boards AS b ON (b.id_cat = c.id_cat)' . $restriction . '
-      ORDER BY c.cat_order, b.child_level, b.board_order',
+      ORDER BY c.cat_order, b.board_order, b.child_level',
       array()
    );
    $cat_tree = array();
@@ -1170,7 +1182,7 @@
          $prevBoard = $row['id_board'];
          $last_board_order = $row['board_order'];
 
-         if (empty($row['child_level']))
+         if (empty($row['child_level']) || !$boards[$row['id_parent']])
          {
             $cat_tree[$row['id_cat']]['children'][$row['id_board']] = array(
                'node' => &$boards[$row['id_board']],

  • Add to modifyBoard()
  • Change how a board owner is defined: what if a moderator decides to modify a user's board in their behalf? Also, in the future profile boards section, I think an admin should only see the boards with a defined owner. (I should note that this will affect the existing boards management; at least one said area imposes the restriction.
  • Change the sorting order of the query. I had a second-level board appear appear after a first-level board when they were supposed too be flipped. After changing the code, I played with moving some boards around and all appears to work as expected.
  • A second-level board had no parent according to the function because its parent had a different owner. This would trigger an error. The changed code doesn't feel right, but prevents the error.
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.