Advertisement
Guest User

list_moodle_categories

a guest
Jul 12th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. <?php
  2. public
  3.  
  4. function list_categories()
  5. {
  6.     global $CFG, $OUTPUT, $DB;
  7.     $header = '<div>
  8. <h2>category</h2><div class="courses frontpage-course-list-all"><div class="row-fluid">';
  9.     $footer = '</div>
  10.                                 </div>
  11.                         </div>';
  12.     $co_cnt = 1;
  13.     $content = '';
  14.     $noimg_url = $OUTPUT - &gt;
  15.     pix_url('no-image', 'theme');
  16.     $categories = $DB - &gt;
  17.     get_records('course_categories', array(
  18.         'visible' = & gt;
  19.         '1',
  20.         'depth' = & gt;
  21.         '1'
  22.     ));
  23.     function URLIsValid($URL)
  24.     {
  25.         $exists = true;
  26.         $file_headers = @get_headers($URL);
  27.         $InvalidHeaders = array(
  28.             '404',
  29.             '403',
  30.             '500'
  31.         );
  32.         foreach($InvalidHeaders as $HeaderVal)
  33.         {
  34.             if (strstr($file_headers[0], $HeaderVal))
  35.             {
  36.                 $exists = false;
  37.                 break;
  38.             }
  39.         }
  40.  
  41.         return $exists;
  42.     }
  43.  
  44.     foreach($categories as $categorie)
  45.     {
  46.         $categorie_url = new moodle_url('/course/category.php', array(
  47.             'id' = & gt;
  48.             $categorie - &gt;
  49.             id
  50.         ));
  51.         $img_url = $OUTPUT - &gt;
  52.         pix_url('categories/' . $categorie - &gt;
  53.         id, 'theme');
  54.         if (!URLIsValid($img_url))
  55.         {
  56.             $img_url = $noimg_url;
  57.         }
  58.  
  59.         $content.= '<div class="span3"><div class="fp-coursebox"><div class="fp-coursethumb"><a href="' . $categorie_url . '"><img src="' . $img_url . '" width="243" height="165" alt="' . $categorie - &gt;name . '" /></a></div>
  60. <div class="fp-courseinfo"><h5><a href="' . $categorie_url . '">' . $categorie - &gt;name . '</a></h5><div class="readmore"><a href="' . $categorie_url . '">En savoir plus<i class="fa fa-angle-double-right"></i></a></div></div></div></div>';
  61.        
  62.  
  63.  
  64. if (($co_cnt % 4) == "0")
  65.         {
  66.             $content.= '<div class="clearfix hidexs"></div>';
  67.         }
  68.  
  69.         $co_cnt++;
  70.     }
  71.  
  72.     $course_html = $header . $content . $footer;
  73.     $frontpage = isset($CFG - &gt;
  74.     frontpage) ? $CFG - &gt;
  75.     frontpage : '';
  76.     $frontpageloggedin = isset($CFG - &gt;
  77.     frontpageloggedin) ? $CFG - &gt;
  78.     frontpageloggedin : '';
  79.     $f1_pos = strpos($frontpage, '6');
  80.     $f2_pos = strpos($frontpageloggedin, '6');
  81.     $btn_html = '';
  82.     if ($co_cnt & lt; = 1 & amp; & amp;
  83.     !$this - &gt;
  84.     page - &gt;
  85.     user_is_editing() & amp; & amp;
  86.     has_capability('moodle/course:create', context_system::instance()))
  87.     {
  88.         $btn_html = $this - &gt;
  89.         add_new_course_button();
  90.     }
  91.  
  92.     if (!isloggedin() or isguestuser())
  93.     {
  94.         if ($f1_pos === false)
  95.         {
  96.             if ($co_cnt & gt;
  97.             1)
  98.             {
  99.                 echo $course_html;
  100.             }
  101.         }
  102.     }
  103.     else
  104.     {
  105.         if ($f2_pos === false)
  106.         {
  107.             echo $course_html . "<br />" . $btn_html;
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement