Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 66... Línea 66...
66
    public function __construct($mode, mod_feedback_structure $structure, $formid, $customdata = null) {
66
    public function __construct($mode, mod_feedback_structure $structure, $formid, $customdata = null) {
67
        $this->mode = $mode;
67
        $this->mode = $mode;
68
        $this->structure = $structure;
68
        $this->structure = $structure;
69
        $this->gopage = isset($customdata['gopage']) ? $customdata['gopage'] : 0;
69
        $this->gopage = isset($customdata['gopage']) ? $customdata['gopage'] : 0;
70
        $isanonymous = $this->structure->is_anonymous() ? ' ianonymous' : '';
70
        $isanonymous = $this->structure->is_anonymous() ? ' ianonymous' : '';
71
        parent::__construct(null, $customdata, 'POST', '',
71
        parent::__construct(
-
 
72
            customdata: $customdata,
72
                array('id' => $formid, 'class' => 'feedback_form' . $isanonymous), true);
73
            attributes: ['id' => $formid, 'class' => 'feedback_form' . $isanonymous],
-
 
74
        );
73
        $this->set_display_vertical();
75
        $this->set_display_vertical();
74
    }
76
    }
Línea 75... Línea 77...
75
 
77
 
76
    /**
78
    /**
Línea 165... Línea 167...
165
     * Called from definition_after_data() in all modes except for completion
167
     * Called from definition_after_data() in all modes except for completion
166
     *
168
     *
167
     * This will add all items to the form, including pagebreaks as horizontal rules.
169
     * This will add all items to the form, including pagebreaks as horizontal rules.
168
     */
170
     */
169
    protected function definition_preview() {
171
    protected function definition_preview() {
-
 
172
        $this->_form->addElement('html', html_writer::start_div('', ['data-region' => 'questions-sortable-list']));
170
        foreach ($this->structure->get_items() as $feedbackitem) {
173
        foreach ($this->structure->get_items() as $feedbackitem) {
171
            $itemobj = feedback_get_item_class($feedbackitem->typ);
174
            $itemobj = feedback_get_item_class($feedbackitem->typ);
172
            $itemobj->complete_form_element($feedbackitem, $this);
175
            $itemobj->complete_form_element($feedbackitem, $this);
173
        }
176
        }
-
 
177
        $this->_form->addElement('html', html_writer::end_div());
174
    }
178
    }
Línea 175... Línea 179...
175
 
179
 
176
    /**
180
    /**
177
     * Removes the button that is not applicable for the current page
181
     * Removes the button that is not applicable for the current page
Línea 241... Línea 245...
241
    public function is_frozen() {
245
    public function is_frozen() {
242
        return $this->mode == self::MODE_VIEW_RESPONSE;
246
        return $this->mode == self::MODE_VIEW_RESPONSE;
243
    }
247
    }
Línea 244... Línea 248...
244
 
248
 
-
 
249
    /**
-
 
250
     * Returns whether the form is considered read-only (e.g. when previewing it)
-
 
251
     *
-
 
252
     * @return bool
-
 
253
     */
-
 
254
    private function is_readonly(): bool {
-
 
255
        return $this->mode === self::MODE_PRINT;
-
 
256
    }
-
 
257
 
245
    /**
258
    /**
246
     * Returns the current course module
259
     * Returns the current course module
247
     * @return cm_info
260
     * @return cm_info
248
     */
261
     */
