Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 19... Línea 19...
19
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
19
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
20
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
20
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 */
21
 */
Línea 22... Línea 22...
22
 
22
 
23
use mod_data\manager;
-
 
Línea 24... Línea 23...
24
use mod_data\preset;
23
use mod_data\manager;
Línea 25... Línea 24...
25
 
24
 
26
defined('MOODLE_INTERNAL') || die();
25
defined('MOODLE_INTERNAL') || die();
Línea 510... Línea 509...
510
     * @param int $recordid
509
     * @param int $recordid
511
     * @param object $template
510
     * @param object $template
512
     * @return bool|string
511
     * @return bool|string
513
     */
512
     */
514
    function display_browse_field($recordid, $template) {
513
    function display_browse_field($recordid, $template) {
515
        global $DB;
-
 
516
        $content = $this->get_data_content($recordid);
514
        $content = $this->get_data_content($recordid);
517
        if (!$content || !isset($content->content)) {
515
        if (!$content || !isset($content->content)) {
518
            return '';
516
            return '';
519
        }
517
        }
520
        $options = new stdClass();
518
        $options = new stdClass();
521
        if ($this->field->param1 == '1') {
519
        if ($this->field->param1 == '1') {
522
            // We are autolinking this field, so disable linking within us.
520
            // We are autolinking this field, so disable linking within us.
523
            $options->filter = false;
521
            $options->filter = false;
524
        }
522
        }
525
        $options->para = false;
523
        $options->para = false;
-
 
524
        $format = !empty($content->content1) && !empty(trim($content->content1)) ? $content->content1 : null;
526
        $str = format_text($content->content, $content->content1, $options);
525
        $str = format_text($content->content, $format, $options);
527
        return $str;
526
        return $str;
528
    }
527
    }
Línea 529... Línea 528...
529
 
528
 
530
    /**
529
    /**
Línea 639... Línea 638...
639
     * @return string
638
     * @return string
640
     */
639
     */
641
    function image() {
640
    function image() {
642
        global $OUTPUT;
641
        global $OUTPUT;
Línea 643... Línea 642...
643
 
642
 
644
        return $OUTPUT->pix_icon('field/' . $this->type, $this->type, 'data');
643
        return $OUTPUT->image_icon('icon', $this->type, 'datafield_' . $this->type);
Línea 645... Línea 644...
645
    }
644
    }
646
 
645
 
647
    /**
646
    /**
Línea 879... Línea 878...
879
        $selectedtags += $DB->get_records_sql_menu($sql, $params);
878
        $selectedtags += $DB->get_records_sql_menu($sql, $params);
880
    }
879
    }
Línea 881... Línea 880...
881
 
880
 
Línea 882... Línea 881...
882
    $tags += $selectedtags;
881
    $tags += $selectedtags;
883
 
882
 
884
    $str .= '<select class="custom-select" name="tags[]" id="tags" multiple>';
883
    $str .= '<select class="form-select" name="tags[]" id="tags" multiple>';
885
    foreach ($tags as $tagid => $tag) {
884
    foreach ($tags as $tagid => $tag) {
886
        $selected = key_exists($tagid, $selectedtags) ? 'selected' : '';
885
        $selected = key_exists($tagid, $selectedtags) ? 'selected' : '';
887
        $str .= "<option value='$tag' $selected>$tag</option>";
886
        $str .= "<option value='$tag' $selected>$tag</option>";
Línea 1535... Línea 1534...
1535
 
1534
 
1536
    return grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, NULL, array('deleted'=>1));
1535
    return grade_update('mod/data', $data->course, 'mod', 'data', $data->id, 0, NULL, array('deleted'=>1));
Línea 1537... Línea 1536...
1537
}
1536
}
1538
 
-
 
1539
// junk functions
-
 
1540
/**
-
 
1541
 * takes a list of records, the current data, a search string,
-
 
1542
 * and mode to display prints the translated template
-
 
1543
 *
-
 
1544
 * @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more.
-
 
1545
 * @todo MDL-75189 Final deprecation in Moodle 4.5.
-
 
1546
 * @param string $templatename the template name
-
 
1547
 * @param array $records the entries records
-
 
1548
 * @param stdClass $data the database instance object
-
 
1549
 * @param string $search the current search term
-
 
1550
 * @param int $page page number for pagination
-
 
1551
 * @param bool $return if the result should be returned (true) or printed (false)
-
 
1552
 * @param moodle_url|null $jumpurl a moodle_url by which to jump back to the record list (can be null)
-
 
1553
 * @return mixed string with all parsed entries or nothing if $return is false
-
 
1554
 */
-
 
1555
function data_print_template($templatename, $records, $data, $search='', $page=0, $return=false, moodle_url $jumpurl=null) {
-
 
1556
    debugging(
-
 
1557
        'data_print_template is deprecated. Use mod_data\\manager::get_template and mod_data\\template::parse_entries instead',
-
 
1558
        DEBUG_DEVELOPER
-
 
1559
    );
-
 
1560
 
-
 
1561
    $options = [
-
 
1562
        'search' => $search,
-
 
1563
        'page' => $page,
-
 
1564
    ];
-
 
1565
    if ($jumpurl) {
-
 
1566
        $options['baseurl'] = $jumpurl;
-
 
1567
    }
-
 
1568
    $manager = manager::create_from_instance($data);
-
 
1569
    $parser = $manager->get_template($templatename, $options);
-
 
1570
    $content = $parser->parse_entries($records);
-
 
1571
    if ($return) {
-
 
1572
        return $content;
-
 
1573
    }
-
 
Línea 1574... Línea 1537...
1574
    echo $content;
1537
 
1575
}
1538
// junk functions
1576
 
1539
 
