view_career_setting.php 6.89 KB
Newer Older
Thomas Fradet's avatar
Thomas Fradet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

/**
 * block_career
 *
 *
 * @package    block_career
 * @category   block
 * @copyright  2018 Softia/Université lorraine
 * @author     vrignaud camille/ faouzi / Thomas Fradet
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

class view_career_setting extends moodleform
{
    public function definition()
    {
        // TODO: Implement definition() method.
        global $CFG;

        $mform = $this->_form; // Don't forget the underscore!

              //Default value
    }

    public function get_content()
    {
        global $DB, $CFG;

        $mform = $this->_form;
        $careerId = optional_param('id', NULL, PARAM_INT);
        $course = required_param('course', PARAM_INT);

        $name = "";
        $description = "";
        $ressourcesId = "";
        $contentButton = "Ajouter un parcours";
        // $imagePath = "";

        if (isset($careerId) && !empty($careerId))
        {
            $requete = $DB->get_record_sql('SELECT * FROM {block_career} WHERE id = ?', array($careerId));
            $name = $requete->name;
            $description = $requete->description;
            $ressourcesId = explode(",", $requete->ressources);
            $contentButton = "Modifier le parcours";
            // $imagePath = $requete->image;

        }


        $mform->addElement('text','careerName',get_string('titleaddname_plugin', 'block_career'));
        $mform->addRule('careerName', get_string('error'), 'required', null, null, false, false);
        $mform->setDefault('careerName',$name);

        $mform->addElement('editor', 'descriptionName', get_string('titleadddesc_plugin', 'block_career'));
        $mform->setType('descriptionName', PARAM_RAW);
        $mform->addRule('descriptionName', get_string('error'), 'required', null, null, false, false);
        $mform->setDefault('descriptionName',array('text'=>$description));

        //FilePicker IMAGE
        //$mform->addElement('filepicker', 'imageName', get_string('titleaddimg_plugin', 'block_career'), null);


        // $content = "<h1>" . get_string('title_plugin', 'block_career') . "</h1>";
Thomas Fradet's avatar
Thomas Fradet committed
66
        $content = "";
Thomas Fradet's avatar
Thomas Fradet committed
67
68
69
70
71
72
73
        $content .= "<div class='alert alert-info'>" . get_string('heading_plugin', 'block_career') . "</div>";

        $temp = $mform->toHtml();


        $temp = substr($temp,(strpos($temp,'>')+1));
        $temp = substr($temp,0, -7);
Thomas Fradet's avatar
Thomas Fradet committed
74
75
76

        $sections = block_career_section::get_sections_by_id_course($course);

Thomas Fradet's avatar
Thomas Fradet committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        $content .= '<div class="row"><form class="col-12" action="career_setting.php?course=' . $course . '" method="post" enctype="multipart/form-data">';

        $content .= $temp;

        // $content .= ' <section class="section"><h3>' . get_string('titleaddimg_plugin', 'block_career') . '</h3>
        // <input type="file" class="input" name="imageName" accept="image/*" /></section>';


        $content .= ' <section class="section row"><div class="col-12"><h2>' . get_string('titleaddelem_plugin', 'block_career') . '</h2>
        <div class="alert alert-info">' . get_string('titleaddelemdesc_plugin', 'block_career') . '</div>
        <div class="left_course_elements">
        <div class="title">Cours</div>
        <div class="subject-info-box-1">
        <select multiple="multiple" id="lstBox1" class="form-control">';

        foreach ($sections as $section)
        {
            $section->ressources = block_career_ressource::get_ressources_by_id_section($section->id);
        }

        foreach ($sections as $section)
        {
            $content .= '<optgroup label="'.$section->name.'" value="'.$section->id.'">';

            foreach ($section->ressources as $ressource)
            {
                $content .= '<option label="'.$ressource->name.'" value ="'.$ressource->id.'" name="'.$ressource->id.'">'.$ressource->name.'</option>';
            }
            $content .= '</optgroup>';
        }

        $content .='</select></div></div>';

        $content .= '<div class="middle_elements">
        <div class="title">Actions</div>
        <div class="subject-info-arrows text-center">
        <input type="button" id="btnAllRight" value=">>" class="btn btn-default iena-btn-career-arrow" /><br />
        <input type="button" id="btnRight" value=">" class="btn btn-default iena-btn-career-arrow" /><br />
        <input type="button" id="btnLeft" value="<" class="btn btn-default iena-btn-career-arrow" /><br />
        <input type="button" id="btnAllLeft" value="<<" class="btn btn-default iena-btn-career-arrow" />
        </div>
        </div>';

        $content .= '<div class="right_course_elements">
        <div class="title">Parcours</div>
        <div class="subject-info-box-2">
        <select multiple="multiple" id="lstBox2" name="ressource[]" class="form-control" required>';

Thomas Fradet's avatar
Thomas Fradet committed
125
126
127
128
129
        if ($ressourcesId != "") {
            foreach ($ressourcesId as $value)
            {
                $res = new block_career_ressource();
                $res->get_ressource_by_id($value);
Thomas Fradet's avatar
Thomas Fradet committed
130

Thomas Fradet's avatar
Thomas Fradet committed
131
132
133
                if ($careerId != 0)
                    $content .= '<option label="'.$res->name.'" value ="'.$res->id.'">';
            }
Thomas Fradet's avatar
Thomas Fradet committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
        }

        
        $content .=  '</select>
        </div>
        <div class="clearfix"></div>
        </div>
        </div>
        </section>';

        $content .= '<script>
        function selectAll(e)
        {
            // e.preventDefault();
            selectBox = document.getElementById("lstBox2");

            var checkValue = 0;

            for (var i = 0; i < selectBox.options.length; i++)
            { 
                selectBox.options[i].selected = true;
            }

            $("#lstBox2 :selected").map(function(i, el) {

                if (checkValue == $(el).val())
                $(el).remove();

                checkValue = $(el).val();
                });
            }
            // console.log()
            </script>';

Thomas Fradet's avatar
Thomas Fradet committed
168
169
170
            // if ($careerId != 0) {
            //     $content .= '<input type="hidden" name="imagePath" value="'.$imagePath.'">';
            // }
Thomas Fradet's avatar
Thomas Fradet committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

            $content .= '
            <div class="row mt-3">  
            <div class="col">
            <input type="hidden" name="careerId" value="'.$careerId.'">
            <a href=' . $CFG->wwwroot . "/blocks/career/career_list.php?course=" . $course . ' class="btn btn-secondary">Annuler</a> ';



            if ($careerId != 0) {
                $content .= "<a href='$CFG->wwwroot/blocks/career/career_setting.php?course=$course&delete=1&id=$careerId' class='btn btn-danger'>Supprimer</a> ";
            }

            $content .= '
            <button type="submit" onclick="selectAll(event);" class="btn btn-primary">'.$contentButton.'</button>
            </div>
            </div>
            ';


            $content .= '</div></form>';


            return $content;
        }

    }