Commit b5c9e316 authored by Jono Mingard's avatar Jono Mingard
Browse files

Removed Contact info blocktype (Bug #892684)



Since the data storage format is virtually identical for Contact information
and Profile information, all Contact info blocks can easily be changed to
Profile info ones

Change-Id: I4844630745c2d12d06a76b70ad7fd624342833eb
Signed-off-by: default avatarJono Mingard <jonom@catalyst.net.nz>
parent 3a190471
<?php
/**
*
* @package mahara
* @subpackage blocktype-contactinfo
* @author Catalyst IT Ltd
* @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.
*
*/
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
/**
*
* @package mahara
* @subpackage blocktype-contactinfo
* @author Catalyst IT Ltd
* @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.
*
*/
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, $editing=false) {
require_once(get_config('docroot') . 'artefact/lib.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'])) {
$viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
foreach ($configdata['artefactids'] as $id) {
try {
$artefact = artefact_instance_from_id($id);
if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) {
$rendered = $artefact->render_self(array('link' => true));
$data[$artefact->get('artefacttype')] = $rendered['html'];
}
}
catch (ArtefactNotFoundException $e) {
log_debug('Artefact not found when rendering contactinfo block instance. '
. 'There might be a bug with deleting artefacts of this type? '
. 'Original error follows:');
log_debug($e->getMessage());
}
}
}
$smarty->assign('profileinfo', $data);
return $smarty->fetch('blocktype:contactinfo:content.tpl');
}
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' => '<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,
'search' => 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 '';
}
public static function rewrite_blockinstance_config(View $view, $configdata) {
if ($view->get('owner') !== null) {
$artefacttypes = array_diff(PluginArtefactInternal::get_contactinfo_artefact_types(), array('email'));
$artefactids = get_column_sql('
SELECT a.id FROM {artefact} a
WHERE a.owner = ? AND a.artefacttype IN (' . join(',', array_map('db_quote', $artefacttypes)) . ')', array($view->get('owner')));
$configdata['artefactids'] = $artefactids;
if (isset($configdata['email'])) {
if ($newemail = get_field('artefact_internal_profile_email', 'artefact', 'principal', 1, 'owner', $view->get('owner'))) {
$configdata['email'] = $newemail;
}
else {
unset($configdata['email']);
}
}
}
else {
$configdata['artefactids'] = array();
}
return $configdata;
}
public static function default_copy_type() {
return 'shallow';
}
/**
* Contactinfo blocktype is only allowed in personal views, because
* there's no such thing as group/site profiles
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
}
/**
* Overrides the default implementation so we can export enough information
* to reconstitute profile information again.
*
* Leap2A export doesn't export profile related artefacts as entries, so we
* need to take that into account when exporting config for it.
*/
public static function export_blockinstance_config_leap(BlockInstance $bi) {
return PluginArtefactInternal::export_blockinstance_config_leap($bi);
}
/**
* Sister method to export_blockinstance_config_leap (creates block
* instance based of what that method exports)
*/
public static function import_create_blockinstance_leap(array $biconfig, array $viewconfig) {
return PluginArtefactInternal::import_create_blockinstance_leap($biconfig, $viewconfig);
}
}
<ul>
{foreach from=$profileinfo key=key item=item}
<li><strong>{str tag=$key section=artefact.internal}:</strong> {$item|clean_html|safe}</li>
{/foreach}
</ul>
\ No newline at end of file
<?php
/**
*
* @package mahara
* @subpackage blocktype-contactinfo
* @author Catalyst IT Ltd
* @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.
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008040200;
$config->release = '1.0.0';
......@@ -26,5 +26,13 @@ function xmldb_artefact_internal_upgrade($oldversion=0) {
execute_sql("DROP TABLE {artefact_internal_profile_icon}");
}
if ($oldversion < 2014022700) {
// Remove the unnecessary Contact information block and change all current instances to Profile information
execute_sql("UPDATE {block_instance} SET blocktype='profileinfo' WHERE blocktype='contactinfo'");
execute_sql("DELETE FROM {blocktype_installed_viewtype} WHERE blocktype='contactinfo'");
execute_sql("DELETE FROM {blocktype_installed_category} WHERE blocktype='contactinfo'");
execute_sql("DELETE FROM {blocktype_installed} WHERE name='contactinfo'");
}
return $status;
}
......@@ -12,5 +12,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011071200;
$config->version = 2014022700;
$config->release = '1.1.0';
......@@ -3155,5 +3155,11 @@ function xmldb_core_upgrade($oldversion=0) {
drop_field($table, $field);
}
if ($oldversion < 2014022700) {
if ($data = check_upgrades('artefact.internal')) {
upgrade_plugin($data);
}
}
return $status;
}
......@@ -15,7 +15,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014022600;
$config->version = 2014022700;
$config->release = '1.9.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
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