1577
/**
1540
/**
Línea 1778... Línea 1741...
1778
 
1741
 
1779
    $cm = get_coursemodule_from_instance('data', $data->id);
1742
    $cm = get_coursemodule_from_instance('data', $data->id);
1780
    $context = context_module::instance($cm->id);
1743
    $context = context_module::instance($cm->id);
1781
    echo '<div class="datapreferences my-5">';
1744
    echo '<div class="datapreferences my-5">';
1782
    echo '<form id="options" action="view.php" method="get">';
1745
    echo '<form id="options" action="view.php" method="get">';
1783
    echo '<div class="d-flex">';
-
 
1784
    echo '<div>';
1746
    echo '<div class="d-flex flex-wrap align-items-center gap-1">';
1785
    echo '<input type="hidden" name="d" value="'.$data->id.'" />';
1747
    echo '<input type="hidden" name="d" value="'.$data->id.'" />';
1786
    if ($mode =='asearch') {
1748
    if ($mode =='asearch') {
1787
        $advanced = 1;
1749
        $advanced = 1;
1788
        echo '<input type="hidden" name="mode" value="list" />';
1750
        echo '<input type="hidden" name="mode" value="list" />';
1789
    }
1751
    }
1790
    echo '<label for="pref_perpage">'.get_string('pagesize','data').'</label> ';
1752
    echo '<label for="pref_perpage">'.get_string('pagesize','data').'</label> ';
1791
    $pagesizes = array(2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,
1753
    $pagesizes = array(2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10,15=>15,
1792
                       20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000);
1754
                       20=>20,30=>30,40=>40,50=>50,100=>100,200=>200,300=>300,400=>400,500=>500,1000=>1000);
1793
    echo html_writer::select($pagesizes, 'perpage', $perpage, false, array('id' => 'pref_perpage',
1755
    echo html_writer::select($pagesizes, 'perpage', $perpage, false, array('id' => 'pref_perpage',
Línea 1794... Línea 1756...
1794
        'class' => 'custom-select mr-1'));
1756
        'class' => 'form-select me-1'));
1795
 
1757
 
1796
    if ($advanced) {
1758
    if ($advanced) {
1797
        $regsearchclass = 'search_none';
1759
        $regsearchclass = 'search_none';
1798
        $advancedsearchclass = 'search_inline';
1760
        $advancedsearchclass = 'search_inline';
1799
    } else {
1761
    } else {
1800
        $regsearchclass = 'search_inline';
1762
        $regsearchclass = 'search_inline';
1801
        $advancedsearchclass = 'search_none';
1763
        $advancedsearchclass = 'search_none';
1802
    }
1764
    }
1803
    echo '<div id="reg_search" class="' . $regsearchclass . ' mr-1" >';
1765
    echo '<div id="reg_search" class="' . $regsearchclass . ' me-1" >';
1804
    echo '<label for="pref_search" class="mr-1">' . get_string('search') . '</label><input type="text" ' .
1766
    echo '<label for="pref_search" class="me-1">' . get_string('search') . '</label><input type="text" ' .
1805
         'class="form-control d-inline-block align-middle w-auto mr-1" size="16" name="search" id= "pref_search" value="' . s($search) . '" /></div>';
1767
         'class="form-control d-inline-block align-middle w-auto me-1" size="16" name="search" id= "pref_search" value="' . s($search) . '" /></div>';
1806
    echo '<label for="pref_sortby">'.get_string('sortby').'</label> ';
1768
    echo '<label for="pref_sortby">'.get_string('sortby').'</label> ';
1807
    // foreach field, print the option
1769
    // foreach field, print the option
1808
    echo '<select name="sort" id="pref_sortby" class="custom-select mr-1">';
1770
    echo '<select name="sort" id="pref_sortby" class="form-select me-1">';
1809
    if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'name')) {
1771
    if ($fields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'name')) {
1810
        echo '<optgroup label="'.get_string('fields', 'data').'">';
1772
        echo '<optgroup label="'.get_string('fields', 'data').'">';
1811
        foreach ($fields as $field) {
1773
        foreach ($fields as $field) {
Línea 1834... Línea 1796...
1834
        }
1796
        }
1835
    }
1797
    }
1836
    echo '</optgroup>';
1798
    echo '</optgroup>';
1837
    echo '</select>';
1799
    echo '</select>';
1838
    echo '<label for="pref_order" class="accesshide">'.get_string('order').'</label>';
1800
    echo '<label for="pref_order" class="accesshide">'.get_string('order').'</label>';
1839
    echo '<select id="pref_order" name="order" class="custom-select mr-1">';
1801
    echo '<select id="pref_order" name="order" class="form-select me-1">';
1840
    if ($order == 'ASC') {
1802
    if ($order == 'ASC') {
1841
        echo '<option value="ASC" selected="selected">'.get_string('ascending','data').'</option>';
1803
        echo '<option value="ASC" selected="selected">'.get_string('ascending','data').'</option>';
1842
    } else {
1804
    } else {
1843
        echo '<option value="ASC">'.get_string('ascending','data').'</option>';
1805
        echo '<option value="ASC">'.get_string('ascending','data').'</option>';
1844
    }
1806
    }
Línea 1859... Línea 1821...
1859
    echo '<input type="hidden" name="advanced" value="0" />';
1821
    echo '<input type="hidden" name="advanced" value="0" />';
1860
    echo '<input type="hidden" name="filter" value="1" />';
1822
    echo '<input type="hidden" name="filter" value="1" />';
1861
    echo '<input type="checkbox" id="advancedcheckbox" name="advanced" value="1" ' . $checked . ' ' .
1823
    echo '<input type="checkbox" id="advancedcheckbox" name="advanced" value="1" ' . $checked . ' ' .
1862
         'onchange="showHideAdvSearch(this.checked);" class="mx-1" />' .
1824
         'onchange="showHideAdvSearch(this.checked);" class="mx-1" />' .
1863
         '<label for="advancedcheckbox">' . get_string('advancedsearch', 'data') . '</label>';
1825
         '<label for="advancedcheckbox">' . get_string('advancedsearch', 'data') . '</label>';
1864
    echo '</div>';
-
 
1865
    echo '<div id="advsearch-save-sec" class="ml-auto '. $regsearchclass . '">';
1826
    echo '<div id="advsearch-save-sec" class="ms-3 '. $regsearchclass . '">';
1866
    echo '<input type="submit" class="btn btn-secondary" value="' . get_string('savesettings', 'data') . '" />';
1827
    echo '<input type="submit" class="btn btn-secondary" value="' . get_string('savesettings', 'data') . '" />';
1867
    echo '</div>';
1828
    echo '</div>';
1868
    echo '</div>';
1829
    echo '</div>';
1869
    echo '<div>';
-
 
Línea 1870... Línea 1830...
1870
 
1830
 
1871
    echo '<br />';
1831
    echo '<br />';
1872
    echo '<div class="' . $advancedsearchclass . '" id="data_adv_form">';
1832
    echo '<div class="' . $advancedsearchclass . '" id="data_adv_form">';
Línea 1966... Línea 1926...
1966
    echo '<tr><td>';
1926
    echo '<tr><td>';
1967
    echo preg_replace($patterns, $replacement, format_text($asearchtemplate, FORMAT_HTML, $options));
1927
    echo preg_replace($patterns, $replacement, format_text($asearchtemplate, FORMAT_HTML, $options));
1968
    echo '</td></tr>';
1928
    echo '</td></tr>';
Línea 1969... Línea 1929...
1969
 
1929
 
1970
    echo '<tr><td colspan="4"><br/>' .
1930
    echo '<tr><td colspan="4"><br/>' .
1971
         '<input type="submit" class="btn btn-primary mr-1" value="' . get_string('savesettings', 'data') . '" />' .
1931
         '<input type="submit" class="btn btn-primary me-1" value="' . get_string('savesettings', 'data') . '" />' .
1972
         '<input type="submit" class="btn btn-secondary" name="resetadv" value="' . get_string('resetsettings', 'data') . '" />' .
1932
         '<input type="submit" class="btn btn-secondary" name="resetadv" value="' . get_string('resetsettings', 'data') . '" />' .
1973
         '</td></tr>';
1933
         '</td></tr>';
1974
    echo '</table>';
1934
    echo '</table>';
1975
    echo '</div>';
1935
    echo '</div>';
Línea 2214... Línea 2174...
2214
    }
2174
    }
2215
    return true;
2175
    return true;
2216
}
2176
}
Línea 2217... Línea 2177...
2217
 
2177
 
2218
/**
-
 
2219
 * Returns the best name to show for a preset
-
 
2220
 *
-
 
2221
 * @param string $shortname
-
 
2222
 * @param  string $path
-
 
2223
 * @return string
-
 
2224
 * @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::get_name_from_plugin() function instead.
-
 
2225
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
2226
 * @see preset::get_name_from_plugin()
-
 
2227
 */
-
 
2228
function data_preset_name($shortname, $path) {
-
 
2229
    debugging('data_preset_name() is deprecated. Please use preset::get_name_from_plugin() instead.', DEBUG_DEVELOPER);
-
 
2230
 
-
 
2231
    return preset::get_name_from_plugin($shortname);
-
 
2232
}
-
 
2233
 
-
 
