Commit 893d08bc authored by Nigel McNie's avatar Nigel McNie
Browse files
parents 80b8e009 5eb5f690
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype-contactinfo
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$string['title'] = 'Contact Information';
$string['description'] = 'Choose contact information to display';
$string['dontshowemail'] = 'Don\'t show email address';
$string['fieldstoshow'] = 'Fields to show';
?>
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype-contactinfo
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeContactinfo extends PluginBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.internal/contactinfo');
}
public static function get_description() {
return get_string('description', 'blocktype.internal/contactinfo');
}
public static function get_categories() {
return array('internal');
}
public static function render_instance(BlockInstance $instance) {
require_once(get_config('docroot') . 'lib/artefact.php');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
$data = array();
// add in the selected email address
if (!empty($configdata['email'])) {
$configdata['artefactids'][] = $configdata['email'];
}
// Get data about the profile fields in this blockinstance
if (!empty($configdata['artefactids'])) {
$artefactids = implode(', ', array_map('db_quote', $configdata['artefactids']));
$profiledata = get_records_select_array('artefact',
'id IN (' . $artefactids . ') AND owner = (SELECT owner FROM {view} WHERE id = ?)',
array($instance->get('view')),
'',
'artefacttype, title'
);
foreach ($profiledata as $profilefield) {
$data[$profilefield->artefacttype] = $profilefield->title;
}
}
$smarty->assign('profileinfo', $data);
return $smarty->fetch('blocktype:contactinfo:content.tpl');
}
public static function get_artefacts(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$return = false;
if (isset($configdata['artefactids'])) {
$return = $configdata['artefactids'];
}
return $return;
}
public static function has_instance_config() {
return true;
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
$form = array();
// email addresses
$result = get_records_sql_array('SELECT a.id, a.title, a.note
FROM {artefact} a
WHERE artefacttype = \'email\'
AND a.owner = (
SELECT owner
FROM {view}
WHERE id = ?
)
ORDER BY a.id', array($instance->get('view')));
$options = array(
0 => get_string('dontshowemail', 'blocktype.internal/contactinfo'),
);
foreach ($result as $email) {
$options[$email->id] = $email->title;
}
$form['email'] = array(
'type' => 'radio',
'title' => get_string('email', 'artefact.internal'),
'options' => $options,
'defaultvalue' => (isset($configdata['email'])) ? $configdata['email'] : 0,
'separator' => HTML_BR,
);
// Which fields does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
return $form;
}
// TODO: make decision on whether this should be abstract or not
public static function artefactchooser_element($default=null) {
safe_require('artefact', 'internal');
return array(
'name' => 'artefactids',
'type' => 'artefactchooser',
'title' => get_string('fieldstoshow', 'blocktype.internal/contactinfo'),
'defaultvalue' => $default,
'blocktype' => 'contactinfo',
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => false,
'artefacttypes' => array_diff(PluginArtefactInternal::get_contactinfo_artefact_types(), array('email')),
'template' => 'artefact:internal:artefactchooser-element.tpl',
);
}
/**
* Deliberately enforce _no_ sort order. The database will return them in
* the order they were inserted, which means roughly the order that they
* are listed in the profile screen
*/
public static function artefactchooser_get_sort_order() {
return '';
}
}
?>
<ul>
{foreach from=$profileinfo key=key item=item}
<li><strong>{str tag=$key section=artefact.internal}:</strong>
{if $key == 'email'}
<a href="mailto:{$item|escape}">{$item|escape}</a>
{elseif $key == 'country'}
{str tag=country.$item}
{elseif in_array($key, array('officialwebsite', 'personalwebsite', 'blogaddress'))}
<a href="{$item|escape}">{$item|str_shorten:50}</a>
{else}
{$item|escape}
{/if}</li>
{/foreach}
</ul>
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype-contactinfo
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2007110200;
$config->release = '0.9';
?>
......@@ -34,5 +34,6 @@ $string['fieldstoshow'] = 'Fields to show';
$string['introtext'] = 'Introduction Text';
$string['useintroductioninstead'] = 'You can use your introduction profile field instead by enabling that and leaving this field blank';
$string['dontshowprofileicon'] = "Don't show a profile icon";
$string['dontshowemail'] = "Don't show email address";
?>
......@@ -47,6 +47,11 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
$data = array();
// add in the selected email address
if (!empty($configdata['email'])) {
$configdata['artefactids'][] = $configdata['email'];
}
// Get data about the profile fields in this blockinstance
if (!empty($configdata['artefactids'])) {
$artefactids = implode(', ', array_map('db_quote', $configdata['artefactids']));
......@@ -106,31 +111,49 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
// Profile icon
$result = get_records_sql_array('SELECT a.id, a.title, a.note
if (!$result = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.note
FROM {artefact} a
WHERE artefacttype = \'profileicon\'
WHERE artefacttype = \'profileicon\' OR artefacttype = \'email\'
AND a.owner = (
SELECT owner
FROM {view}
WHERE id = ?
)
ORDER BY a.id', array($instance->get('view')));
ORDER BY a.id', array($instance->get('view')))) {
$result = array();
}
$options = array(
$iconoptions = array(
0 => get_string('dontshowprofileicon', 'blocktype.internal/profileinfo'),
);
foreach ($result as $profileicon) {
$options[$profileicon->id] = ($profileicon->title) ? $profileicon->title : $profileicon->note;
$emailoptions = array(
0 => get_string('dontshowemail', 'blocktype.internal/profileinfo'),
);
foreach ($result as $profilefield) {
if ($profilefield->artefacttype == 'profileicon') {
$iconoptions[$profilefield->id] = ($profilefield->title) ? $profilefield->title : $profilefield->note;
}
else {
$emailoptions[$profilefield->id] = $profilefield->title;
}
}
$form['profileicon'] = array(
'type' => 'radio',
'title' => get_string('profileicon', 'artefact.internal'),
'options' => $options,
'options' => $iconoptions,
'defaultvalue' => (isset($configdata['profileicon'])) ? $configdata['profileicon'] : 0,
'separator' => HTML_BR,
);
$form['email'] = array(
'type' => 'radio',
'title' => get_string('email', 'artefact.internal'),
'options' => $emailoptions,
'defaultvalue' => (isset($configdata['email'])) ? $configdata['email'] : 0,
'separator' => HTML_BR,
);
// Introduction
$form['introtext'] = array(
'type' => 'tinywysiwyg',
......@@ -155,7 +178,7 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
'blocktype' => 'profileinfo',
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => false,
'artefacttypes' => array_diff(PluginArtefactInternal::get_artefact_types(), array('profileicon')),
'artefacttypes' => array_diff(PluginArtefactInternal::get_artefact_types(), array('profileicon', 'email')),
'template' => 'artefact:internal:artefactchooser-element.tpl',
);
}
......
......@@ -58,6 +58,29 @@ class PluginArtefactInternal extends PluginArtefact {
'profileicon'
);
}
public static function get_contactinfo_artefact_types() {
return array(
'email',
'officialwebsite',
'personalwebsite',
'blogaddress',
'address',
'town',
'city',
'country',
'homenumber',
'businessnumber',
'mobilenumber',
'faxnumber',
'icqnumber',
'msnnumber',
'aimscreenname',
'yahoochat',
'skypeusername',
'jabberusername',
);
}
public static function get_block_types() {
return array();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment