3
* Mahara: Electronic portfolio, weblog, resume builder and social networking
4
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
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.
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.
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/>.
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
27
defined('INTERNAL') || die();
29
class PluginBlocktypeContactinfo extends PluginBlocktype {
31
public static function get_title() {
32
return get_string('title', 'blocktype.internal/contactinfo');
35
public static function get_description() {
36
return get_string('description', 'blocktype.internal/contactinfo');
39
public static function get_categories() {
40
return array('internal');
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');
50
// add in the selected email address
51
if (!empty($configdata['email'])) {
52
$configdata['artefactids'][] = $configdata['email'];
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')),
65
foreach ($profiledata as $profilefield) {
66
$data[$profilefield->artefacttype] = $profilefield->title;
70
$smarty->assign('profileinfo', $data);
72
return $smarty->fetch('blocktype:contactinfo:content.tpl');
75
public static function has_instance_config() {
79
public static function instance_config_form($instance) {
80
$configdata = $instance->get('configdata');
85
$result = get_records_sql_array('SELECT a.id, a.title, a.note
87
WHERE artefacttype = \'email\'
93
ORDER BY a.id', array($instance->get('view')));
96
0 => get_string('dontshowemail', 'blocktype.internal/contactinfo'),
99
foreach ($result as $email) {
100
$options[$email->id] = $email->title;
103
$form['email'] = array(
105
'title' => get_string('email', 'artefact.internal'),
106
'options' => $options,
107
'defaultvalue' => (isset($configdata['email'])) ? $configdata['email'] : 0,
108
'separator' => HTML_BR,
111
// Which fields does the user want
112
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
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');
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,
129
'artefacttypes' => array_diff(PluginArtefactInternal::get_contactinfo_artefact_types(), array('email')),
130
'template' => 'artefact:internal:artefactchooser-element.tpl',
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
139
public static function artefactchooser_get_sort_order() {