2234
/**
-
 
2235
 * Returns an array of all the available presets.
-
 
2236
 *
-
 
2237
 * @return array
-
 
2238
 * @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_presets() function instead.
-
 
2239
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
2240
 * @see manager::get_available_presets()
-
 
2241
 */
-
 
2242
function data_get_available_presets($context) {
-
 
2243
    debugging('data_get_available_presets() is deprecated. Please use manager::get_available_presets() instead.', DEBUG_DEVELOPER);
-
 
2244
 
-
 
2245
    $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST);
-
 
2246
    $manager = manager::create_from_coursemodule($cm);
-
 
2247
    return $manager->get_available_presets();
-
 
2248
}
-
 
2249
 
-
 
2250
/**
-
 
2251
 * Gets an array of all of the presets that users have saved to the site.
-
 
2252
 *
-
 
2253
 * @param stdClass $context The context that we are looking from.
-
 
2254
 * @param array $presets
-
 
2255
 * @return array An array of presets
-
 
2256
 * @deprecated since Moodle 4.1 MDL-75148 - please, use the manager::get_available_saved_presets() function instead.
-
 
2257
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
2258
 * @see manager::get_available_saved_presets()
-
 
2259
 */
-
 
2260
function data_get_available_site_presets($context, array $presets=array()) {
-
 
2261
    debugging(
-
 
2262
        'data_get_available_site_presets() is deprecated. Please use manager::get_available_saved_presets() instead.',
-
 
2263
        DEBUG_DEVELOPER
-
 
2264
    );
-
 
2265
 
-
 
2266
    $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST);
-
 
2267
    $manager = manager::create_from_coursemodule($cm);
-
 
2268
    $savedpresets = $manager->get_available_saved_presets();
-
 
2269
    return array_merge($presets, $savedpresets);
-
 
2270
}
-
 
2271
 
-
 
2272
/**
-
 
2273
 * Deletes a saved preset.
-
 
2274
 *
-
 
2275
 * @param string $name
-
 
2276
 * @return bool
-
 
2277
 * @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::delete() function instead.
-
 
2278
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
2279
 * @see preset::delete()
-
 
2280
 */
-
 
2281
function data_delete_site_preset($name) {
-
 
2282
    debugging('data_delete_site_preset() is deprecated. Please use preset::delete() instead.', DEBUG_DEVELOPER);
-
 
2283
 
-
 
2284
    $fs = get_file_storage();
-
 
2285
 
-
 
2286
    $files = $fs->get_directory_files(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, '/'.$name.'/');
-
 
2287
    if (!empty($files)) {
-
 
2288
        foreach ($files as $file) {
-
 
2289
            $file->delete();
-
 
2290
        }
-
 
2291
    }
-
 
2292
 
-
 
2293
    $dir = $fs->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, '/'.$name.'/', '.');
-
 
2294
    if (!empty($dir)) {
-
 
2295
        $dir->delete();
-
 
2296
    }
-
 
2297
    return true;
-
 
2298
}
-
 
2299
 
-
 
2300
/**
2178
/**
2301
 * Prints the heads for a page
2179
 * Prints the heads for a page
2302
 *
2180
 *
2303
 * @param stdClass $course
2181
 * @param stdClass $course
2304
 * @param stdClass $cm
2182
 * @param stdClass $cm
Línea 2427... Línea 2305...
2427
    }
2305
    }
2428
    return true;
2306
    return true;
2429
}
2307
}
Línea 2430... Línea 2308...
2430
 
2308
 
2431
/**
-
 
2432
 * Check if the files in a directory are the expected for a preset.
-
 
2433
 *
-
 
2434
 * @return bool Wheter the defined $directory has or not all the expected preset files.
-
 
2435
 *
-
 
2436
 * @deprecated since Moodle 4.1 MDL-75148 - please, use the preset::is_directory_a_preset() function instead.
-
 
2437
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
2438
 * @see manager::is_directory_a_preset()
-
 
2439
 */
-
 
2440
function is_directory_a_preset($directory) {
-
 
2441
    debugging('is_directory_a_preset() is deprecated. Please use preset::is_directory_a_preset() instead.', DEBUG_DEVELOPER);
-
 
2442
 
-
 
2443
    return preset::is_directory_a_preset($directory);
-
 
2444
}
-
 
2445
 
-
 
2446
/**
-
 
2447
 * Abstract class used for data preset importers
-
 
2448
 *
-
 
2449
 * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more.
-
 
2450
 * @todo MDL-75189 Final deprecation in Moodle 4.5.
-
 
2451
 */
-
 
2452
abstract class data_preset_importer {
-
 
2453
 
-
 
2454
    protected $course;
-
 
2455
    protected $cm;
-
 
2456
    protected $module;
-
 
2457
    protected $directory;
-
 
2458
 
-
 
2459
    /**
-
 
2460
     * Constructor
-
 
2461
     *
-
 
2462
     * @param stdClass $course
-
 
2463
     * @param stdClass $cm
-
 
2464
     * @param stdClass $module
-
 
2465
     * @param string $directory
-
 
2466
     */
-
 
2467
    public function __construct($course, $cm, $module, $directory) {
-
 
2468
        debugging(
-
 
2469
            'data_preset_importer is deprecated. Please use mod\\data\\local\\importer\\preset_importer instead',
-
 
2470
            DEBUG_DEVELOPER
-
 
2471
        );
-
 
2472
 
-
 
2473
        $this->course = $course;
-
 
2474
        $this->cm = $cm;
-
 
2475
        $this->module = $module;
-
 
2476
        $this->directory = $directory;
-
 
2477
    }
-
 
2478
 
-
 
2479
    /**
-
 
2480
     * Returns the name of the directory the preset is located in
-
 
2481
     * @return string
-
 
2482
     */
-
 
2483
    public function get_directory() {
-
 
2484
        return basename($this->directory);
-
 
2485
    }
-
 
2486
 
-
 
2487
    /**
-
 
2488
     * Retreive the contents of a file. That file may either be in a conventional directory of the Moodle file storage
-
 
2489
     * @param file_storage $filestorage. should be null if using a conventional directory
-
 
2490
     * @param stored_file $fileobj the directory to look in. null if using a conventional directory
-
 
2491
     * @param string $dir the directory to look in. null if using the Moodle file storage
-
 
2492
     * @param string $filename the name of the file we want
-
 
2493
     * @return string the contents of the file or null if the file doesn't exist.
-
 
2494
     */
-
 
2495
    public function data_preset_get_file_contents(&$filestorage, &$fileobj, $dir, $filename) {
-
 
2496
        if(empty($filestorage) || empty($fileobj)) {
-
 
2497
            if (substr($dir, -1)!='/') {
-
 
2498
                $dir .= '/';
-
 
2499
            }
-
 
2500
            if (file_exists($dir.$filename)) {
-
 
2501
                return file_get_contents($dir.$filename);
-
 
2502
            } else {
-
 
2503
                return null;
-
 
2504
            }
-
 
2505
        } else {
-
 
2506
            if ($filestorage->file_exists(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename)) {
-
 
2507
                $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename);
-
 
2508
                return $file->get_content();
-
 
2509
            } else {
-
 
2510
                return null;
-
 
2511
            }
-
 
2512
        }
-
 
2513
 
-
 
2514
    }
-
 
2515
    /**
-
 
2516
     * Gets the preset settings
-
 
2517
     * @global moodle_database $DB
-
 
2518
     * @return stdClass
-
 
2519
     */
-
 
