lib.php 4.71 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
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    mahara
 * @subpackage blocktype-plans
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

defined('INTERNAL') || die();

class PluginBlocktypePlans extends PluginBlocktype {

    public static function get_title() {
        return get_string('title', 'blocktype.plans/plans');
    }

    public static function get_description() {
        return get_string('description', 'blocktype.plans/plans');
    }

    public static function get_categories() {
        return array('general');
    }

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
     /**
     * Optional method. If exists, allows this class to decide the title for
     * all blockinstances of this type
     */
    public static function get_instance_title(BlockInstance $bi) {
        $configdata = $bi->get('configdata');

        if (!empty($configdata['artefactid'])) {
            safe_require('artefact','plans');
            $plan = new ArtefactTypePlan($configdata['artefactid']);
            $title = $plan->get('title');
            return $title;
        }
        return '';
    }

60
    public static function render_instance(BlockInstance $instance, $editing=false) {
61
62
        global $exporter;

63
64
        require_once(get_config('docroot') . 'artefact/lib.php');
        safe_require('artefact','plans');
65

66
        $configdata = $instance->get('configdata');
67

68
        $smarty = smarty_core();
69
70
        if (isset($configdata['artefactid'])) {
            $tasks = ArtefactTypeTask::get_tasks($configdata['artefactid']);
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
            $template = 'artefact:plans:taskrows.tpl';
            $blockid = $instance->get('id');
            if ($exporter) {
                $pagination = false;
            }
            else {
                $pagination = array(
                    'baseurl'   => $instance->get_view()->get_url() . '&block=' . $blockid,
                    'id'        => 'block' . $blockid . '_pagination',
                    'datatable' => 'tasktable_' . $blockid,
                    'jsonscript' => 'artefact/plans/viewtasks.json.php',
                );
            }
            ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);

            if ($exporter && $tasks['count'] > $tasks['limit']) {
                $artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $configdata['artefactid']
                    . '&amp;view=' . $instance->get('view');
                $tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
            }
91
92
93
94
95
            $smarty->assign('tasks',$tasks);
        }
        else {
            $smarty->assign('noplans','blocktype.plans/plans');
        }
96
        $smarty->assign('blockid', $instance->get('id'));
97
98
        return $smarty->fetch('blocktype:plans:content.tpl');
    }
99
100

    // My Plans blocktype only has 'title' option so next two functions return as normal
101
102
103
104
    public static function has_instance_config() {
        return true;
    }

105
    public static function instance_config_form($instance) {
106
107
108
109
110
111
112
113
        $configdata = $instance->get('configdata');

        $form = array();

        // Which resume field does the user want
        $form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);

        return $form;
114
115
116
    }

    public static function artefactchooser_element($default=null) {
117
118
119
120
121
122
123
124
125
126
127
128
        safe_require('artefact', 'plans');
        return array(
            'name'  => 'artefactid',
            'type'  => 'artefactchooser',
            'title' => get_string('planstoshow', 'blocktype.plans/plans'),
            'defaultvalue' => $default,
            'blocktype' => 'plans',
            'selectone' => true,
            'search'    => false,
            'artefacttypes' => array('plan'),
            'template'  => 'artefact:plans:artefactchooser-element.tpl',
        );
129
130
131
132
    }
}

?>