+ Post New Thread
Results 1 to 7 of 7
Coding Thread, Moodle PHP in Coding and Web Development; Wonder if someone could help me out? I know very little about PHP, however I have managed to use GREP ...
  1. #1

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29

    Moodle PHP

    Wonder if someone could help me out? I know very little about PHP, however I have managed to use GREP to locate the specific bit of code which i need to change:

    Bit of PHP code out of Moodle here:

    Code:
        //Construct an unordered list from $navlinks
        //Accessibility: heading hidden from visual browsers by default.
        $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n";
        $lastindex = count($navlinks) - 1;
        $i = -1; // Used to count the times, so we know when we get to the last item.
        $first = true;
        foreach ($navlinks as $navlink) {
            $i++;
            $last = ($i == $lastindex);
            if (!is_array($navlink)) {
                continue;
            }
            if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) {
                continue;
            }
            $navigation .= '<li class="first">';
            if (!$first) {
                $navigation .= get_separator();
            }
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">";
            }
            $navigation .= "{$navlink['name']}";
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "</a>";
            }
    
            $navigation .= "</li>";
            $first = false;
        }
        $navigation .= "</ul>";
    
        return(array('newnav' => true, 'navlinks' => $navigation));
    }
    This builds the breadcrumb nav in Moodle,

    Basically translates to:

    HTML Code:
    <ul>
    <li class="first">Home</li>
    <li class="first">Course</li>
    <li class="first">Activity</li>
    </ul>
    What I want to create is:

    HTML Code:
    <ul id="nav"> 
      <li class="navtop">Home</li> 
        <li class="navitem"><a href="http://www.google.com">Course</a></li> 
        <li class="navitem"><a href="http://www.msn.com">Activity</a></li> 
        <li class="navitem"><a href="http://edugeek.net">Web Page</a></li> 
    </ul> 
    Allowing me to create a drop down menu in plain CSS.

  2. #2

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    I've managed the first step (The easiest)

    Code:
     $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n";

    changed to:

    Code:
     $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul class=nav>\n";

  3. #3

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    So you want to create a dropdown menu in place of the breadcrumb? The menu won't change much so does it need to be written in PHP?

    Can you not just create a seperate file (i.e. menu.php), write the drop down as you need it and then include it in place of where the breadcrumb code is?

    I'm not up with PHP too much either so it's just an idea and probably doesn't make sense

  4. #4

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    It makes sense, but the breadcrumb links are generated dynamically so i cant pre-create the menu links.

    Moodle generates them on the fly so i need to get my classes in 'on the fly'

  5. #5

    Join Date
    Jan 2008
    Posts
    90
    Thank Post
    6
    Thanked 18 Times in 14 Posts
    Rep Power
    17
    Well, I know nothing about Moodle, but wouldn't this work?
    Code:
    //Construct an unordered list from $navlinks
        //Accessibility: heading hidden from visual browsers by default.
        
        //Comment out virtually all of this using the slash and asterisk...
        
        /*
        $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n";
        $lastindex = count($navlinks) - 1;
        $i = -1; // Used to count the times, so we know when we get to the last item.
        $first = true;
        foreach ($navlinks as $navlink) {
            $i++;
            $last = ($i == $lastindex);
            if (!is_array($navlink)) {
                continue;
            }
            if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) {
                continue;
            }
            $navigation .= '<li class="first">';
            if (!$first) {
                $navigation .= get_separator();
            }
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">";
            }
            $navigation .= "{$navlink['name']}";
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "</a>";
            }
    
            $navigation .= "</li>";
            $first = false;
        }
        */
        
        //The routine above just builds a string called $navigation, which is then fed into Moodle, so why not just
        //include the HTML you want directly, as in the line below? (Note that the dot before the equals sign has been deleted).
        $navigation = "<ul id="nav"><li class="navtop">Home</li><li class="navitem"><a href="http://www.google.com">Course</a></li><li class="navitem"><a href="http://www.msn.com">Activity</a></li><li class="navitem"><a href="http://edugeek.net">Web Page</a></li></ul>";
    
        return(array('newnav' => true, 'navlinks' => $navigation));
    }

  6. #6

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    The links i provided were example, the links are dynamic they could be anything depending on which page you land or navigate to.

  7. #7
    kesomir's Avatar
    Join Date
    Mar 2008
    Location
    London
    Posts
    288
    Thank Post
    15
    Thanked 28 Times in 23 Posts
    Rep Power
    17
    TO sort the names for your css;

    Replace

    Code:
    $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n";
        $lastindex = count($navlinks) - 1;
        $i = -1; // Used to count the times, so we know when we get to the last item.
        $first = true;
        foreach ($navlinks as $navlink) {
            $i++;
            $last = ($i == $lastindex);
            if (!is_array($navlink)) {
                continue;
            }
            if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) {
                continue;
            }
            $navigation .= '<li class="first">';
            if (!$first) {
                $navigation .= get_separator();
            }
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">";
            }
            $navigation .= "{$navlink['name']}";
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "</a>";
            }
    
            $navigation .= "</li>";
            $first = false;
        }
        */
    with

    Code:
    $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul id=\"nav\" >\n";
        $lastindex = count($navlinks) - 1;
        $i = -1; // Used to count the times, so we know when we get to the last item.
        $first = true;
        foreach ($navlinks as $navlink) {
    
            $i++;
            $last = ($i == $lastindex);
            if (!is_array($navlink)) {
                continue;
            }
            if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) {
                continue;
            }
            
            if (!$first) {
                $navigation .= '<li class="navitem">';
                $navigation .= get_separator();
            }
            else{
                $navigation .= '<li class="navtop">';
            }
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">";
            }
            $navigation .= "{$navlink['name']}";
            if ((!empty($navlink['link'])) && !$last) {
                $navigation .= "</a>";
            }
    
            $navigation .= "</li>";
            $first = false;
        }
        */
    As for the links - you would need an array of the urls and the navlinks they apply to and then use a switch to apply them by modifying the url section of that loop. I can't do it for you without knowing what you want though.
    Last edited by kesomir; 12th January 2009 at 05:14 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. Moodle - Word template to create Moodle XML Quiz
    By lasercat in forum Virtual Learning Platforms
    Replies: 4
    Last Post: 25th October 2010, 12:19 PM
  2. PHP ID
    By Jackd in forum Coding
    Replies: 4
    Last Post: 30th November 2008, 01:08 PM
  3. FreeBSD, PHP, Moodle + LDAP
    By Marci in forum Web Development
    Replies: 4
    Last Post: 25th June 2008, 08:20 AM
  4. PHP Help!
    By Cravon in forum Coding
    Replies: 2
    Last Post: 20th November 2007, 05:05 PM
  5. Office 2007 file format support in Apache, PHP and Moodle
    By Geoff in forum Virtual Learning Platforms
    Replies: 2
    Last Post: 8th July 2007, 12:12 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •