Proyectos de Subversion Moodle

Rev

Rev 891 | Rev 912 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 891 Rev 901
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace theme_universe\output;
17
namespace theme_universe_child\output;
18
 
18
 
19
use html_writer;
19
use html_writer;
20
use stdClass;
20
use stdClass;
Línea 37... Línea 37...
37
use theme_config;
37
use theme_config;
38
use get_string;
38
use get_string;
39
use core_course_category;
39
use core_course_category;
40
use theme_universe\util\user;
40
use theme_universe\util\user;
41
use theme_universe\util\course;
41
use theme_universe\util\course;
-
 
42
use core_completion\progress;
Línea 42... Línea 43...
42
 
43
 
Línea 43... Línea 44...
43
require_once($CFG->dirroot . '/cesa/statics_blocks.php'); // Incluimos StaticsBlocks
44
require_once($CFG->dirroot . '/cesa/statics_blocks.php'); // Incluimos StaticsBlocks
Línea 844... Línea 845...
844
        }
845
        }
845
        return '';
846
        return '';
846
    }
847
    }
Línea -... Línea 848...
-
 
848
 
847
 
849
 
848
 
850
 
849
    /**
851
    /**
850
     * This is an optional menu that can be added to a layout by a theme. It contains the
852
     * This is an optional menu that can be added to a layout by a theme. It contains the
851
     * menu for the course administration, only on the course main page.
853
     * menu for the course administration, only on the course main page.
Línea 2427... Línea 2429...
2427
            return new moodle_url($url);
2429
            return new moodle_url($url);
2428
        }
2430
        }
Línea 2429... Línea 2431...
2429
 
2431
 
2430
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-messages-white.png';
2432
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-messages-white.png';
-
 
2433
    }
-
 
2434
 
-
 
2435
    private function extractDurationFromVideo($record, $filename)
-
 
2436
    {
-
 
2437
        global $DB;
-
 
2438
 
-
 
2439
        $duration = 0;
-
 
2440
 
-
 
2441
        if (empty($record->duration)) {
-
 
2442
            $fs = get_file_storage();
-
 
2443
            $file = $fs->get_file($record->contextid, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename);
-
 
2444
            if ($file) {
-
 
2445
 
-
 
2446
                $data = $file->get_content();
-
 
2447
 
-
 
2448
                $path_temp = __DIR__ . DIRECTORY_SEPARATOR . 'tmp';
-
 
2449
                if (!file_exists($path_temp)) {
-
 
2450
                    mkdir($path_temp, 0755);
-
 
2451
                }
-
 
2452
 
-
 
2453
                $full_filename = $path_temp . DIRECTORY_SEPARATOR . uniqid() . '_' . $filename;
-
 
2454
                file_put_contents($full_filename, $data);
-
 
2455
 
-
 
2456
                if (file_exists($full_filename)) {
-
 
2457
                    $cmd = "/usr/bin/ffprobe -i $full_filename -show_entries format=duration -v quiet -of csv=\"p=0\" ";
-
 
2458
                    $response = trim(shell_exec($cmd));
-
 
2459
                    @unlink($full_filename);
-
 
2460
 
-
 
2461
 
-
 
2462
                    $duration = $response;
-
 
2463
 
-
 
2464
 
-
 
2465
                    if ($response) {
-
 
2466
                        $response = floatval($response);
-
 
2467
 
-
 
2468
                        if ($response > 60) {
-
 
2469
 
-
 
2470
                            //echo 'response = ' . $response . '<br>';
-
 
2471
 
-
 
2472
                            $minutes = intval($response / 60);
-
 
2473
                            //echo 'minutes = ' . $minutes . '<br>';
-
 
2474
 
-
 
2475
                            $seconds = round(($response - ($minutes * 60)));
-
 
2476
                            //echo 'seconds = ' . $seconds . '<br>';
-
 
2477
 
-
 
2478
 
-
 
2479
                            if ($minutes < 10) {
-
 
2480
                                $duration = '0' . $minutes;
-
 
2481
                            } else {
-
 
2482
                                $duration = $minutes;
-
 
2483
                            }
-
 
2484
 
-
 
2485
                            if ($seconds) {
-
 
2486
                                if ($seconds < 10) {
-
 
2487
                                    $duration = $duration . ':0' . $seconds;
-
 
2488
                                } else {
-
 
2489
                                    $duration = $duration . ':' . $seconds;
-
 
2490
                                }
-
 
2491
                            } else {
-
 
2492
                                $duration = $duration . ':00';
-
 
2493
                            }
-
 
2494
                        } else {
-
 
2495
                            $duration = '00:' . intval($response);
-
 
2496
                        }
-
 
2497
 
-
 
2498
 
-
 
2499
 
-
 
2500
                        $dataobject = new \stdClass();
-
 
2501
                        $dataobject->id = $record->id;
-
 
2502
                        $dataobject->duration = $duration;
-
 
2503
 
-
 
2504
 
-
 
2505
 
-
 
2506
                        $DB->update_record('files', $dataobject);
-
 
2507
                    }
-
 
2508
                }
-
 
2509
            }
-
 
2510
        }
-
 
2511
        return $duration;
-
 
2512
    }
-
 
2513
 
-
 
2514
    private function substr_cesa_navigation_course_menu_name($s, $l = 50)
-
 
2515
    {
-
 
2516
        $s = trim($s);
-
 
2517
        if (strlen($s) > $l) {
-
 
2518
            $s = substr($s, 0, $l) . '...';
-
 
2519
        }
-
 
2520
        return $s;
-
 
2521
    }
-
 
2522
 
-
 
2523
    public function cesa_navigation_course_menu_lateral_output()
-
 
2524
    {
-
 
2525
        global $CFG, $COURSE, $PAGE, $DB, $OUTPUT;
-
 
2526
 
-
 
2527
 
-
 
2528
 
-
 
2529
 
-
 
2530
        if (!$COURSE->id) {
-
 
2531
            return '';
-
 
2532
        }
-
 
2533
 
-
 
2534
        $course_id = $COURSE->id;
-
 
2535
 
-
 
2536
        $parent = optional_param('parent', 0, PARAM_INT); // Course module id
-
 
2537
        if (!$parent) {
-
 
2538
            $parent = optional_param('amp;parent', 0, PARAM_INT); // Course module id
-
 
2539
        }
-
 
2540
 
-
 
2541
        $PAGE->requires->js('/theme/edumynew/javascript/menu-lateral.js');
-
 
2542
 
-
 
2543
 
-
 
2544
        if ($parent) {
-
 
2545
            $sql  = ' SELECT * FROM {subcourse} WHERE course = ' . $parent;
-
 
2546
            $sql .= ' AND refcourse = ' . $course_id;
-
 
2547
 
-
 
2548
            $recordParentRefCourse  = $DB->get_record_sql($sql);
-
 
2549
            if ($recordParentRefCourse) {
-
 
2550
                $course_id = $recordParentRefCourse->course;
-
 
2551
            }
-
 
2552
        }
-
 
2553
 
-
 
2554
 
-
 
2555
 
-
 
2556
        $course = get_course($course_id);
-
 
2557
        $course_context = context_course::instance($course->id);
-
 
2558
        $completioninfo = new \completion_info($course);
-
 
2559
 
-
 
2560
        // $course_context = !empty($PAGE->cm->id)  ? $PAGE->cm : \context_course::instance($COURSE->id);
-
 
2561
        // First we should check if we want to add navigation.
-
 
2562
        // Get a list of all the activities in the course.
-
 
2563
 
-
 
2564
 
-
 
2565
 
-
 
2566
        $menu = [];
-
 
2567
 
-
 
2568
        $currentServerLink = strtolower(trim($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
-
 
2569
        $currentServerLink = html_entity_decode($currentServerLink);
-
 
2570
        $currentServerLink = htmlentities($currentServerLink);
-
 
2571
 
-
 
2572
        $parts = explode('&', $currentServerLink);
-
 
2573
        if (count($parts) > 1) {
-
 
2574
            $currentServerLink = $parts[0];
-
 
2575
        }
-
 
2576
 
-
 
2577
 
-
 
2578
 
-
 
2579
 
-
 
2580
        $modules = get_fast_modinfo($course->id)->get_cms();
-
 
2581
 
-
 
2582
        $prevmod = null;
-
 
2583
        $nextmod = null;
-
 
2584
        $currentmod = new stdClass();
-
 
2585
        $currentmod->name = "Sin Módulos";
-
 
2586
        $mods = [];
-
 
2587
        $menu = [];
-
 
2588
        $numberOfTemary = 1;
-
 
2589
        $prevlink = new \StdClass();
-
 
2590
        $nextlink = new \StdClass();
-
 
2591
        $prevlink->url = "#";
-
 
2592
        $nextlink->url = "#";
-
 
2593
 
-
 
2594
        $isACoursePage = $course->id !== "1" ? true : false;
-
 
2595
 
-
 
2596
 
-
 
2597
 
-
 
2598
 
-
 
2599
        $modules = get_fast_modinfo($COURSE->id)->get_cms();
-
 
2600
        /*
-
 
2601
            echo '<pre>';
-
 
2602
            print_r($modules);
-
 
2603
            echo '</pre>';
-
 
2604
            */