2520
    public function get_preset_settings() {
-
 
2521
        global $DB, $CFG;
-
 
2522
        require_once($CFG->libdir.'/xmlize.php');
-
 
2523
 
-
 
2524
        $fs = $fileobj = null;
-
 
2525
        if (!preset::is_directory_a_preset($this->directory)) {
-
 
2526
            //maybe the user requested a preset stored in the Moodle file storage
-
 
2527
 
-
 
2528
            $fs = get_file_storage();
-
 
2529
            $files = $fs->get_area_files(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA);
-
 
2530
 
-
 
2531
            //preset name to find will be the final element of the directory
-
 
2532
            $explodeddirectory = explode('/', $this->directory);
-
 
2533
            $presettofind = end($explodeddirectory);
-
 
2534
 
-
 
2535
            //now go through the available files available and see if we can find it
-
 
2536
            foreach ($files as $file) {
-
 
2537
                if (($file->is_directory() && $file->get_filepath()=='/') || !$file->is_directory()) {
-
 
2538
                    continue;
-
 
2539
                }
-
 
2540
                $presetname = trim($file->get_filepath(), '/');
-
 
2541
                if ($presetname==$presettofind) {
-
 
2542
                    $this->directory = $presetname;
-
 
2543
                    $fileobj = $file;
-
 
2544
                }
-
 
2545
            }
-
 
2546
 
-
 
2547
            if (empty($fileobj)) {
-
 
2548
                throw new \moodle_exception('invalidpreset', 'data', '', $this->directory);
-
 
2549
            }
-
 
2550
        }
-
 
2551
 
-
 
2552
        $allowed_settings = array(
-
 
2553
            'intro',
-
 
2554
            'comments',
-
 
2555
            'requiredentries',
-
 
2556
            'requiredentriestoview',
-
 
2557
            'maxentries',
-
 
2558
            'rssarticles',
-
 
2559
            'approval',
-
 
2560
            'defaultsortdir',
-
 
2561
            'defaultsort');
-
 
2562
 
-
 
2563
        $result = new stdClass;
-
 
2564
        $result->settings = new stdClass;
-
 
2565
        $result->importfields = array();
-
 
2566
        $result->currentfields = $DB->get_records('data_fields', array('dataid'=>$this->module->id));
-
 
2567
        if (!$result->currentfields) {
-
 
2568
            $result->currentfields = array();
-
 
2569
        }
-
 
2570
 
-
 
2571
 
-
 
2572
        /* Grab XML */
-
 
2573
        $presetxml = $this->data_preset_get_file_contents($fs, $fileobj, $this->directory,'preset.xml');
-
 
2574
        $parsedxml = xmlize($presetxml, 0);
-
 
2575
 
-
 
2576
        /* First, do settings. Put in user friendly array. */
-
 
2577
        $settingsarray = $parsedxml['preset']['#']['settings'][0]['#'];
-
 
2578
        $result->settings = new StdClass();
-
 
2579
        foreach ($settingsarray as $setting => $value) {
-
 
2580
            if (!is_array($value) || !in_array($setting, $allowed_settings)) {
-
 
2581
                // unsupported setting
-
 
2582
                continue;
-
 
2583
            }
-
 
2584
            $result->settings->$setting = $value[0]['#'];
-
 
2585
        }
-
 
2586
 
-
 
2587
        /* Now work out fields to user friendly array */
-
 
2588
        $fieldsarray = $parsedxml['preset']['#']['field'];
-
 
2589
        foreach ($fieldsarray as $field) {
-
 
2590
            if (!is_array($field)) {
-
 
2591
                continue;
-
 
2592
            }
-
 
2593
            $f = new StdClass();
-
 
2594
            foreach ($field['#'] as $param => $value) {
-
 
2595
                if (!is_array($value)) {
-
 
2596
                    continue;
-
 
2597
                }
-
 
2598
                $f->$param = $value[0]['#'];
-
 
2599
            }
-
 
2600
            $f->dataid = $this->module->id;
-
 
2601
            $f->type = clean_param($f->type, PARAM_ALPHA);
-
 
2602
            $result->importfields[] = $f;
-
 
2603
        }
-
 
2604
        /* Now add the HTML templates to the settings array so we can update d */
-
 
2605
        $result->settings->singletemplate     = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"singletemplate.html");
-
 
2606
        $result->settings->listtemplate       = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplate.html");
-
 
2607
        $result->settings->listtemplateheader = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplateheader.html");
-
 
2608
        $result->settings->listtemplatefooter = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplatefooter.html");
-
 
2609
        $result->settings->addtemplate        = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"addtemplate.html");
-
 
2610
        $result->settings->rsstemplate        = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstemplate.html");
-
 
2611
        $result->settings->rsstitletemplate   = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstitletemplate.html");
-
 
2612
        $result->settings->csstemplate        = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"csstemplate.css");
-
 
2613
        $result->settings->jstemplate         = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"jstemplate.js");
-
 
2614
        $result->settings->asearchtemplate    = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"asearchtemplate.html");
-
 
2615
 
-
 
2616
        $result->settings->instance = $this->module->id;
-
 
2617
        return $result;
-
 
2618
    }
-
 
2619
 
-
 
2620
    /**
-
 
2621
     * Import the preset into the given database module
-
 
2622
     * @return bool
-
 
2623
     */
-
 
2624
    function import($overwritesettings) {
-
 
2625
        global $DB, $CFG, $OUTPUT;
-
 
2626
 
-
 
2627
        $params = $this->get_preset_settings();
-
 
2628
        $settings = $params->settings;
-
 
2629
        $newfields = $params->importfields;
-
 
2630
        $currentfields = $params->currentfields;
-
 
2631
        $preservedfields = array();
-
 
2632
 
-
 
2633
        /* Maps fields and makes new ones */
-
 
2634
        if (!empty($newfields)) {
-
 
2635
            /* We require an injective mapping, and need to know what to protect */
-
 
2636
            foreach ($newfields as $nid => $newfield) {
-
 
2637
                $cid = optional_param("field_$nid", -1, PARAM_INT);
-
 
2638
                if ($cid == -1) {
-
 
2639
                    continue;
-
 
2640
                }
-
 
2641
                if (array_key_exists($cid, $preservedfields)){
-
 
2642
                    throw new \moodle_exception('notinjectivemap', 'data');
-
 
2643
                }
-
 
2644
                else $preservedfields[$cid] = true;
-
 
2645
            }
-
 
2646
            $missingfieldtypes = [];
-
 
2647
            foreach ($newfields as $nid => $newfield) {
-
 
2648
                $cid = optional_param("field_$nid", -1, PARAM_INT);
-
 
2649
 
-
 
2650
                /* A mapping. Just need to change field params. Data kept. */
-
 
2651
                if ($cid != -1 and isset($currentfields[$cid])) {
-
 
2652
                    $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->module);
-
 
2653
                    foreach ($newfield as $param => $value) {
-
 
2654
                        if ($param != "id") {
-
 
2655
                            $fieldobject->field->$param = $value;
-
 
2656
                        }
-
 
2657
                    }
-
 
2658
                    unset($fieldobject->field->similarfield);
-
 
2659
                    $fieldobject->update_field();
-
 
2660
                    unset($fieldobject);
-
 
2661
                } else {
-
 
2662
                    /* Make a new field */
-
 
2663
                    $filepath = "field/$newfield->type/field.class.php";
-
 
2664
                    if (!file_exists($filepath)) {
-
 
2665
                        $missingfieldtypes[] = $newfield->name;
-
 
2666
                        continue;
-
 
2667
                    }
-
 
2668
                    include_once($filepath);
-
 
2669
 
-
 
2670
                    if (!isset($newfield->description)) {
-
 
2671
                        $newfield->description = '';
-
 
2672
                    }
-
 
2673
                    $classname = 'data_field_'.$newfield->type;
-
 
2674
                    $fieldclass = new $classname($newfield, $this->module);
-
 
2675
                    $fieldclass->insert_field();
-
 
2676
                    unset($fieldclass);
-
 
2677
                }
-
 
2678
            }
-
 
2679
            if (!empty($missingfieldtypes)) {
-
 
2680
                echo $OUTPUT->notification(get_string('missingfieldtypeimport', 'data') . html_writer::alist($missingfieldtypes));
-
 
2681
            }
-
 
2682
        }
