~ubuntu-branches/ubuntu/maverick/mahara/maverick-updates

« back to all changes in this revision

Viewing changes to htdocs/artefact/internal/blocktype/contactinfo/lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Nigel McNie
  • Date: 2008-04-29 11:15:39 UTC
  • Revision ID: james.westby@ubuntu.com-20080429111539-b28eqkagavaub2zr
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * @package    mahara
 
20
 * @subpackage blocktype-contactinfo
 
21
 * @author     Catalyst IT Ltd
 
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 
24
 *
 
25
 */
 
26
 
 
27
defined('INTERNAL') || die();
 
28
 
 
29
class PluginBlocktypeContactinfo extends PluginBlocktype {
 
30
 
 
31
    public static function get_title() {
 
32
        return get_string('title', 'blocktype.internal/contactinfo');
 
33
    }
 
34
 
 
35
    public static function get_description() {
 
36
        return get_string('description', 'blocktype.internal/contactinfo');
 
37
    }
 
38
 
 
39
    public static function get_categories() {
 
40
        return array('internal');
 
41
    }
 
42
 
 
43
    public static function render_instance(BlockInstance $instance) {
 
44
        require_once(get_config('docroot') . 'artefact/lib.php');
 
45
        $smarty = smarty_core();
 
46
        $configdata = $instance->get('configdata');
 
47
 
 
48
        $data = array();
 
49
 
 
50
        // add in the selected email address
 
51
        if (!empty($configdata['email'])) {
 
52
            $configdata['artefactids'][] = $configdata['email'];
 
53
        }
 
54
 
 
55
        // Get data about the profile fields in this blockinstance
 
56
        if (!empty($configdata['artefactids'])) {
 
57
            $artefactids = implode(', ', array_map('db_quote', $configdata['artefactids']));
 
58
            $profiledata = get_records_select_array('artefact',
 
59
                'id IN (' . $artefactids . ') AND owner = (SELECT owner FROM {view} WHERE id = ?)',
 
60
                array($instance->get('view')),
 
61
                '',
 
62
                'artefacttype, title'
 
63
            );
 
64
 
 
65
            foreach ($profiledata as $profilefield) {
 
66
                $data[$profilefield->artefacttype] = $profilefield->title;
 
67
            }
 
68
        }
 
69
 
 
70
        $smarty->assign('profileinfo', $data);
 
71
 
 
72
        return $smarty->fetch('blocktype:contactinfo:content.tpl');
 
73
    }
 
74
 
 
75
    public static function has_instance_config() {
 
76
        return true;
 
77
    }
 
78
 
 
79
    public static function instance_config_form($instance) {
 
80
        $configdata = $instance->get('configdata');
 
81
 
 
82
        $form = array();
 
83
 
 
84
        // email addresses
 
85
        $result = get_records_sql_array('SELECT a.id, a.title, a.note
 
86
            FROM {artefact} a
 
87
            WHERE artefacttype = \'email\'
 
88
            AND a.owner = (
 
89
                SELECT owner
 
90
                FROM {view}
 
91
                WHERE id = ?
 
92
            )
 
93
            ORDER BY a.id', array($instance->get('view')));
 
94
 
 
95
        $options = array(
 
96
            0 => get_string('dontshowemail', 'blocktype.internal/contactinfo'),
 
97
        );
 
98
 
 
99
        foreach ($result as $email) {
 
100
            $options[$email->id] = $email->title;
 
101
        }
 
102
 
 
103
        $form['email'] = array(
 
104
            'type'    => 'radio',
 
105
            'title'   => get_string('email', 'artefact.internal'),
 
106
            'options' => $options,
 
107
            'defaultvalue' => (isset($configdata['email'])) ? $configdata['email'] : 0,
 
108
            'separator' => HTML_BR,
 
109
        );
 
110
 
 
111
        // Which fields does the user want
 
112
        $form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
 
113
 
 
114
        return $form;
 
115
    }
 
116
 
 
117
    // TODO: make decision on whether this should be abstract or not
 
118
    public static function artefactchooser_element($default=null) {
 
119
        safe_require('artefact', 'internal');
 
120
        return array(
 
121
            'name'  => 'artefactids',
 
122
            'type'  => 'artefactchooser',
 
123
            'title' => get_string('fieldstoshow', 'blocktype.internal/contactinfo'),
 
124
            'defaultvalue' => $default,
 
125
            'blocktype' => 'contactinfo',
 
126
            'limit'     => 655360, // 640K profile fields is enough for anyone!
 
127
            'selectone' => false,
 
128
            'search'    => false,
 
129
            'artefacttypes' => array_diff(PluginArtefactInternal::get_contactinfo_artefact_types(), array('email')),
 
130
            'template'  => 'artefact:internal:artefactchooser-element.tpl',
 
131
        );
 
132
    }
 
133
 
 
134
    /**
 
135
     * Deliberately enforce _no_ sort order. The database will return them in 
 
136
     * the order they were inserted, which means roughly the order that they 
 
137
     * are listed in the profile screen
 
138
     */
 
139
    public static function artefactchooser_get_sort_order() {
 
140
        return '';
 
141
    }
 
142
}
 
143
 
 
144
?>