-
 
2605
 
-
 
2606
        if (!empty($modules)) {
-
 
2607
            // Put the modules into an array in order by the position they are shown in the course.
-
 
2608
            foreach ($modules as $module) {
-
 
2609
                if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
-
 
2610
                    continue;
-
 
2611
                }
-
 
2612
                $mods[$module->id] = $module;
-
 
2613
            }
-
 
2614
 
-
 
2615
 
-
 
2616
            $nummods = count($mods);
-
 
2617
 
-
 
2618
 
-
 
2619
            // If there is only one mod then do nothing.
-
 
2620
            if ($nummods == 1) {
-
 
2621
            }
-
 
2622
 
-
 
2623
            // Get an array of just the course module ids used to get the cmid value based on their position in the course.
-
 
2624
            $modids = array_keys($mods);
-
 
2625
 
-
 
2626
            // Get the position in the array of the course module we are viewing.
-
 
2627
            $position = array_search($course_context->id, $modids);   //array_search($this->page->cm->id, $modids);
-
 
2628
 
-
 
2629
            $currentmod = $mods[$modids[$position]];
-
 
2630
 
-
 
2631
 
-
 
2632
 
-
 
2633
            // Check if we have a previous mod to show.
-
 
2634
            if ($position > 0) {
-
 
2635
                $prevmod = $mods[$modids[$position - 1]];
-
 
2636
            }