-
 
2683
 
-
 
2684
        /* Get rid of all old unused data */
-
 
2685
        foreach ($currentfields as $cid => $currentfield) {
-
 
2686
            if (!array_key_exists($cid, $preservedfields)) {
-
 
2687
                /* Data not used anymore so wipe! */
-
 
2688
                echo "Deleting field $currentfield->name<br />";
-
 
2689
 
-
 
2690
                // Delete all information related to fields.
-
 
2691
                $todelete = data_get_field_from_id($currentfield->id, $this->module);
-
 
2692
                $todelete->delete_field();
-
 
2693
            }
-
 
2694
        }
-
 
2695
 
-
 
2696
        // handle special settings here
-
 
2697
        if (!empty($settings->defaultsort)) {
-
 
2698
            if (is_numeric($settings->defaultsort)) {
-
 
2699
                // old broken value
-
 
2700
                $settings->defaultsort = 0;
-
 
2701
            } else {
-
 
2702
                $settings->defaultsort = (int)$DB->get_field('data_fields', 'id', array('dataid'=>$this->module->id, 'name'=>$settings->defaultsort));
-
 
2703
            }
-
 
2704
        } else {
-
 
2705
            $settings->defaultsort = 0;
-
 
2706
        }
-
 
2707
 
-
 
2708
        // do we want to overwrite all current database settings?
-
 
2709
        if ($overwritesettings) {
-
 
2710
            // all supported settings
-
 
2711
            $overwrite = array_keys((array)$settings);
-
 
2712
        } else {
-
 
2713
            // only templates and sorting
-
 
2714
            $overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
-
 
2715
                               'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate',
-
 
2716
                               'asearchtemplate', 'defaultsortdir', 'defaultsort');
-
 
2717
        }
-
 
2718
 
-
 
2719
        // now overwrite current data settings
-
 
2720
        foreach ($this->module as $prop=>$unused) {
-
 
2721
            if (in_array($prop, $overwrite)) {
-
 
2722
                $this->module->$prop = $settings->$prop;
-
 
2723
            }
-
 
2724
        }
-
 
2725
 
-
 
2726
        data_update_instance($this->module);
-
 
2727
 
-
 
2728
        return $this->cleanup();
-
 
2729
    }
-
 
2730
 
-
 
2731
    /**
-
 
2732
     * Any clean up routines should go here
-
 
2733
     * @return bool
-
 
2734
     */
-
 
2735
    public function cleanup() {
-
 
2736
        return true;
-
 
2737
    }
-
 
2738
}
-
 
2739
 
-
 
2740
/**
-
 
2741
 * Data preset importer for uploaded presets
-
 
2742
 *
-
 
2743
 * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more.
-
 
2744
 * @todo MDL-75189 Final deprecation in Moodle 4.5.
-
 
2745
 */
-
 
2746
class data_preset_upload_importer extends data_preset_importer {
-
 
2747
    public function __construct($course, $cm, $module, $filepath) {
-
 
2748
        global $USER;
-
 
2749
 
-
 
2750
        debugging(
-
 
2751
            'data_preset_upload_importer is deprecated. Please use mod\\data\\local\\importer\\preset_upload_importer instead',
-
 
2752
            DEBUG_DEVELOPER
-
 
2753
        );
-
 
2754
 
-
 
2755
        if (is_file($filepath)) {
-
 
2756
            $fp = get_file_packer();
-
 
2757
            if ($fp->extract_to_pathname($filepath, $filepath.'_extracted')) {
-
 
2758
                fulldelete($filepath);
-
 
2759
            }
-
 
2760
            $filepath .= '_extracted';
-
 
2761
        }
-
 
2762
        parent::__construct($course, $cm, $module, $filepath);
-
 
2763
    }
-
 
2764
 
-
 
2765
    public function cleanup() {
-
 
2766
        return fulldelete($this->directory);
-
 
2767
    }
-
 
2768
}
-
 
2769
 
-
 
2770
/**
-
 
2771
 * Data preset importer for existing presets
-
 
2772
 *
-
 
2773
 * @deprecated since Moodle 4.1 MDL-75140 - please do not use this class any more.
-
 
2774
 * @todo MDL-75189 Final deprecation in Moodle 4.5.
-
 
2775
 */
-
 
2776
class data_preset_existing_importer extends data_preset_importer {
-
 
2777
    protected $userid;
-
 
2778
    public function __construct($course, $cm, $module, $fullname) {
-
 
2779
        global $USER;
-
 
2780
 
-
 
2781
        debugging(
-
 
2782
            'data_preset_existing_importer is deprecated. Please use mod\\data\\local\\importer\\preset_existing_importer instead',
-
 
2783
            DEBUG_DEVELOPER
-
 
2784
        );
-
 
2785
 
-
 
2786
        list($userid, $shortname) = explode('/', $fullname, 2);
-
 
2787
        $context = context_module::instance($cm->id);
-
 
2788
        if ($userid && ($userid != $USER->id) && !has_capability('mod/data:manageuserpresets', $context) && !has_capability('mod/data:viewalluserpresets', $context)) {
-
 
2789
           throw new coding_exception('Invalid preset provided');
-
 
2790
        }
-
 
2791
 
-
 
2792
        $this->userid = $userid;
-
 
2793
        $filepath = data_preset_path($course, $userid, $shortname);
-
 
2794
        parent::__construct($course, $cm, $module, $filepath);
-
 
2795
    }
-
 
2796
    public function get_userid() {
-
 
2797
        return $this->userid;
-
 
2798
    }
-
 
2799
}
-
 
2800
 
-
 
2801
/**
2309
/**
2802
 * @global object
2310
 * @global object
2803
 * @global object
2311
 * @global object
2804
 * @param object $course
2312
 * @param object $course
2805
 * @param int $userid
2313
 * @param int $userid
Línea 2831... Línea 2339...
2831
 *
2339
 *
2832
 * @param MoodleQuickForm $mform form passed by reference
2340
 * @param MoodleQuickForm $mform form passed by reference
2833
 */
2341
 */
