Jump to content

Recommended Posts

Posted

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:

 

    //Construct an unordered list from $navlinks
   //Accessibility: heading hidden from visual browsers by default.
   $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." </pre><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 .= '';
       if (!$first) {
           $navigation .= get_separator();
       }
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "framename'\" href=\"{$navlink['link']}\">";
       }
       $navigation .= "{$navlink['name']}";
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "";
       }

       $navigation .= "";
       $first = false;
   }
   $navigation .= "</ul>";<br><br>   return(array('newnav' => true, 'navlinks' => $navigation));<br

 

This builds the breadcrumb nav in Moodle,

 

Basically translates to:

 

</pre><ul>
Home
Course
Activity
</u

 

What I want to create is:

 

</pre><ul id="nav"> 
 Home 
   Course 
   Activity 
   Web Page 
</ul

 

Allowing me to create a drop down menu in plain CSS.

Posted

I've managed the first step (The easiest)

 

 $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." </pre><ul>\n"

 

 

changed to:

 

 $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." </pre><ul class="[b]nav[/b]">\n";

Posted

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 :D

Posted

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'

Posted

Well, I know nothing about Moodle, but wouldn't this work?

//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')." </pre><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 .= '';
       if (!$first) {
           $navigation .= get_separator();
       }
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "framename'\" href=\"{$navlink['link']}\">";
       }
       $navigation .= "{$navlink['name']}";
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "";
       }

       $navigation .= "";
       $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 = "HomeCourseActivityWeb Page";

   return(array('newnav' => true, 'navlinks' => $navigation));

Posted (edited)

TO sort the names for your css;

 

Replace

 

$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." </pre><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 .= '';
       if (!$first) {
           $navigation .= get_separator();
       }
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "framename'\" href=\"{$navlink['link']}\">";
       }
       $navigation .= "{$navlink['name']}";
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "";
       }

       $navigation .= "";
       $first = false;
   }
   */

 

with

 

$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." </pre><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 .= '';
           $navigation .= get_separator();
       }
       else{
           $navigation .= '';
       }
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "framename'\" href=\"{$navlink['link']}\">";
       }
       $navigation .= "{$navlink['name']}";
       if ((!empty($navlink['link'])) && !$last) {
           $navigation .= "";
       }

       $navigation .= "";
       $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.

Edited by kesomir

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • 46 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...