-
 
2637
 
-
 
2638
            // Check if we have a next mod to show.
-
 
2639
            if ($position < ($nummods - 1)) {
-
 
2640
                $nextmod = $mods[$modids[$position + 1]];
-
 
2641
            }
-
 
2642
        }
-
 
2643
 
-
 
2644
 
-
 
2645
        //$sections = $DB->get_records('course_sections', ['course' => $COURSE->id], 'section ASC', 'id,name,section,sequence,visible');
-
 
2646
 
-
 
2647
 
-
 
2648
 
-
 
2649
 
-
 
2650
        $modinfo = get_fast_modinfo($course);
-
 
2651
        $records  =  $modinfo->get_section_info_all();
-
 
2652
        $sections = [];
-
 
2653
 
-
 
2654
        foreach ($records as $record) {
-
 
2655
            if (!$record->visible) {
-
 
2656
                continue;
-
 
2657
            }
-
 
2658
 
-
 
2659
            $section = new \stdClass();
-
 
2660
            $section->id = $record->id;
-
 
2661
            $section->section = $record->section;
-
 
2662
            $section->name = $record->name;
-
 
2663
            $section->parent = $record->parent;
-
 
2664
            $section->visible = 1;
-
 
2665
 
-
 
2666
 
-
 
2667
            array_push($sections, $section);
-
 
2668
        }
-
 
2669
 
-
 
2670
 
-
 
2671
 
-
 
2672
        $openParent = 0;
-
 
2673
        $maxSections = count($sections);
-
 
2674
        for ($i = 0; $i < $maxSections; $i++) {
-
 
2675
 
-
 
2676
 
-
 
2677
 
-
 
2678
            $j = $i + 1;
-
 
2679
            if ($j < $maxSections) {
-
 
2680
 
-
 
2681
                if ($sections[$j]->parent) {
-
 
2682
                    $openParent = true;
-
 
2683
                    $sections[$i]->close_section_parent = 0;
-
 
2684
                    $sections[$i]->close_section = 0;
-
 
2685
                } else {
-
 
2686
                    $sections[$i]->close_section_parent = $openParent ? 1 : 0;
-
 
2687
 
-
 
2688
                    $sections[$i]->close_section = 1;
-
 
2689
                }
-
 
2690
            } else {
-
 
2691
                $sections[$i]->close_section_parent = $openParent ? 1 : 0;
-
 
2692
                $sections[$i]->close_section = 1;
-
 
2693
            }
-
 
2694
 
-
 
2695
            // print_r($section);
-
 
2696
 
-
 
2697
 
-
 
2698
        }
-
 
2699
 
-
 
2700
        /*
-
 
2701
             echo '<pre>';
-
 
2702
           print_r($sections);
-
 
2703
           echo '</pre>';
-
 
2704
      
-
 
2705
      */
-
 
2706
 
-
 
2707
 
-
 
2708
 
-
 
2709
 
-
 
