Advertisement
Guest User

Untitled

a guest
Jan 11th, 2015
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. if (!defined('SMF'))
  2.     die('No direct access...');
  3.  
  4. // We need to build a menu, so grab categories and types
  5. function getCategoriesTypes($workIndexOptions)
  6. {
  7.     global $smcFunc, $scripturl, $user_info, $modSettings, $txt;
  8.     global $settings, $options, $context, $sourcedir;
  9.  
  10.         $result_work_cats_and_types = $smcFunc['db_query']('workindex_fetch_cats_and_types' , '
  11.         SELECT
  12.             c.id_cat,
  13.             c.cat_order,
  14.             c.cat_name,
  15.             c.cat_desc,
  16.             t.id_type,
  17.             t.id_cat AS parent_cat,
  18.             t.id_parent,
  19.             t.child_level,
  20.             t.type_order,
  21.             t.type_name,
  22.             t.type_desc,
  23.             t.num_works,
  24.             t.num_comments,
  25.             t.unapproved_comments
  26.         FROM
  27.             {db_prefix}works_categories AS c,
  28.             {db_prefix}works_types AS t
  29.         WHERE
  30.             c.id_cat = t.id_cat
  31.         ORDER BY
  32.             c.cat_order, t.id_parent
  33.     ');
  34.  
  35.     // Start with an empty array.
  36.     $work_categories = array();
  37.    
  38.     // Build the array of cats and types
  39.     while ($row = $smcFunc['db_fetch_assoc']($result_work_cats_and_types))
  40.     {
  41.         // Make sure we haven't seen the cat yet then grab it
  42.         if (!isset($work_categories[$row['id_cat']]))
  43.         {
  44.             $work_categories[$row['id_cat']] = array(
  45.                 'id_cat' => $row['id_cat'],
  46.                 'order' => $row['cat_order'],
  47.                 'name' => $row['cat_name'],
  48.                 'description' => $row['cat_desc'],
  49.                 'href' => $scripturl . '#c' . $row['id_cat'],
  50.                 'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cat_name'] . '</a>',
  51.                 'types' => array() ,
  52.             );
  53.         }
  54.  
  55.         // Make sure to grab the types
  56.         if (($work_categories[$row['child_level']]) == 0)
  57.         {
  58.             $work_categories[$row['id_cat']]['types'][$row['id_type']] = array(
  59.                 'id_type' => $row['id_type'],
  60.                 'order' => $row['type_order'],
  61.                 'parent' => $row['id_parent'],
  62.                 'child_level' => $row['child_level'],
  63.                 'name' => $row['type_name'],
  64.                 'description' => $row['type_desc'],
  65.                 'works' => $row['num_works'],
  66.                 'comments' => $row['num_comments'],
  67.                 'href' => $scripturl . '?type=' . $row['id_type'] . '.0',
  68.                 'link' => '<a href="' . $scripturl . '?type=' . $row['id_type'] . '.0">' . $row['type_name'] . '</a>',
  69.                 'types' => array() ,
  70.             );
  71.         }
  72.        
  73.         // Grab the syubtypes
  74.         if (($work_categories[$row['child_level']]) > 0)
  75.         {
  76.             $work_categories[$row['id_cat']]['types'][$row['id_parent']]['types'][$row['id_type']] = array(
  77.                 'id_type' => $row['id_type'],
  78.                 'order' => $row['type_order'],
  79.                 'parent' => $row['id_parent'],
  80.                 'child_level' => $row['child_level'],
  81.                 'name' => $row['type_name'],
  82.                 'description' => $row['type_desc'],
  83.                 'works' => $row['num_works'],
  84.                 'comments' => $row['num_comments'],
  85.                 'href' => $scripturl . '?type=' . $row['id_type'] . '.0',
  86.                 'link' => '<a href="' . $scripturl . '?type=' . $row['id_type'] . '.0">' . $row['type_name'] . '</a>',
  87.             );
  88.         }
  89.     }
  90.    
  91.     // We don't need this query anymore we have the data
  92.     $smcFunc['db_free_result']($result_work_cats_and_types);
  93.    
  94.     // Let's return something....
  95.     return $work_categories;
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement