lib.php 4.5 KB
Newer Older
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage blocktype-entireresume
6
 * @author     Catalyst IT Ltd
7
8
 * @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.
9
10
11
12
13
 *
 */

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

14
class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
15
16

    public static function get_title() {
Ghada El-Zoghbi's avatar
Ghada El-Zoghbi committed
17
        return get_string('title', 'blocktype.resume/entireresume');
18
19
20
21
22
23
24
    }

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

    public static function get_categories() {
25
        return array('internal' => 29000);
26
27
    }

28
    public static function render_instance(BlockInstance $instance, $editing=false) {
29
30
31
32
33
34
35
36
37
38
39
40
        require_once(get_config('docroot') . 'artefact/lib.php');
        $smarty = smarty_core();

        // Get data about the resume fields the user has
        $return = '';
        if ($artefacts = get_records_sql_array('
            SELECT va.artefact, a.artefacttype
            FROM {view_artefact} va
            INNER JOIN {artefact} a ON (va.artefact = a.id)
            WHERE va.view = ?
            AND va.block = ?', array($instance->get('view'), $instance->get('id')))) {
            foreach ($artefacts as $artefact) {
41
                $resumefield = $instance->get_artefact_instance($artefact->artefact);
42
43
44
                $rendered = $resumefield->render_self(array('viewid' => $instance->get('view')));
                $result = $rendered['html'];
                if (!empty($rendered['javascript'])) {
45
                    $result .= '<script type="application/javascript">' . $rendered['javascript'] . '</script>';
46
47
48
49
50
51
52
                }
                $smarty->assign($artefact->artefacttype, $result);
            }
        }
        return $smarty->fetch('blocktype:entireresume:content.tpl');
    }

Aaron Wells's avatar
Aaron Wells committed
53
54
    // Yes, we do have instance config. People are allowed to specify the title
    // of the block, nothing else at this time. So in the next two methods we
55
    // say yes and return no fields, so the title will be configurable.
56
    public static function has_instance_config() {
57
58
59
        return true;
    }

Son Nguyen's avatar
Son Nguyen committed
60
    public static function instance_config_form(BlockInstance $instance) {
61
        return array();
62
63
    }

64
    public static function artefactchooser_element($default=null) {
65
66
67
    }

    /**
Aaron Wells's avatar
Aaron Wells committed
68
     * Subscribe to the blockinstancecommit event to make sure all artefacts
69
70
71
72
73
74
75
76
77
78
79
80
     * that should be in the blockinstance are
     */
    public static function get_event_subscriptions() {
        return array(
            (object)array(
                'event'        => 'blockinstancecommit',
                'callfunction' => 'ensure_resume_artefacts_in_blockinstance',
            ),
        );
    }

    /**
Aaron Wells's avatar
Aaron Wells committed
81
     * Hook for making sure that all resume artefacts are associated with a
82
83
84
     * blockinstance at blockinstance commit time
     */
    public static function ensure_resume_artefacts_in_blockinstance($event, $blockinstance) {
85
86
87
        if ($blockinstance->get('blocktype') == 'entireresume') {
            safe_require('artefact', 'resume');
            $artefacttypes = implode(', ', array_map('db_quote', PluginArtefactResume::get_artefact_types()));
88

89
90
91
92
93
            // Get all artefacts that are resume related and belong to the correct owner
            $artefacts = get_records_sql_array('
                SELECT id
                FROM {artefact}
                WHERE artefacttype IN(' . $artefacttypes . ')
Francois Marier's avatar
Francois Marier committed
94
95
                AND "owner" = (
                    SELECT "owner"
96
97
98
                    FROM {view}
                    WHERE id = ?
                )', array($blockinstance->get('view')));
99

100
101
102
103
104
105
106
107
108
109
            if ($artefacts) {
                // Make sure they're registered as being in this view
                foreach ($artefacts as $artefact) {
                    $record = (object)array(
                        'view' => $blockinstance->get('view'),
                        'artefact' => $artefact->id,
                        'block' => $blockinstance->get('id'),
                    );
                    ensure_record_exists('view_artefact', $record, $record);
                }
110
111
112
            }
        }
    }
Richard Mansfield's avatar
Richard Mansfield committed
113

114
115
116
117
    public static function default_copy_type() {
        return 'shallow';
    }

118
    /**
Aaron Wells's avatar
Aaron Wells committed
119
     * Entireresume blocktype is only allowed in personal views, because
120
121
122
123
124
125
     * there's no such thing as group/site resumes
     */
    public static function allowed_in_view(View $view) {
        return $view->get('owner') != null;
    }

126
}