2710
        foreach ($sections as $key =>  $section) {
-
 
2711
 
-
 
2712
 
-
 
2713
            if (!$section->visible) {
-
 
2714
                continue;
-
 
2715
            }
-
 
2716
 
-
 
2717
            $activities = [];
-
 
2718
            $section_active = false;
-
 
2719
 
-
 
2720
 
-
 
2721
            foreach ($modules as $module) {
-
 
2722
 
-
 
2723
                /*
-
 
2724
                                       echo '<pre>';
-
 
2725
                    print_r($module);
-
 
2726
                    echo '</pre>';
-
 
2727
                    // exit;
-
 
2728
                    
-
 
2729
                     */
-
 
2730
 
-
 
2731
 
-
 
2732
 
-
 
2733
 
-
 
2734
 
-
 
2735
 
-
 
2736
 
-
 
2737
                if ($module->section  != $section->id) {
-
 
2738
 
-
 
2739
 
-
 
2740
 
-
 
2741
                    continue;
-
 
2742
                }
-
 
2743
 
-
 
2744
                if (!$module->uservisible || $module->is_stealth()) {
-
 
2745
 
-
 
2746
                    // if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
-
 
2747
                    continue;
-
 
2748
                }
-
 
2749
                $mods[$module->id] = $module;
-
 
2750
 
-
 
2751
                /*
-
 
2752
                    if($module->instance == 649) {
-
 
2753
                        
-
 
2754
                        echo '<pre>';
-
 
2755
                        echo 'module->section = '.  $module->section .  ' $section->id = '  . $section->id . "\r\n";
-
 
2756
                        echo '/<pre>';
-
 
2757
                        exit;
-
 
2758
                        
-
 
2759
                    }*/
-
 
2760
 
-
 
2761
 
-
 
2762
 
-
 
2763
                $duration = '';
-
 
2764
                $type = '';
-
 
2765
                $filepath = '';
-
 
2766
 
-
 
2767
                $sql = 'SELECT md.name, cm.instance  FROM {modules} md  ' .
-
 
2768
                    ' JOIN {course_modules} cm ON cm.module = md.id ' .
-
 
2769
                    ' WHERE cm.id = '  . $module->id . ' LIMIT 1 ';
-
 
2770
 
-
 
2771
                $record = $DB->get_record_sql($sql);
-
 
2772
                if ($record) {
-
 
2773
 
-
 
2774
                    /*
-
 
2775
                        echo '<pre>';
-
 
2776
                        print_r($record);
-
 
2777
                        echo '<pre>';
-
 
2778
                        */
-
 
2779
 
-
 
2780
                    $type = $record->name;
-
 
2781
 
-
 
2782
                    if ($type == 'hvp') {
-
 
2783
                        $instance   = $record->instance;
-
 
2784
 
-
 
2785
                        $sql = 'SELECT json_content FROM {hvp} WHERE id = ' . $instance . ' LIMIT 1';
-
 
2786
                        $record = $DB->get_record_sql($sql);
-
 
2787
 
-
 
2788
                        if ($record) {
-
 
2789
                            $json_content = json_decode($record->json_content);
-
 
2790
 
-
 
2791
                            if (!empty($json_content->interactiveVideo->video->files[0]->path)) {
-
 
2792
                                $filepath = trim($json_content->interactiveVideo->video->files[0]->path);
-
 
2793
                                $filepath = trim(str_replace('#tmp', '', $filepath));
-
 
2794
 
-
 
2795
 
-
 
2796
                                $arr = explode('/', $filepath);
-
 
2797
                                if (count($arr) > 1) {
-
 
2798
                                    $filename = $arr[count($arr) - 1];
-
 
2799
                                } else {
-
 
2800
                                    $filename = $arr[0];
-
 
2801
                                }
-
 
2802
 
-
 
2803
                                $record = $DB->get_record('files', ['filename' => $filename]);
-
 
2804
                                if ($record) {
-
 
2805
                                    $duration = $this->extractDurationFromVideo($record, $filename);
-
 
2806
                                }
-
 
2807
                            }
-
 
2808
                        }
-
 
2809
                    }
-
 
2810
                }
-
 
2811
 
-
 
2812
 
-
 
2813
 
-
 
2814
                $modname = $module->get_formatted_name();
-
 
2815
                if (empty($module->url)) {
-
 
2816
                    $linkurl = '';
-
 
2817
                    $currentLink = '';
-
 
2818
                } else {
-
 
2819
 
-
 
2820
                    $linkurl = new moodle_url($module->url, array('forceview' => 1));
-
 
2821
                    $linkurl = strtolower(trim($linkurl->__toString()));
-
 
2822
 
-
 
2823
                    $parts = explode('&', $linkurl);
-
 
2824
                    if (count($parts) > 1) {
-
 
2825
                        $currentLink = $parts[0];
-
 
2826
                    } else {
-
 
2827
                        $currentLink = $linkurl;
-
 
2828
                    }
-
 
2829
                }
-
 
2830
 
-
 
2831
 
-
 
2832
 
-
 
2833
 
-
 
2834
 
-
 
2835
                $completiondata = $completioninfo->get_data($module, true);
-
 
2836
 
-
 
2837
 
-
 
2838
                if (strcasecmp($currentLink,  $currentServerLink) == 0) {
-
 
2839
                    $active = true;
-
 
2840
                    $section_active = true;
-
 
2841
                } else {
-
 
2842
                    $active = false;
-
 
2843
                }
-
 
2844
 
-
 
2845
                array_push($activities, [
-
 
2846
                    'active' => $active,
-
 
2847
                    'indexElement' => $key,
-
 
2848
                    'numberOfTemary' => $numberOfTemary,
-
 
2849
                    'activity' => true,
-
 
2850
                    'blank' => !empty($section->section),
-
 
2851
                    'name' => $this->substr_cesa_navigation_course_menu_name($modname),
-
 
2852
                    'duration' => $duration,
-
 
2853
                    'type' =>  $type,
-
 
2854
                    'completed' => $completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS,
-
 
2855
                    'url' => $linkurl,
-
 
2856
 
-
 
2857
 
-
 
2858
                ]);
-
 
2859
            }
-
 
2860
 
-
 
2861
 
-
 
2862
            if ($activities) {
-
 
2863
 
-
 
2864
                if ($section->section) {
-
 
2865
                    $sectionname = trim($section->name);
-
 
2866
                    $sectionname = $sectionname ? $sectionname : ' Tema ' . $section->section;
-
 
2867
                } else {
-
 
2868
                    $sectionname = 'Recursos';
-
 
2869
                }
-
 
2870
 
-
 
2871
                array_push($menu, [
-
 
2872
                    'active' => $section_active,
-
 
2873
                    'indexElement' => $key,
-
 
2874
                    'numberOfTemary' => $numberOfTemary,
-
 
2875
                    'section' => true,
-
 
2876
                    'name' => $this->substr_cesa_navigation_course_menu_name($sectionname),
-
 
2877
                    'close_section_parent' => $section->close_section_parent,
-
 
2878
                    'close_section' => $section->close_section,
-
 
2879
                    'completed' => false,
-
 
2880
                    'url' => false,
-
 
2881
                    'activities' => $activities,
-
 
2882
 
-
 
2883
 
-
 
2884
                ]);
-
 
2885
            }
-
 
2886
 
-
 
2887
 
-
 
2888
            $numberOfTemary = ++$numberOfTemary;
-
 
2889
        }
