matrix.php 9.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
<?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);
13
define('PUBLIC', 1);
14
15
16
17
18
19
20
21
22
23
24
25
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'framework');

require(dirname(dirname(dirname(__FILE__))) . '/init.php');

require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'collection.php');
require_once(get_config('libroot') . 'institution.php');
safe_require('module', 'framework');
safe_require('artefact', 'comment');

26
27
pieform_setup_headdata();

28
29
30
31
32
33
34
// This page should only be viewable if:
// 1). The collection has_framework() return true
// 2). The institution the collection owner belongs to has 'Smart Evidence' turned on.
// 3). The collection is able to be viewed by the user.

$collectionid = param_integer('id');
$collection = new Collection($collectionid);
35
if (!$collection->has_framework()) {
36
37
38
39
40
41
42
43
44
45
    if ($collection->get('framework') > 0) {
        // The collection does have a framework associated but we are not allowed
        // to see the matrix page so show an error page with link to first page of collection.
        $smarty = smarty();
        $smarty->assign('owner', $collection->get('owner'));
        $smarty->assign('PAGEHEADING', null);
        $smarty->assign('name', get_string('frameworkmissing', 'module.framework'));
        $smarty->assign('error', get_string('accessdeniednoframework', 'module.framework'));
        if ($collection->get('navigation')) {
            $views = $collection->get('views');
46
47
48
            if ($views) {
                $smarty->assign('firstviewlink', get_string('firstviewlink', 'module.framework', $views['views'][0]->fullurl));
            }
49
50
51
52
53
        }
        $smarty->display('module:framework:noviewmatrix.tpl');
        exit;
    }
    // No framework involved.
54
55
    throw new AccessDeniedException(get_string('accessdeniednoframework', 'module.framework'));
}
56
$owner = $collection->get('owner');
57
$views = $collection->get('views');
58
59
60
61

// Get the first view from the collection
$firstview = $views['views'][0];
$view = new View($firstview->id);
62

63
64
65
66
if (!can_view_view($view->get('id'))) {
    $errorstr = get_string('accessdenied', 'error');
    throw new AccessDeniedException($errorstr);
}
67
68
$frameworkid = $collection->get('framework');
$framework = new Framework($frameworkid);
69
$standards = $framework->standards();
70
71
72
73
74
75
// Set the sections being open/closed based on session info
$settings = !empty($SESSION->get('matrixsettings')) ? $SESSION->get('matrixsettings') : array();
foreach ($standards['standards'] as $standard) {
    $settingstate = isset($settings[$collectionid][$standard->id]) ? $settings[$collectionid][$standard->id] : 'open';
    $standard->settingstate = $settingstate;
}
76
77
78

define('TITLE', $collection->get('name'));

79
$javascript = array('js/collection-navigation.js', 'js/jquery/jquery-mobile/jquery.mobile.custom.min.js', 'tinymce', 'module/framework/js/matrix.js', 'js/jquery/jquery-ui/js/jquery-ui.min.js');
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

// Set up theme
$viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
    $THEME = new Theme($viewtheme);
}