2834
function data_reset_course_form_definition(&$mform) {
2342
function data_reset_course_form_definition(&$mform) {
2835
    $mform->addElement('header', 'dataheader', get_string('modulenameplural', 'data'));
2343
    $mform->addElement('header', 'dataheader', get_string('modulenameplural', 'data'));
-
 
2344
    $mform->addElement('static', 'datadelete', get_string('delete'));
2836
    $mform->addElement('checkbox', 'reset_data', get_string('deleteallentries','data'));
2345
    $mform->addElement('checkbox', 'reset_data', get_string('deleteallentries','data'));
Línea 2837... Línea 2346...
2837
 
2346
 
2838
    $mform->addElement('checkbox', 'reset_data_notenrolled', get_string('deletenotenrolled', 'data'));
2347
    $mform->addElement('checkbox', 'reset_data_notenrolled', get_string('deletenotenrolled', 'data'));
Línea 2891... Línea 2400...
2891
    global $CFG, $DB;
2400
    global $CFG, $DB;
2892
    require_once($CFG->libdir.'/filelib.php');
2401
    require_once($CFG->libdir.'/filelib.php');
2893
    require_once($CFG->dirroot.'/rating/lib.php');
2402
    require_once($CFG->dirroot.'/rating/lib.php');
Línea 2894... Línea 2403...
2894
 
2403
 
2895
    $componentstr = get_string('modulenameplural', 'data');
2404
    $componentstr = get_string('modulenameplural', 'data');
Línea 2896... Línea 2405...
2896
    $status = array();
2405
    $status = [];
2897
 
2406
 
2898
    $allrecordssql = "SELECT r.id
2407
    $allrecordssql = "SELECT r.id
2899
                        FROM {data_records} r
2408
                        FROM {data_records} r
Línea 2910... Línea 2419...
2910
    $ratingdeloptions->ratingarea = 'entry';
2419
    $ratingdeloptions->ratingarea = 'entry';
Línea 2911... Línea 2420...
2911
 
2420
 
2912
    // Set the file storage - may need it to remove files later.
2421
    // Set the file storage - may need it to remove files later.
Línea 2913... Línea 2422...
2913
    $fs = get_file_storage();
2422
    $fs = get_file_storage();
2914
 
2423
 
2915
    // delete entries if requested
2424
    // Delete entries if requested.
2916
    if (!empty($data->reset_data)) {
2425
    if (!empty($data->reset_data)) {
2917
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
2426
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", [$data->courseid]);
Línea 2918... Línea 2427...
2918
        $DB->delete_records_select('data_content', "recordid IN ($allrecordssql)", array($data->courseid));
2427
        $DB->delete_records_select('data_content', "recordid IN ($allrecordssql)", [$data->courseid]);
2919
        $DB->delete_records_select('data_records', "dataid IN ($alldatassql)", array($data->courseid));
2428
        $DB->delete_records_select('data_records', "dataid IN ($alldatassql)", [$data->courseid]);
2920
 
2429
 
2921
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
2430
        if ($datas = $DB->get_records_sql($alldatassql, [$data->courseid])) {
2922
            foreach ($datas as $dataid=>$unused) {
2431
            foreach ($datas as $dataid=>$unused) {
2923
                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
2432
                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
Línea 2934... Línea 2443...
2934
                core_tag_tag::delete_instances('mod_data', null, $datacontext->id);
2443
                core_tag_tag::delete_instances('mod_data', null, $datacontext->id);
2935
            }
2444
            }
2936
        }
2445
        }
Línea 2937... Línea 2446...
2937
 
2446
 
2938
        if (empty($data->reset_gradebook_grades)) {
2447
        if (empty($data->reset_gradebook_grades)) {
2939
            // remove all grades from gradebook
2448
            // Remove all grades from gradebook.
2940
            data_reset_gradebook($data->courseid);
2449
            data_reset_gradebook($data->courseid);
-
 
2450
        }
-
 
2451
        $status[] = [
2941
        }
2452
            'component' => $componentstr,
-
 
2453
            'item' => get_string('deleteallentries', 'data'),
-
 
2454
            'error' => false,
2942
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallentries', 'data'), 'error'=>false);
2455
        ];
Línea 2943... Línea 2456...
2943
    }
2456
    }
2944
 
2457
 
2945
    // remove entries by users not enrolled into course
2458
    // Remove entries by users not enrolled into course.
2946
    if (!empty($data->reset_data_notenrolled)) {
2459
    if (!empty($data->reset_data_notenrolled)) {
2947
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted
2460
        $recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted
2948
                         FROM {data_records} r
2461
                         FROM {data_records} r
2949
                              JOIN {data} d ON r.dataid = d.id
2462
                              JOIN {data} d ON r.dataid = d.id
Línea 2950... Línea 2463...
2950
                              LEFT JOIN {user} u ON r.userid = u.id
2463
                              LEFT JOIN {user} u ON r.userid = u.id
2951
                        WHERE d.course = ? AND r.userid > 0";
2464
                        WHERE d.course = ? AND r.userid > 0";
2952
 
2465
 
2953
        $course_context = context_course::instance($data->courseid);
2466
        $course_context = context_course::instance($data->courseid);
2954
        $notenrolled = array();
2467
        $notenrolled = [];
2955
        $fields = array();
2468
        $fields = [];
2956
        $rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
2469
        $rs = $DB->get_recordset_sql($recordssql, [$data->courseid]);
2957
        foreach ($rs as $record) {
2470
        foreach ($rs as $record) {
2958
            if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
2471
            if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
2959
              or !is_enrolled($course_context, $record->userid)) {
2472
              or !is_enrolled($course_context, $record->userid)) {
2960
                //delete ratings
2473
                // Delete ratings.
2961
                if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) {
2474
                if (!$cm = get_coursemodule_from_instance('data', $record->dataid)) {
2962
                    continue;
2475
                    continue;
2963
                }
2476
                }
2964
                $datacontext = context_module::instance($cm->id);
2477
                $datacontext = context_module::instance($cm->id);
Línea 2965... Línea 2478...
2965
                $ratingdeloptions->contextid = $datacontext->id;
2478
                $ratingdeloptions->contextid = $datacontext->id;
2966
                $ratingdeloptions->itemid = $record->id;
2479
                $ratingdeloptions->itemid = $record->id;
2967
                $rm->delete_ratings($ratingdeloptions);
2480
                $rm->delete_ratings($ratingdeloptions);
2968
 
2481
 
2969
                // Delete any files that may exist.
2482
                // Delete any files that may exist.
2970
                if ($contents = $DB->get_records('data_content', array('recordid' => $record->id), '', 'id')) {
2483
                if ($contents = $DB->get_records('data_content', ['recordid' => $record->id], '', 'id')) {
2971
                    foreach ($contents as $content) {
2484
                    foreach ($contents as $content) {
Línea 2972... Línea 2485...
2972
                        $fs->delete_area_files($datacontext->id, 'mod_data', 'content', $content->id);
2485
                        $fs->delete_area_files($datacontext->id, 'mod_data', 'content', $content->id);
Línea 2973... Línea 2486...
2973
                    }
2486
                    }
2974
                }
2487
                }
2975
                $notenrolled[$record->userid] = true;
2488
                $notenrolled[$record->userid] = true;
2976
 
2489
 
2977
                core_tag_tag::remove_all_item_tags('mod_data', 'data_records', $record->id);
2490
                core_tag_tag::remove_all_item_tags('mod_data', 'data_records', $record->id);
2978
 
2491
 
-
 
2492
                $DB->delete_records('comments', ['itemid' => $record->id, 'commentarea' => 'database_entry']);
-
 
2493
                $DB->delete_records('data_content', ['recordid' => $record->id]);
2979
                $DB->delete_records('comments', array('itemid' => $record->id, 'commentarea' => 'database_entry'));
2494
                $DB->delete_records('data_records', ['id' => $record->id]);
-
 
2495
            }
-
 
2496
        }
2980
                $DB->delete_records('data_content', array('recordid' => $record->id));
2497
        $rs->close();
Línea 2981... Línea 2498...
2981
                $DB->delete_records('data_records', array('id' => $record->id));
2498
        $status[] = [
2982
            }
2499
            'component' => $componentstr,
2983
        }
2500
            'item' => get_string('deletenotenrolled', 'data'),
2984
        $rs->close();
2501
            'error' => false,
2985
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deletenotenrolled', 'data'), 'error'=>false);
2502
        ];