-
 
2890
 
-
 
2891
        // Check if there is a previous module to display.
-
 
2892
        if ($prevmod) {
-
 
2893
            $linkurl = new \moodle_url($prevmod->url, array('forceview' => 1));
-
 
2894
            $attributes = [];
-
 
2895
            $prevlink = new \action_link($linkurl, $OUTPUT->larrow(), null, $attributes);
-
 
2896
        }
-
 
2897
 
-
 
2898
        // Check if there is a next module to display.
-
 
2899
        if ($nextmod) {
-
 
2900
            $linkurl = new \moodle_url($nextmod->url, array('forceview' => 1));
-
 
2901
            $attributes = [];
-
 
2902
            $nextlink = new \action_link($linkurl, $OUTPUT->rarrow(), null, $attributes);
-
 
2903
        }
-
 
2904
 
-
 
2905
 
-
 
2906
        //  echo '<pre>'; 
-
 
2907
        // print_r($activities);
-
 
2908
        // echo '</pre>';
-
 
2909
        // exit;
-
 
2910
 
-
 
2911
 
-
 
2912
        $progreso = number_format(progress::get_course_progress_percentage($course), 2); // Progreso por curso
-
 
2913
 
-
 
2914
 
-
 
2915
        $course_navigation = new \theme_universe_child\output\custom_drawer($prevlink->url, $nextlink->url, $menu, $this->substr_cesa_navigation_course_menu_name($currentmod->name, 10), false, $isACoursePage,  $COURSE->summary, $progreso);
-
 
2916
        return $course_navigation->export_for_template($OUTPUT);
2431
    }
2917
    }