Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. <?php
  2. /**
  3. * Used to render the navigation items in the simple_nav block
  4. *
  5. */
  6. class block_simple_nav_renderer extends plugin_renderer_base {
  7.  
  8. public function simple_nav_tree($items) {
  9. $depth = 0;
  10. $type = 0;
  11. ?><script>
  12. window.onload = function(e) {
  13. $(document).ready(function() {
  14. $('div.block_simple_nav li.type_category .tree_item').click(function() {
  15. console.log(this);
  16. if ($(this).parent().hasClass("collapsed")) {
  17. $(this).parent().removeClass("collapsed")
  18. } else {
  19. $(this).parent().addClass("collapsed")
  20. }
  21. })
  22. })
  23. }
  24.  
  25. </script><?php
  26. foreach ($items as $item) {
  27. //print_object($item);
  28. //category and courses open <ul> tags. if they are empty, we have to make sure they're closed again.
  29.  
  30.  
  31. // We have to check if the category before was empty
  32. if ($depth>=$item['mydepth'] && $type == 'category' && $item['mytype'] == 'category') {
  33. $content[] = '</li></ul>';
  34. }
  35.  
  36.  
  37. //this is to know if we have to close the tags for the branch. We calculate the difference between the old and new branch and add the close tags accordingly
  38. if ($depth>$item['mydepth']) {
  39. // this is necessary to take care of the "startingpoint"-case, which suppresses the output of a category sometimes
  40. if (substr($item['myclass'], -14, 14) == ' startingpoint') {
  41. $mydifference = $depth-$item['mydepth']-1;
  42. }
  43. else {
  44. $mydifference = $depth-$item['mydepth'];
  45. }
  46. $content[] = str_repeat('</li></ul>',$mydifference);
  47. }
  48.  
  49.  
  50. // Every time we the last item was a module and the new isn't, we can close <ul> as well as <li>
  51. elseif ($item['mytype'] <> 'module' && $type == 'module') {
  52. $content[] = '</li></ul>';
  53. }
  54.  
  55.  
  56. // if depth stays the same, we can just close the <li> tag
  57. elseif ($depth==$item['mydepth']) {
  58. $content[] = '</li>';
  59. }
  60.  
  61. //if the old item was course and the new is module, we have to open ul
  62. if ($item['mytype'] == 'module' && ($type == 'course' || $type == 'invisiblecourse')) {
  63. $content[] = '<ul>';
  64. }
  65.  
  66. //print out html code for the item
  67. $content[] = $this->sn_print_item($item['myclass'], $item['myid'], $item['myname'], $item['mydepth'], $item['mytype'], $item['mypath'], $item['myicon'], $item['myvisibility']);
  68. // keep the information for the next loop
  69. $depth = $item['mydepth'];
  70. $myid = $item['myid'];
  71. $type = $item['mytype'];
  72. }
  73. $content[] = '</li></ul>';
  74. $content = implode($content);
  75. return $content;
  76. }
  77.  
  78. protected function sn_print_item($myclass, $myid, $myname, $mydepth, $mytype, $mypath, $myicon, $myvisibility) {
  79. global $CFG, $OUTPUT;
  80.  
  81. $icon = '';
  82. $baseurl =$CFG->wwwroot;
  83. $mystartclass = "";
  84.  
  85. if (! empty($this->config->space)) {
  86. $space_symbol = $this->config->space;
  87. }
  88.  
  89. //if we don't want to show the first node, we use the class "startingpoint" as an indicator to totally skip it
  90. if (substr($myclass, -14, 14) == ' startingpoint') {
  91. return null;
  92. }
  93.  
  94. // we only want the active branch to be open, all the other ones whould be collapsed
  95. $mycollapsed ='';
  96. // myclass only has a value when it's active
  97. if (!$myclass) {
  98. $mycollapsed =' collapsed';
  99. }
  100. else {
  101. $mycollapsed ='';
  102. }
  103.  
  104. //sometimes, we don't show categories by simple setting their name to "". If this is the case, we want them not to be collapsed.
  105. //Here is a simple way to do so:
  106. //If the Name is empty, we also set the class, which controls the collapsed/uncollapsed status, to "".
  107. if (empty($myname)) {
  108. $mycollapsed = "";
  109. }
  110.  
  111.  
  112.  
  113. // is it a category
  114. if ($mytype == 'category') {
  115. $myurl =$CFG->wwwroot.'/course/index.php?categoryid='.$myid;
  116. //$myname = "";
  117. $myclass_ul_open = '';
  118. $myclass_li = 'type_category depth_'.$mydepth.''.$mycollapsed.' contains_branch'.$mystartclass;
  119. $myclass_p = 'tree_item branch'.$myclass;
  120. $myopentag = '<ul>';
  121. $myclass_a = '';
  122. if ($myvisibility == 0) {
  123. $myclass_a = 'class="dimmed_text"';
  124. }
  125. else {
  126. $myclass_a = '';
  127. }
  128.  
  129. }
  130. // is it a course
  131. elseif ($mytype == 'course') {
  132. // We don't want course-nodes to be open, even when they are active so:
  133. //$mycollapsed =' collapsed';
  134.  
  135.  
  136. $myurl =$CFG->wwwroot.'/course/view.php?id='.$myid;
  137.  
  138. $myclass_ul_open = '';
  139. $myclass_li = 'type_course depth_'.$mydepth.''.$mycollapsed.' contains_branch';;
  140. $myclass_p = 'tree_item branch hasicon'.$myclass;
  141. $myopentag = '';
  142.  
  143. if ($myvisibility == 0) {
  144. $myclass_a = 'class="dimmed_text"';
  145. }
  146. else {
  147. $myclass_a = '';
  148. }
  149.  
  150.  
  151. }
  152. // or the home node
  153. elseif ($mytype == 'home') {
  154. $myurl =$CFG->wwwroot;
  155.  
  156. $myclass_ul_open = '<ul class="block_tree list">';
  157. $myclass_li = 'type_unknown depth_1 contains_branch';
  158. $myclass_p = 'tree_item branch '.$myclass.' navigation_node';
  159. $myopentag = '<ul>';
  160. $myclass_a = '';
  161.  
  162. }
  163. // or invisible home node
  164. elseif ($mytype == 'nohome') {
  165. $myurl =$CFG->wwwroot;
  166. $myclass_ul_open = '<ul class="block_tree list">';
  167. $myclass_li = 'type_unknown depth_1 contains_branch simple_invisible';
  168. $myclass_p = 'tree_item branch '.$myclass.' navigation_node';
  169. $myopentag = '<ul>';
  170. $myclass_a = '';
  171.  
  172. }
  173. // or a module
  174. elseif ($mytype == 'module') {
  175. $myurl =$CFG->wwwroot.'/mod/'.$myicon.'/view.php?id='.$myid;
  176. $myclass_ul_open = '';
  177. $myclass_li = 'contains_branch item_with_icon';
  178. $myclass_p = 'tree_item leaf hasicon'.$myclass;
  179. $myopentag = '';
  180. $myclass_a = '';
  181.  
  182. if ($myvisibility == 0) {
  183. $myclass_a = 'class="dimmed_text"';
  184. }
  185. else {
  186. $myclass_a = '';
  187. }
  188. // fork for Angela Kohl
  189. $displayoption = get_config('block_simple_nav', 'displayoptions');
  190. if($displayoption === '1'){
  191. $icon = '<img alt="'.$myicon.'" class="smallicon navicon" title="'.$myicon.'" src="'.$baseurl.'/theme/image.php?theme=standard&image=icon&rev=295&component='.$myicon.'">';
  192. } else if ($displayoption === '2'){
  193. $icon = '<img alt="'.$myicon.'" class="smallicon navicon" title="'.$myicon.'" src="'.$baseurl.'/theme/image.php?theme='.$CFG->theme.'&image=t/collapsed&rev=295&component=core">';
  194. } else {
  195. $icon = '<img alt="'.$myicon.'" class="smallicon navicon navigationitem" title="'.$myicon.'" src="'.$baseurl.'/theme/image.php?theme='.$CFG->theme.'&image=i/navigationitem&rev=295&component=core">';
  196. }
  197.  
  198. }
  199.  
  200. $myitem = $myclass_ul_open.'<li class="'.$myclass_li.'"><p class="'.$myclass_p.'"><a '.$myclass_a.' href="'.$myurl.'">'.$icon.''.$myname.'</a></p>'.$myopentag;
  201. return $myitem;
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement