createversion.php 3.75 KB
Newer Older
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
<?php
/**
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */

define('INTERNAL', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('view.php');
$viewid = param_integer('view');

$view = new View($viewid, null);

if (!$view || !$USER->can_edit_view($view) || $view->is_submitted()) {
    throw new AccessDeniedException(get_string('cantversionview', 'view'));
}
$groupid = $view->get('group');
if ($groupid && !group_within_edit_window($groupid)) {
    throw new AccessDeniedException(get_string('cantversionview', 'view'));
}

$version = new stdClass();
$version->numrows = $view->get('numrows');
$version->layout = $view->get('layout');
$version->description = $view->get('description');
31
$version->title = $view->get('title');
32
33
34
35
36
37
38
39
40
41
42
$version->tags = $view->get('tags');
$version->columnsperrow = $view->get('columnsperrow');
$version->blocks = array();
$blocks = get_records_array('block_instance', 'view', $view->get('id'));

if ($blocks) {
    foreach ($blocks as $k => $b) {
        if (safe_require('blocktype', $b->blocktype, 'lib.php', 'require_once', true) !== false) {
            $oldblock = new BlockInstance($b->id, $b);

            $bi = new stdClass();
43
            $bi->originalblockid = $oldblock->get('id');
44
45
46
47
48
49
            $bi->blocktype = $oldblock->get('blocktype');
            $bi->title = $oldblock->get('title');
            $bi->configdata = $oldblock->get('configdata');
            $bi->row = $oldblock->get('row');
            $bi->column = $oldblock->get('column');
            $bi->order = $oldblock->get('order');
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
            if (isset($bi->configdata['artefactid']) && !empty($bi->configdata['artefactid'])) {
                // The block is for one artefact so lets see if it displays more than one artefact
                if ($artefacts = call_static_method(generate_class_name('blocktype', $oldblock->get('blocktype')), 'get_current_artefacts', $oldblock)) {
                    // We need to ignore the parent artefactid
                    foreach ($artefacts as $key => $artefact) {
                        if ($bi->configdata['artefactid'] == $artefact) {
                            unset($artefacts[$key]);
                        }
                    }
                    if (!empty($artefacts)) {
                        $bi->configdata['existing_artefacts'] = $artefacts;
                    }
                }
            }
65
66
67
68
69
70
71
72
73
            if ($oldblock->get('blocktype') == 'annotation' || $oldblock->get('blocktype') ==  'textbox') {
                $configdata = $oldblock->get('configdata');
                if (!empty($configdata['artefactid'])) {
                    safe_require('artefact', 'file');
                    $artefactid = $configdata['artefactid'];
                    $artefact = $oldblock->get_artefact_instance($artefactid);
                    $bi->configdata['text'] = $artefact->get('description');
                }
            }
74
75
76
77
            if ($oldblock->get('blocktype') == 'taggedposts') {
                $tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $oldblock->get('id'), 'tagtype desc, tag', 'tag, tagtype');
                $bi->configdata['tagrecords'] = $tagrecords;
            }
78
79
80
81
82
83
84
85
86
87
88
89
90
            $version->blocks[$k] = $bi;
        }
    }
}

$fordb = new stdClass();
$fordb->view = $view->get('id');
$fordb->ctime = db_format_timestamp(time());
$fordb->blockdata = json_encode($version);
$fordb->owner = $view->get('owner');
$id = insert_record('view_versioning', $fordb, 'id', true);
$SESSION->add_ok_msg(get_string('savedtotimeline', 'view'));
redirect('/view/view.php?id=' . $view->get('id'));