acp_modules::get_module_branch PHP Method

get_module_branch() public method

Get module branch
public get_module_branch ( $module_id, $type = 'all', $order = 'descending', $include_module = true )
    function get_module_branch($module_id, $type = 'all', $order = 'descending', $include_module = true)
    {
        global $db;
        switch ($type) {
            case 'parents':
                $condition = 'm1.left_id BETWEEN m2.left_id AND m2.right_id';
                break;
            case 'children':
                $condition = 'm2.left_id BETWEEN m1.left_id AND m1.right_id';
                break;
            default:
                $condition = 'm2.left_id BETWEEN m1.left_id AND m1.right_id OR m1.left_id BETWEEN m2.left_id AND m2.right_id';
                break;
        }
        $rows = array();
        $sql = 'SELECT m2.*
			FROM ' . MODULES_TABLE . ' m1
			LEFT JOIN ' . MODULES_TABLE . " m2 ON ({$condition})\n\t\t\tWHERE m1.module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND m2.module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND m1.module_id = {$module_id}\n\t\t\tORDER BY m2.left_id " . ($order == 'descending' ? 'ASC' : 'DESC');
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (!$include_module && $row['module_id'] == $module_id) {
                continue;
            }
            $rows[] = $row;
        }
        $db->sql_freeresult($result);
        return $rows;
    }

Usage Example

 /**
  * remove_modules
  */
 function remove_modules($mode, $sub)
 {
     global $db, $user, $phpbb_root_path, $phpEx;
     if (!class_exists('acp_modules')) {
         require $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx;
     }
     $_module = new acp_modules();
     // Set the module class
     $module_classes = array_keys($this->module_categories);
     $_module->u_action = "phpbb_seo_install.{$phpEx}";
     $cat_module_data = array();
     $module_data = array();
     $delete_module_data = array();
     foreach ($module_classes as $module_class) {
         $_module->module_class = $module_class;
         foreach ($this->module_categories[$module_class] as $cat_name => $subs) {
             // If the cat is already uninstalled break for now
             if ($this->get_module_id($cat_name) < 1) {
                 $url_mod = !empty($this->sub) ? '?mode=' . $this->mode : '';
                 $this->p_master->error(sprintf($user->lang['SEO_ERROR_UNINSTALLED'], $user->lang[$cat_name]) . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->p_master->module_url . $url_mod . '">', '</a>'), '', '', false, $user->lang['SEO_ERROR_INFO']);
             }
             $cat_module_data[$cat_name] = array('module_id' => $this->check_module_id($cat_name), 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => '');
             if (is_array($subs)) {
                 foreach ($subs as $sub_cat) {
                     $sub_cat_module_data[$sub_cat] = array('module_id' => $this->check_module_id($sub_cat), 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $cat_module_data[$cat_name]['module_id'], 'module_class' => $module_class, 'module_langname' => $sub_cat, 'module_mode' => '', 'module_auth' => '');
                     $branch = $_module->get_module_branch($sub_cat_module_data[$sub_cat]['module_id'], 'children', 'descending', false);
                     if (sizeof($branch)) {
                         foreach ($branch as $module) {
                             $error = $_module->delete_module($module['module_id']);
                             if (!sizeof($error)) {
                                 $_module->remove_cache_file();
                                 $delete_module_data[$module['module_id']] = $module['module_langname'] . ' - id : ' . $module['module_id'];
                             } else {
                                 $this->errors[] = implode(' ', $error);
                             }
                         }
                         // End modules
                     }
                     if (!sizeof($this->errors)) {
                         $error = $_module->delete_module($sub_cat_module_data[$sub_cat]['module_id']);
                         if (!sizeof($error)) {
                             $_module->remove_cache_file();
                             $delete_module_data[$sub_cat_module_data[$sub_cat]['module_id']] = $sub_cat_module_data[$sub_cat]['module_langname'] . ' - id : ' . $sub_cat_module_data[$sub_cat]['module_id'];
                         } else {
                             $this->errors[] = implode(' ', $error);
                         }
                     }
                 }
             }
             // End sub categories
             if (!sizeof($this->errors)) {
                 $branch = $_module->get_module_branch($cat_module_data[$cat_name]['module_id'], 'children', 'descending', false);
                 if (empty($branch)) {
                     $error = $_module->delete_module($cat_module_data[$cat_name]['module_id']);
                 }
                 if (!sizeof($error)) {
                     $_module->remove_cache_file();
                     $delete_module_data[$cat_module_data[$cat_name]['module_id']] = $cat_module_data[$cat_name]['module_langname'] . ' - id : ' . $cat_module_data[$cat_name]['module_id'];
                 } else {
                     $this->errors[] = implode(' ', $error);
                 }
             }
         }
         // End categories
     }
     // End classes
     return;
 }
All Usage Examples Of acp_modules::get_module_branch