1

Is there any example of how to create recursive menu protected by ACL?

Idea is to have printed traversal path to end-document with read access even if user don't have read access to parent node.

Here is HTML code example of how it should looks:

<ul>
    <li><a href="some_url">I have read access here</a>
        <ul>
            <li>I don't have read access here - only print node name (traversal)
                <ul>
                    <li><a href="some_url">I have read access here</a>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Acl have method has_read_permission( $node_id ) - return true/false

I've managed to generate full recursive menu but non acl protected.

PHP is server backend.

DB table structure:

node_id | parent id | node_content

Thx

P.S.

PHP Code I use to generate non acl protected recursive menu (it is adopted to codeigniter framework):

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Menu extends MY_Controller {

    public static $menu = array();

    function index(){

        $permited_objects=$this->session->userdata('permited_objects');
        $session_email=$this->session->userdata('email');

        self::$menu[] = "<ul id=\"treemenu2\" class=\"treeview\">";

        $this -> _display_children(0, 0, $permited_objects);

        self::$menu[] = "</ul>";
        $menu_imploded = implode("", self::$menu);

        $menu_db = str_replace("<ul></ul>", " ", $menu_imploded);

        //write in db or return

        return $menu_db;

    }


    function _display_children($parent, $level) {

        $sql = "SELECT `title`, `doc_uid` 
                FROM `documents` 
                WHERE `parent_uid` = '" . $parent . "' 
                order by `title` 
                ASC";

        try {
            $this -> db -> trans_start();
            $query = $this -> db -> query($sql);
            $this -> db -> trans_complete();
        } catch (Exception $e) {
            $this -> _log_message('error', 'Model global\Generate_main_menu->execute() => ERROR=' . $e);
        }

        if ($level > 0)
            self::$menu[] = "<ul>";


        foreach ($query->result() as $row) {
                    self::$menu[] = '<li>';
                    self::$menu[] = '<a onclick="javascript: dms_display_document(\'' . $this->ec_crypt-> encode($row -> doc_uid) . '\');" href="#" >';
                    self::$menu[] = $row -> title;
                    self::$menu[] = '</a>';

                $this -> _display_children($row -> doc_uid, $level + 1);
            }

            if ($level > 0) {
                self::$menu[]='</ul>';
            }

            self::$menu[]='</li>';
        }
}
Vukasin
  • 561
  • 5
  • 9

1 Answers1

0

You could do it yourself by creating an m-to-n relationship between users table and nodes table and hold the permissions in the pivot table:

users_nodes

  • user_id
  • node_id
  • can_read
Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
  • I'm not sure that understand you well. As I stated I have acl method which return true/false if user have read access to node so what is purpose of doing solution you suggested ? Thx – Vukasin Jul 03 '12 at 10:02