acp_modules::move_module PHP Метод

move_module() публичный Метод

Move module around the tree
public move_module ( $from_module_id, $to_parent_id )
    function move_module($from_module_id, $to_parent_id)
    {
        global $db;
        $moved_modules = $this->get_module_branch($from_module_id, 'children', 'descending');
        $from_data = $moved_modules[0];
        $diff = sizeof($moved_modules) * 2;
        $moved_ids = array();
        for ($i = 0; $i < sizeof($moved_modules); ++$i) {
            $moved_ids[] = $moved_modules[$i]['module_id'];
        }
        // Resync parents
        $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\tSET right_id = right_id - {$diff}\n\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND left_id < " . (int) $from_data['right_id'] . '
				AND right_id > ' . (int) $from_data['right_id'];
        $db->sql_query($sql);
        // Resync righthand side of tree
        $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND left_id > " . (int) $from_data['right_id'];
        $db->sql_query($sql);
        if ($to_parent_id > 0) {
            $to_data = $this->get_module_row($to_parent_id);
            // Resync new parents
            $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\t\tSET right_id = right_id + {$diff}\n\t\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\t\tAND " . (int) $to_data['right_id'] . ' BETWEEN left_id AND right_id
					AND ' . $db->sql_in_set('module_id', $moved_ids, true);
            $db->sql_query($sql);
            // Resync the righthand side of the tree
            $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\t\tSET left_id = left_id + {$diff}, right_id = right_id + {$diff}\n\t\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\t\tAND left_id > " . (int) $to_data['right_id'] . '
					AND ' . $db->sql_in_set('module_id', $moved_ids, true);
            $db->sql_query($sql);
            // Resync moved branch
            $to_data['right_id'] += $diff;
            if ($to_data['right_id'] > $from_data['right_id']) {
                $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
            } else {
                $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
            }
        } else {
            $sql = 'SELECT MAX(right_id) AS right_id
				FROM ' . MODULES_TABLE . "\n\t\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\t\tAND " . $db->sql_in_set('module_id', $moved_ids, true);
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $diff = '+ ' . (int) ($row['right_id'] - $from_data['left_id'] + 1);
        }
        $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\tSET left_id = left_id {$diff}, right_id = right_id {$diff}\n\t\t\tWHERE module_class = '" . $db->sql_escape($this->module_class) . "'\n\t\t\t\tAND " . $db->sql_in_set('module_id', $moved_ids);
        $db->sql_query($sql);
    }

Usage Example

Пример #1
0
    public function move_prune_users_module()
    {
        $sql = 'SELECT module_id
			FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_class = 'acp'\n\t\t\t\tAND module_basename = 'acp_prune'\n\t\t\t\tAND module_mode = 'users'";
        $result = $this->db->sql_query($sql);
        $acp_prune_users_id = (int) $this->db->sql_fetchfield('module_id');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT module_id
			FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_class = 'acp'\n\t\t\t\tAND module_langname = 'ACP_CAT_USERS'";
        $result = $this->db->sql_query($sql);
        $acp_cat_users_id = (int) $this->db->sql_fetchfield('module_id');
        $this->db->sql_freeresult($result);
        if (!class_exists('\\acp_modules')) {
            include $this->src_root_path . 'includes/acp/acp_modules.' . $this->php_ext;
        }
        $module_manager = new \acp_modules();
        $module_manager->module_class = 'acp';
        $module_manager->move_module($acp_prune_users_id, $acp_cat_users_id);
    }
All Usage Examples Of acp_modules::move_module