249
    public function get_cm() {
262
    public function get_cm() {
Línea 308... Línea 321...
308
 
321
 
309
        // Prepend standard CSS classes to the element classes.
322
        // Prepend standard CSS classes to the element classes.
310
        $attributes = $element->getAttributes();
323
        $attributes = $element->getAttributes();
311
        $class = !empty($attributes['class']) ? ' ' . $attributes['class'] : '';
324
        $class = !empty($attributes['class']) ? ' ' . $attributes['class'] : '';
-
 
325
        $attributes['class'] = $this->get_suggested_class($item) . $class;
312
        $attributes['class'] = $this->get_suggested_class($item) . $class;
326
 
Línea 313... Línea 327...
313
        $element->setAttributes($attributes);
327
        $element->setAttributes($attributes);
314
 
328
 
315
        // Add required rule.
329
        // Add required rule.
Línea 325... Línea 339...
325
        // Freeze if needed.
339
        // Freeze if needed.
326
        if ($this->is_frozen()) {
340
        if ($this->is_frozen()) {
327
            $element->freeze();
341
            $element->freeze();
328
        }
342
        }
Línea -... Línea 343...
-
 
343
 
-
 
344
        // For read-only forms, just disable each added element.
-
 
345
        if ($this->is_readonly()) {
-
 
346
            $this->_form->disabledIf($element->getName(), 'id');
-
 
347
        }
329
 
348
 
330
        // Add red asterisks on required fields.
349
        // Add red asterisks on required fields.
331
        if ($item->required) {
350
        if ($item->required) {
-
 
351
            $requiredlabel = get_string('requiredelement', 'form');
-
 
352
            $pixparams = [
-
 
353
                'class' => 'ms-2',
-
 
354
                'title' => $requiredlabel,
-
 
355
            ];
-
 
356
            $required = $OUTPUT->pix_icon('req', '', 'moodle', $pixparams)
332
            $required = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'));
357
                . \core\output\html_writer::span("($requiredlabel)", 'visually-hidden');
333
            $element->setLabel($element->getLabel() . $required);
358
            $element->setLabel($element->getLabel() . $required);
334
            $this->hasrequired = true;
359
            $this->hasrequired = true;
Línea 335... Línea 360...
335
        }
360
        }
Línea 443... Línea 468...
443
     */
468
     */
444
    protected function enhance_name_for_edit($item, $element) {
469
    protected function enhance_name_for_edit($item, $element) {
445
        global $OUTPUT;
470
        global $OUTPUT;
446
        $menu = new action_menu();
471
        $menu = new action_menu();
447
        $menu->set_owner_selector('#' . $this->guess_element_id($item, $element));
472
        $menu->set_owner_selector('#' . $this->guess_element_id($item, $element));
448
        $menu->set_menu_trigger(get_string('edit'));
473
        $menu->set_kebab_trigger(get_string('edit'));
449
        $menu->prioritise = true;
474
        $menu->prioritise = true;
Línea 450... Línea 475...
450
 
475
 
451
        $itemobj = feedback_get_item_class($item->typ);
476
        $itemobj = feedback_get_item_class($item->typ);
452
        $actions = $itemobj->edit_actions($item, $this->get_feedback(), $this->get_cm());
477
        $actions = $itemobj->edit_actions($item, $this->get_feedback(), $this->get_cm());
453
        foreach ($actions as $action) {
478
        foreach ($actions as $action) {
454
            $menu->add($action);
479
            $menu->add($action);
455
        }
480
        }
456
        $editmenu = $OUTPUT->render($menu);
-
 
457
 
-
 
458
        $name = $element->getLabel();
-
 
459
 
-
 
460
        $name = html_writer::span('', 'itemdd', array('id' => 'feedback_item_box_' . $item->id)) .
481
        $menudata = $menu->export_for_template($OUTPUT);
461
                html_writer::span($name, 'itemname') .
482
        $element->setLabel(html_writer::span($element->getLabel(), '', [
462
                html_writer::span($editmenu, 'itemactions');
483
            'data-item-actions-menu' => json_encode($menudata),
463
        $element->setLabel(html_writer::span($name, 'itemtitle'));
484
        ]));
Línea 464... Línea 485...
464
    }
485
    }
465
 
486
 
466
    /**
487
    /**
Línea 564... Línea 585...
564
            $mform->insertElementBefore($buttons, '__dummyelement');
585
            $mform->insertElementBefore($buttons, '__dummyelement');
565
            $mform->removeElement('__dummyelement');
586
            $mform->removeElement('__dummyelement');
566
        }
587
        }
Línea 567... Línea 588...
567
 
588
 
568
        $this->_form->display();
-
 
569
 
-
 
570
        if ($this->mode == self::MODE_EDIT) {
-
 
571
            $PAGE->requires->js_call_amd('mod_feedback/edit', 'setup');
-
 
572
        }
589
        $this->_form->display();
573
    }
590
    }