2986
    }
2503
    }
2987
 
2504
 
2988
    // remove all ratings
2505
    // Remove all ratings.
Línea 2998... Línea 2515...
2998
                $rm->delete_ratings($ratingdeloptions);
2515
                $rm->delete_ratings($ratingdeloptions);
2999
            }
2516
            }
3000
        }
2517
        }
Línea 3001... Línea 2518...
3001
 
2518
 
3002
        if (empty($data->reset_gradebook_grades)) {
2519
        if (empty($data->reset_gradebook_grades)) {
3003
            // remove all grades from gradebook
2520
            // Remove all grades from gradebook.
3004
            data_reset_gradebook($data->courseid);
2521
            data_reset_gradebook($data->courseid);
Línea -... Línea 2522...
-
 
2522
        }
-
 
2523
 
3005
        }
2524
        $status[] = [
-
 
2525
            'component' => $componentstr,
-
 
2526
            'item' => get_string('deleteallratings'),
3006
 
2527
            'error' => false,
Línea 3007... Línea 2528...
3007
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallratings'), 'error'=>false);
2528
        ];
3008
    }
2529
    }
3009
 
2530
 
-
 
2531
    // Remove all comments.
-
 
2532
    if (!empty($data->reset_data_comments)) {
3010
    // remove all comments
2533
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", [$data->courseid]);
-
 
2534
        $status[] = [
-
 
2535
            'component' => $componentstr,
3011
    if (!empty($data->reset_data_comments)) {
2536
            'item' => get_string('deleteallcomments'),
Línea 3012... Línea 2537...
3012
        $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
2537
            'error' => false,
3013
        $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
2538
        ];
3014
    }
2539
    }
3015
 
2540
 
3016
    // Remove all the tags.
2541
    // Remove all the tags.
3017
    if (!empty($data->reset_data_tags)) {
2542
    if (!empty($data->reset_data_tags)) {
3018
        if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
2543
        if ($datas = $DB->get_records_sql($alldatassql, [$data->courseid])) {
Línea 3019... Línea 2544...
3019
            foreach ($datas as $dataid => $unused) {
2544
            foreach ($datas as $dataid => $unused) {
3020
                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
2545
                if (!$cm = get_coursemodule_from_instance('data', $dataid)) {
Línea 3021... Línea 2546...
3021
                    continue;
2546
                    continue;
3022
                }
2547
                }
-
 
2548
 
-
 
2549
                $context = context_module::instance($cm->id);
3023
 
2550
                core_tag_tag::delete_instances('mod_data', null, $context->id);
-
 
2551
 
-
 
2552
            }
3024
                $context = context_module::instance($cm->id);
2553
        }
Línea 3025... Línea 2554...
3025
                core_tag_tag::delete_instances('mod_data', null, $context->id);
2554
        $status[] = [
3026
 
2555
            'component' => $componentstr,
3027
            }
2556
            'item' => get_string('removealldatatags', 'data'),
3028
        }
2557
            'error' => false,
-
 
2558
        ];
-
 
2559
    }
-
 
2560
 
3029
        $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'data'), 'error' => false);
2561
    // Updating dates - shift may be negative too.
-
 
2562
    if ($data->timeshift) {
-
 
2563
        // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
-
 
2564
        // See MDL-9367.
-
 
2565
        shift_course_mod_dates(
3030
    }
2566
            'data',
-
 
2567
            [
-
 
2568
                'timeavailablefrom',
-
 
2569
                'timeavailableto',
-
 
2570
                'timeviewfrom',
-
 
2571
                'timeviewto',
-
 
2572
                'assesstimestart',
3031
 
2573
                'assesstimefinish',
-
 
2574
            ],
-
 
2575
            $data->timeshift,
3032
    // updating dates - shift may be negative too
2576
            $data->courseid,
Línea 3033... Línea 2577...
3033
    if ($data->timeshift) {
2577
        );
3034
        // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
2578
        $status[] = [
Línea 3355... Línea 2899...
3355
        $datanode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
2899
        $datanode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
3356
    }
2900
    }
3357
}
2901
}
Línea 3358... Línea 2902...
3358
 
2902
 
3359
/**
-
 
3360
 * Save the database configuration as a preset.
-
 
3361
 *
-
 
3362
 * @param stdClass $course The course the database module belongs to.
-
 
3363
 * @param stdClass $cm The course module record
-
 
3364
 * @param stdClass $data The database record
-
 
3365
 * @param string $path
-
 
3366
 * @return bool
-
 
3367
 * @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::save() function instead.
-
 
3368
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
3369
 * @see preset::save()
-
 
3370
 */
-
 
3371
function data_presets_save($course, $cm, $data, $path) {
-
 
3372
    debugging('data_presets_save() is deprecated. Please use preset::save() instead.', DEBUG_DEVELOPER);
-
 
3373
 
-
 
3374
    $manager = manager::create_from_instance($data);
-
 
3375
    $preset = preset::create_from_instance($manager, $path);
-
 
3376
    return $preset->save();
-
 
3377
}
-
 
3378
 
-
 
3379
/**
-
 
3380
 * Generates the XML for the database module provided
-
 
3381
 *
-
 
3382
 * @global moodle_database $DB
-
 
3383
 * @param stdClass $course The course the database module belongs to.
-
 
3384
 * @param stdClass $cm The course module record
-
 
3385
 * @param stdClass $data The database record
-
 
3386
 * @return string The XML for the preset
-
 
3387
 * @deprecated since Moodle 4.1 MDL-75142 - please, use the protected preset::generate_preset_xml() function instead.
-
 
3388
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
3389
 * @see preset::generate_preset_xml()
-
 
3390
 */
-
 
3391
function data_presets_generate_xml($course, $cm, $data) {
-
 
3392
    debugging(
-
 
3393
        'data_presets_generate_xml() is deprecated. Please use the protected preset::generate_preset_xml() instead.',
-
 
3394
        DEBUG_DEVELOPER
-
 
3395
    );
-
 
3396
 
-
 
3397
    $manager = manager::create_from_instance($data);
-
 
3398
    $preset = preset::create_from_instance($manager, $data->name);
-
 
3399
    $reflection = new \ReflectionClass(preset::class);
-
 
3400
    $method = $reflection->getMethod('generate_preset_xml');
-
 
3401
    return $method->invokeArgs($preset, []);
-
 
3402
}
-
 
3403
 
-
 
3404
/**
-
 
3405
 * Export current fields and presets.
-
 
3406
 *
-
 
3407
 * @param stdClass $course The course the database module belongs to.
-
 
3408
 * @param stdClass $cm The course module record
-
 
3409
 * @param stdClass $data The database record
-
 
3410
 * @param bool $tostorage
-
 
3411
 * @return string the full path to the exported preset file.
-
 
3412
 * @deprecated since Moodle 4.1 MDL-75142 - please, use the preset::export() function instead.
-
 
3413
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
3414
 * @see preset::export()
-
 
3415
 */
-
 
3416
function data_presets_export($course, $cm, $data, $tostorage=false) {
-
 
3417
    debugging('data_presets_export() is deprecated. Please use preset::export() instead.', DEBUG_DEVELOPER);
-
 
3418
 
-
 
3419
    $manager = manager::create_from_instance($data);
-
 
3420
    $preset = preset::create_from_instance($manager, $data->name);
-
 
3421
    return $preset->export();
-
 
3422
}
-
 