$headers = array();
$headers[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/smoothness/jquery-ui.min.css') . '">';

// Set up skin, if the page has one
$viewskin = $view->get('skin');
$issiteview = $view->get('institution') == 'mahara';
if ($viewskin && get_config('skins') && can_use_skins($owner, false, $issiteview) && (!isset($THEME->skins) || $THEME->skins !== false)) {
    $skin = array('skinid' => $viewskin, 'viewid' => $view->get('id'));
}
else {
    $skin = false;
}

$headers[] = '<meta name="robots" content="noindex">';  // Tell search engines not to index this page

$smarty = smarty(
    $javascript,
    $headers,
    array('View' => 'view',
          'Collection' => 'collection'),
    array(
        'sidebars' => false,
        'skin' => $skin
    )
);

113
114
115
116
117
118
119
120
121
122
// collection top navigation
if ($collection) {
    $shownav = $collection->get('navigation');
    if ($shownav) {
        $viewnav = $views['views'];
        array_unshift($viewnav, $collection->collection_nav_framework_option());
        $smarty->assign('collection', $viewnav);
    }
}

Robert Lyon's avatar
Robert Lyon committed
123
$evidence = $framework->get_evidence($collection->get('id'));
124
125
126
if (!$evidence) {
    $evidence = array();
}
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

$evidencematrix = array();
$statuscounts = new StdClass();
$enabled = new StdClass();

//completed should be always enabled
$statuscounts->completed = array();
$enabled->completed = true;

if ($framework->get_config('readyforassesment_field_enabled')) {
    $statuscounts->readyforassessment = array();
    $enabled->readyforassessment = true;
}
if ($framework->get_config('partiallycomplete_field_enabled')) {
    $statuscounts->partiallycomplete = array();
    $enabled->partiallycomplete = true;
}
if ($framework->get_config('dontmatch_field_enabled')) {
    $statuscounts->dontmatch = array();
    $enabled->dontmatch = true;
}

$statusestodisplay = get_statuses_to_display($frameworkid);

151
foreach ($evidence as $e) {
152
153
154
155
    $state = Framework::get_state_array($e->state, true);
    $choices = Framework::get_evidence_statuses($e->framework);
    $state['title'] = $choices[$e->state];
    $evidencematrix[$e->framework][$e->element][$e->view] = $state;
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

    switch ($e->state) {
        case Framework::EVIDENCE_COMPLETED:
            if (isset($statuscounts->completed)) {
                if (!isset($statuscounts->completed[$e->element])) {
                    $statuscounts->completed[$e->element] = 0;
                }
                $statuscounts->completed[$e->element] ++;
            }
        break;
        case Framework::EVIDENCE_BEGUN:
            if (isset($statuscounts->readyforassessment)) {
                if (!isset($statuscounts->readyforassessment[$e->element])) {
                    $statuscounts->readyforassessment[$e->element] = 0;
                }
                $statuscounts->readyforassessment[$e->element] ++;
            }
        break;
        case Framework::EVIDENCE_PARTIALCOMPLETE:
            if (isset($statuscounts->partiallycomplete)) {
                if (!isset($statuscounts->partiallycomplete[$e->element])) {
                    $statuscounts->partiallycomplete[$e->element] = 0;
                }
                $statuscounts->partiallycomplete[$e->element] ++;
            }
        break;
        case Framework::EVIDENCE_INCOMPLETE:
            if (isset($statuscounts->dontmatch)) {
                if (!isset($statuscounts->dontmatch[$e->element])) {
                    $statuscounts->dontmatch[$e->element] = 0;
                }
                $statuscounts->dontmatch[$e->element] ++;
            }
        break;
190
191
192
    }
}

193
194
$inlinejs = <<<EOF
    // Variable to adjust for the hiding/showing of columns
195
    var frameworkid = $frameworkid; // The id of the framework via php
196
197
198
199

EOF;

$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
200
$smarty->assign('maintitle', hsc($collection->get('name')));
201
$smarty->assign('collectionid', $collection->get('id'));
202
203
204
205
206
207
$smarty->assign('owner', $owner);
$smarty->assign('PAGEHEADING', null);
$smarty->assign('name', $framework->get('name'));
$smarty->assign('description', $framework->get('description'));
$smarty->assign('standards', $standards['standards']);
$smarty->assign('evidence', $evidencematrix);
208
209
210
211
$smarty->assign('statuscounts', $statuscounts);
$smarty->assign('statusestodisplay', $statusestodisplay);
$smarty->assign('enabled', $enabled);
$smarty->assign('colspan', count((array)$enabled) * 2);
212
$smarty->assign('canaddannotation', Framework::can_annotate_view($view->get('id')));
213
214
215
216
$smarty->assign('standardscount', $standards['count']);
$smarty->assign('framework', $collection->get('framework'));
$smarty->assign('views', $views['views']);
$smarty->assign('viewcount', $views['count']);
Robert Lyon's avatar
Robert Lyon committed
217
218
219
220
221
222
223
224
225
226
227
228
229
if ($view->is_anonymous()) {
    $smarty->assign('PAGEAUTHOR', get_string('anonymoususer'));
    $smarty->assign('author', get_string('anonymoususer'));
    if ($view->is_staff_or_admin_for_page()) {
        $smarty->assign('realauthor', $view->display_author());
    }
    $smarty->assign('anonymous', TRUE);
}
else {
    $smarty->assign('PAGEAUTHOR', $view->formatted_owner());
    $smarty->assign('author', $view->display_author());
    $smarty->assign('anonymous', FALSE);
}
230
231

$smarty->display('module:framework:matrix.tpl');
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

function get_statuses_to_display($frameworkid) {
    $statusestodisplay = new StdClass();
    $allstatuses = array(
        Framework::EVIDENCE_COMPLETED,
        Framework::EVIDENCE_BEGUN,
        Framework::EVIDENCE_PARTIALCOMPLETE,
        Framework::EVIDENCE_INCOMPLETE
    );
    $choices = Framework::get_evidence_statuses($frameworkid);
    foreach ($allstatuses as $item) {
        $state = Framework::get_state_array($item, true);
        switch ($item) {
            case Framework::EVIDENCE_COMPLETED:
            $statusestodisplay->completed = array(
                'classes' => $state['classes'],
                'title' => $choices[$item],
            );
            break;
            case Framework::EVIDENCE_BEGUN:
            $statusestodisplay->readyforassessment = array(
                'classes' => $state['classes'],
                'title' => $choices[$item],
            );
            break;
            case Framework::EVIDENCE_PARTIALCOMPLETE:
            $statusestodisplay->partiallycomplete = array(
                'classes' => $state['classes'],
                'title' => $choices[$item],
            );
            break;
            case Framework::EVIDENCE_INCOMPLETE:
            $statusestodisplay->dontmatch = array (
                'classes' => $state['classes'],
                'title' => $choices[$item],
            );
            break;
        }
    }
    return $statusestodisplay;
}