3423
 
-
 
3424
/**
2903
/**
3425
 * Running addtional permission check on plugin, for example, plugins
2904
 * Running addtional permission check on plugin, for example, plugins
3426
 * may have switch to turn on/off comments option, this callback will
2905
 * may have switch to turn on/off comments option, this callback will
3427
 * affect UI display, not like pluginname_comment_validate only throw
2906
 * affect UI display, not like pluginname_comment_validate only throw
3428
 * exceptions.
2907
 * exceptions.
Línea 3754... Línea 3233...
3754
    $sqlselect['params'] = $inparam;
3233
    $sqlselect['params'] = $inparam;
3755
    return $sqlselect;
3234
    return $sqlselect;
3756
}
3235
}
Línea 3757... Línea 3236...
3757
 
3236
 
3758
/**
-
 
3759
 * Checks to see if the user has permission to delete the preset.
-
 
3760
 * @param stdClass $context  Context object.
-
 
3761
 * @param stdClass $preset  The preset object that we are checking for deletion.
-
 
3762
 * @return bool  Returns true if the user can delete, otherwise false.
-
 
3763
 * @deprecated since Moodle 4.1 MDL-75187 - please, use the preset::can_manage() function instead.
-
 
3764
 * @todo MDL-75189 This will be deleted in Moodle 4.5.
-
 
3765
 * @see preset::can_manage()
-
 
3766
 */
-
 
3767
function data_user_can_delete_preset($context, $preset) {
-
 
3768
    global $USER;
-
 
3769
 
-
 
3770
    debugging('data_user_can_delete_preset() is deprecated. Please use manager::can_manage() instead.', DEBUG_DEVELOPER);
-
 
3771
 
-
 
3772
    if ($context->contextlevel == CONTEXT_MODULE && isset($preset->name)) {
-
 
3773
        $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST);
-
 
3774
        $manager = manager::create_from_coursemodule($cm);
-
 
3775
        $todelete = preset::create_from_instance($manager, $preset->name);
-
 
3776
        return $todelete->can_manage();
-
 
3777
    }
-
 
3778
 
-
 
3779
    if (has_capability('mod/data:manageuserpresets', $context)) {
-
 
3780
        return true;
-
 
3781
    } else {
-
 
3782
        $candelete = false;
-
 
3783
        $userid = $preset instanceof preset ? $preset->get_userid() : $preset->userid;
-
 
3784
        if ($userid == $USER->id) {
-
 
3785
            $candelete = true;
-
 
3786
        }
-
 
3787
        return $candelete;
-
 
3788
    }
-
 
3789
}
-
 
3790
 
-
 
3791
/**
3237
/**
3792
 * Delete a record entry.
3238
 * Delete a record entry.
3793
 *
3239
 *
3794
 * @param int $recordid The ID for the record to be deleted.
3240
 * @param int $recordid The ID for the record to be deleted.
3795
 * @param object $data The data object for this activity.
3241
 * @param object $data The data object for this activity.
Línea 4049... Línea 3495...
4049
            $completion->update_state($cm, COMPLETION_INCOMPLETE);
3495
            $completion->update_state($cm, COMPLETION_INCOMPLETE);
4050
        }
3496
        }
4051
    }
3497
    }
4052
}
3498
}
Línea 4053... Línea -...
4053
 
-
 
4054
/**
-
 
4055
 * Mark the activity completed (if required) and trigger the course_module_viewed event.
-
 
4056
 *
-
 
4057
 * @deprecated since Moodle 4.1 MDL-75146 - please do not use this function any more.
-
 
4058
 * @todo MDL-75189 Final deprecation in Moodle 4.5.
-
 
4059
 * @param  stdClass $data       data object
-
 
4060
 * @param  stdClass $course     course object
-
 
4061
 * @param  stdClass $cm         course module object
-
 
4062
 * @param  stdClass $context    context object
-
 
4063
 * @since Moodle 3.3
-
 
4064
 */
-
 
4065
function data_view($data, $course, $cm, $context) {
-
 
4066
    global $CFG;
-
 
4067
    debugging('data_view is deprecated. Use mod_data\\manager::set_module_viewed instead', DEBUG_DEVELOPER);
-
 
4068
    require_once($CFG->libdir . '/completionlib.php');
-
 
4069
 
-
 
4070
    // Trigger course_module_viewed event.
-
 
4071
    $params = array(
-
 
4072
        'context' => $context,
-
 
4073
        'objectid' => $data->id
-
 
4074
    );
-
 
4075
 
-
 
4076
    $event = \mod_data\event\course_module_viewed::create($params);
-
 
4077
    $event->add_record_snapshot('course_modules', $cm);
-
 
4078
    $event->add_record_snapshot('course', $course);
-
 
4079
    $event->add_record_snapshot('data', $data);
-
 
4080
    $event->trigger();
-
 
4081
 
-
 
4082
    // Completion.
-
 
4083
    $completion = new completion_info($course);
-
 
4084
    $completion->set_module_viewed($cm);
-
 
Línea 4085... Línea 3499...
4085
}
3499
 
4086
 
3500
 
-
 
3501
/**
-
 
3502
 * Get the list of deprecated icons.
-
 
3503
 *
4087
/**
3504
 * @return array with the deprecated key icons.
4088
 * Get icon mapping for font-awesome.
3505
 * @todo Final deprecation on Moodle 6.0 MDL-83465.
4089
 */
3506
 */
-
 
3507
function mod_data_get_deprecated_icons() {
-
 
3508
    return [
4090
function mod_data_get_fontawesome_icon_map() {
3509
        // Deprecated since Moodle 4.6.
4091
    return [
3510
        // See MDL-82313 for refactoring.
4092
        'mod_data:field/checkbox' => 'fa-check-square-o',
3511
        'mod_data:field/checkbox' => 'fa-regular fa-square-check',
4093
        'mod_data:field/date' => 'fa-calendar-o',
3512
        'mod_data:field/date' => 'fa-regular fa-calendar',
4094
        'mod_data:field/file' => 'fa-file',
3513
        'mod_data:field/file' => 'fa-regular fa-file',
4095
        'mod_data:field/latlong' => 'fa-globe',
3514
        'mod_data:field/latlong' => 'fa-earth-americas',
4096
        'mod_data:field/menu' => 'fa-bars',
3515
        'mod_data:field/menu' => 'fa-bars',
4097
        'mod_data:field/multimenu' => 'fa-bars',
3516
        'mod_data:field/multimenu' => 'fa-bars',
4098
        'mod_data:field/number' => 'fa-hashtag',
3517
        'mod_data:field/number' => 'fa-hashtag',
4099
        'mod_data:field/picture' => 'fa-picture-o',
-
 
4100
        'mod_data:field/radiobutton' => 'fa-circle-o',
3518
        'mod_data:field/picture' => 'fa-regular fa-image',
-
 
3519
        'mod_data:field/radiobutton' => 'fa-regular fa-circle-dot',
4101
        'mod_data:field/textarea' => 'fa-font',
3520
        'mod_data:field/text' => 'fa-i-cursor',
4102
        'mod_data:field/text' => 'fa-i-cursor',
3521
        'mod_data:field/textarea' => 'fa-font',
4103
        'mod_data:field/url' => 'fa-link',
3522
        'mod_data:field/url' => 'fa-link',
Línea 4104... Línea 3523...
4104
    ];
3523
    ];