Commit 86cb3d29 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1783042: Allowing some portfolio only blocks to be added to other pages



And handle how we configure / render them when not on normal portfolio
page

Change-Id: Ib5407a32b52edd0df4ecc2907f8a5c9455f7aa64
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 9614ed8b
......@@ -2553,8 +2553,8 @@ class ArtefactTypeProfileIcon extends ArtefactTypeImage {
}
// No profile icon file selected. Go through fallback icons.
// Look for an appropriate image on gravatar.com
$useremail = !empty($data) ? $data->email : false;
// Look for an appropriate image on gravatar.com if not 'root' user
$useremail = (!empty($data) && $userid !== 0) ? $data->email : false;
if ($useremail and $gravatarurl = remote_avatar_url($useremail, $size)) {
redirect($gravatarurl);
}
......
......@@ -21,6 +21,6 @@ $string['useintroductioninstead'] = 'You can use your introduction profile field
$string['dontshowprofileicon'] = "Don't show a profile picture";
$string['dontshowemail'] = "Don't show email address";
$string['uploadaprofileicon'] = "You have no profile pictures. <a href=\"%sartefact/file/profileicons.php\">Upload one</a>.";
$string['noprofilesselectone'] = "No profile items selected";
$string['dontshowsocialprofiles'] = "Don't show social media accounts";
$string['showsocialprofiles'] = "Show selected social media accounts";
......@@ -30,11 +30,12 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
require_once(get_config('docroot') . 'artefact/lib.php');
safe_require('artefact', 'internal');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
$data = array();
$data['internalprofiles'] = array();
$data['socialprofiles'] = array();
// add in the selected email address
......@@ -43,7 +44,7 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
}
$viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
$sortorder = array_keys(ArtefactTypeProfile::get_all_fields());
// Get data about the profile fields in this blockinstance
if (!empty($configdata['artefactids'])) {
foreach ($configdata['artefactids'] as $id) {
......@@ -65,7 +66,16 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
}
}
else {
$data[$artefacttype] = $rendered['html'];
if ($artefacttype == 'introduction') {
$data['introduction'] = $rendered['html'];
}
else {
$data['internalprofiles'][] = array(
'type' => $artefacttype,
'description' => $rendered['html'],
'order' => array_search($artefacttype, $sortorder),
);
}
}
}
}
......@@ -76,6 +86,12 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
log_debug($e->getMessage());
}
}
// Sort internal profiles by how they display on Content -> Profile page
$orders = array();
foreach ($data['internalprofiles'] as $key => $row) {
$orders[$key] = $row['order'];
}
array_multisort($orders, SORT_ASC, $data['internalprofiles']);
// Sort social profiles alphabetically (in ASC order)
$description = array();
foreach ($data['socialprofiles'] as $key => $row) {
......@@ -83,15 +99,39 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
}
array_multisort($description, SORT_ASC, $data['socialprofiles']);
}
else if ($editing && !empty($configdata['templateids'])) {
foreach ($configdata['templateids'] as $artefacttype) {
$data['internalprofiles'][] = array(
'type' => $artefacttype,
'description' => '',
'order' => array_search($artefacttype, $sortorder),
);
}
// Sort internal profiles by how they display on Content -> Profile page
$orders = array();
foreach ($data['internalprofiles'] as $key => $row) {
$orders[$key] = $row['order'];
}
array_multisort($orders, SORT_ASC, $data['internalprofiles']);
}
else if ($editing) {
$data['nodata'] = get_string('noprofilesselectone', 'blocktype.internal/profileinfo');
}
// Work out the path to the thumbnail for the profile image
if (!empty($configdata['profileicon'])) {
$downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon'] . '&view=' . $instance->get('view');
$downloadpath .= '&maxwidth=80';
$smarty->assign('profileiconpath', $downloadpath);
$smarty->assign('profileiconalt', get_string('profileimagetext', 'mahara', display_default_name(get_user($viewowner))));
if (!empty($configdata['templateids'])) {
$downloadpath = get_config('wwwroot') . 'thumb.php?type=profileicon&id=0';
$smarty->assign('profileiconpath', $downloadpath);
$smarty->assign('profileiconalt', get_string('profileimagetexttemplate', 'mahara'));
}
else {
$downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon'] . '&view=' . $instance->get('view');
$downloadpath .= '&maxwidth=80';
$smarty->assign('profileiconpath', $downloadpath);
$smarty->assign('profileiconalt', get_string('profileimagetext', 'mahara', display_default_name(get_user($viewowner))));
}
}
// Override the introduction text if the user has any for this
// particular blockinstance
if (!empty($configdata['introtext'])) {
......@@ -132,66 +172,93 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
$configdata = $instance->get('configdata');
$form = array();
// Which fields does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
// Profile icon
if (!$result = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.note
FROM {artefact} a
WHERE (artefacttype = \'profileicon\' OR artefacttype = \'email\')
AND a.owner = (
SELECT "owner"
FROM {view}
WHERE id = ?
)
ORDER BY a.id', array($instance->get('view')))) {
$result = array();
$owner = $instance->get_view()->get('owner');
if (!$owner) {
$configdata['artefactids'] = array();
if (isset($configdata['templateids']) && !empty($configdata['templateids'])) {
$element = self::artefactchooser_element(null, $owner);
foreach ($element['artefacttypes'] as $key => $type) {
if (array_search($type, $configdata['templateids']) !== false) {
$configdata['artefactids'][] = $key;
}
}
$configdata['templateids'] = array();
}
$form['blocktemplatehtml'] = array(
'type' => 'html',
'value' => get_string('blockinstanceconfigownerchange', 'mahara'),
);
}
// Which fields does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null, $owner);
if ($owner) {
// Profile icon
if (!$result = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.note
FROM {artefact} a
WHERE (artefacttype = \'profileicon\' OR artefacttype = \'email\')
AND a.owner = (
SELECT "owner"
FROM {view}
WHERE id = ?
)
ORDER BY a.id', array($instance->get('view')))) {
$result = array();
}
$iconoptions = array(
0 => get_string('dontshowprofileicon', 'blocktype.internal/profileinfo'),
);
$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;
$iconoptions = array(
0 => get_string('dontshowprofileicon', 'blocktype.internal/profileinfo'),
);
$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;
}
}
if (count($iconoptions) == 1) {
$form['noprofileicon'] = array(
'type' => 'html',
'title' => get_string('profileicon', 'artefact.file'),
'description' => get_string('uploadaprofileicon', 'blocktype.internal/profileinfo', get_config('wwwroot')),
'value' => '',
);
$form['profileicon'] = array(
'type' => 'hidden',
'value' => 0,
);
}
else {
$emailoptions[$profilefield->id] = $profilefield->title;
$form['profileicon'] = array(
'type' => 'radio',
'title' => get_string('profileicon', 'artefact.file'),
'options' => $iconoptions,
'defaultvalue' => (isset($configdata['profileicon'])) ? $configdata['profileicon'] : 0,
);
}
}
if (count($iconoptions) == 1) {
$form['noprofileicon'] = array(
'type' => 'html',
'title' => get_string('profileicon', 'artefact.file'),
'description' => get_string('uploadaprofileicon', 'blocktype.internal/profileinfo', get_config('wwwroot')),
'value' => '',
);
$form['profileicon'] = array(
'type' => 'hidden',
'value' => 0,
$form['email'] = array(
'type' => 'radio',
'title' => get_string('email', 'artefact.internal'),
'options' => $emailoptions,
'defaultvalue' => (isset($configdata['email'])) ? $configdata['email'] : 0,
);
}
else {
$form['profileicon'] = array(
'type' => 'radio',
'title' => get_string('profileicon', 'artefact.file'),
'options' => $iconoptions,
'defaultvalue' => (isset($configdata['profileicon'])) ? $configdata['profileicon'] : 0,
'title' => get_string('profileicon', 'artefact.file'),
'type' => 'switchbox',
'defaultvalue' => (isset($configdata['profileicon'])) ? boolval($configdata['profileicon']) : 0,
);
$form['blocktemplate'] = array(
'type' => 'hidden',
'value' => 1,
);
}
$form['email'] = array(
'type' => 'radio',
'title' => get_string('email', 'artefact.internal'),
'options' => $emailoptions,
'defaultvalue' => (isset($configdata['email'])) ? $configdata['email'] : 0,
);
// Introduction
$form['introtext'] = array(
'type' => 'wysiwyg',
......@@ -215,6 +282,19 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
else {
EmbeddedImage::delete_embedded_images('introtext', $instance->get('id'));
}
if (isset($values['blocktemplate']) && !empty($values['blocktemplate'])) {
// Need to adjust info to be a template
$owner = $instance->get_view()->get('owner');
$values['templateids'] = array();
$element = self::artefactchooser_element(null, $owner);
foreach ($element['artefacttypes'] as $key => $type) {
if (array_search($key, $values['artefactids']) !== false) {
$values['templateids'][] = $type;
}
}
$values['artefactids'] = array();
}
return $values;
}
......@@ -223,9 +303,13 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
EmbeddedImage::delete_embedded_images('introtext', $instance->get('id'));
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $owner=true) {
safe_require('artefact', 'internal');
$artefacttypes = array_diff(PluginArtefactInternal::get_profile_artefact_types(), array('email'));
$artefacttypes = PluginArtefactInternal::get_profile_artefact_types();
if ($owner) {
$artefacttypes = array_diff($artefacttypes, array('email'));
}
if (!get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile')) {
$artefacttypes = array_diff($artefacttypes, array('socialprofile'));
}
......@@ -236,6 +320,7 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
'title' => get_string('fieldstoshow', 'blocktype.internal/profileinfo'),
'defaultvalue' => $default,
'blocktype' => 'profileinfo',
'blocktemplate' => empty($owner),
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => false,
'search' => false,
......@@ -281,9 +366,29 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
if (!get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile')) {
$artefacttypes = array_diff($artefacttypes, array('socialprofile'));
}
$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')));
if (!empty($configdata['blocktemplate'])) {
if (!empty($configdata['templateids'])) {
$artefactids = get_column_sql('
SELECT a.id FROM {artefact} a
WHERE a.owner = ? AND a.artefacttype != ? AND a.artefacttype IN (' . join(',', array_map('db_quote', $configdata['templateids'])) . ')', array($view->get('owner'), 'email'));
if (in_array('email', $configdata['templateids'])) {
if ($newemail = get_field('artefact_internal_profile_email', 'artefact', 'principal', 1, 'owner', $view->get('owner'))) {
$configdata['email'] = $newemail;
}
}
}
else {
$artefactids = array();
}
unset($configdata['blocktemplatehtml']);
unset($configdata['templateids']);
unset($configdata['blocktemplate']);
}
else {
$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'))) {
......@@ -317,7 +422,7 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
* there's no such thing as group/site profiles
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
return true;
}
/**
......
......@@ -23,3 +23,4 @@ $string['optiontexticon'] = 'buttons with icons and text';
$string['optiontextonly'] = 'buttons with text only';
$string['displaydefaultemail'] = 'Display default email link as button?';
$string['displaymsgservices'] = 'Display messaging services as buttons?';
$string['noitemsselectone'] = 'No social media selected';
......@@ -32,35 +32,46 @@ class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
$type = (isset($configdata['displaytype']) ? $configdata['displaytype'] : 'texticon');
$showicon = ($type == 'icononly' || $type == 'texticon' ? true : false);
$showtext = ($type == 'textonly' || $type == 'texticon' ? true : false);
$owner = $instance->get('view_obj')->get('owner');
$owner = $instance->get_view()->get('owner');
// Whether to include email button
if (isset($configdata['displayemail']) && $configdata['displayemail']) {
if (isset($configdata['displayemail']) && $configdata['displayemail'] && $owner) {
$email = get_field('artefact_internal_profile_email', 'email', 'principal', 1, 'owner', $owner);
}
else if (isset($configdata['displayemail']) && $configdata['displayemail']) {
$email = true;
}
else {
$email = false;
}
if (!isset($configdata['artefactids']) || empty($configdata['artefactids'])) {
// When we first come into this block, it will have
// no social profiles configured yet.
$configdata['artefactids'] = array(0);
$data = array();
$smarty = smarty_core();
if (isset($configdata['artefactids']) && !empty($configdata['artefactids'])) {
// Include selected social profiles
$sql = 'SELECT title, description, note FROM {artefact}
WHERE id IN (' . join(',', $configdata['artefactids']) . ')
AND owner = ? AND artefacttype = ?
ORDER BY description ASC';
$artefactdata = get_records_sql_array($sql, array($owner, 'socialprofile'));
$data = !empty($artefactdata) ? $artefactdata : $data;
}
// Include selected social profiles
$sql = 'SELECT title, description, note FROM {artefact}
WHERE id IN (' . join(',', $configdata['artefactids']) . ')
AND owner = ? AND artefacttype = ?
ORDER BY description ASC';
if (!$data = get_records_sql_array($sql, array($owner, 'socialprofile'))) {
$data = array();
else if ($editing && !empty($configdata['templateids'])) {
foreach ($configdata['templateids'] as $socialtype) {
$stype = new stdClass();
$stype->title = '';
$stype->description = get_string($socialtype, 'artefact.internal');
$stype->note = $socialtype;
$data[] = $stype;
}
}
else if ($editing && !$email) {
$smarty->assign('editing', $editing);
$smarty->assign('noitems', get_string('noitemsselectone', 'blocktype.internal/socialprofile'));
}
safe_require('artefact', 'internal');
$data = ArtefactTypeSocialprofile::get_profile_icons($data);
$smarty = smarty_core();
$smarty->assign('showicon', $showicon);
$smarty->assign('showtext', $showtext);
$smarty->assign('profiles', $data);
......@@ -75,11 +86,30 @@ class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
public static function instance_config_form(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$owner = $instance->get_view()->get('owner');
$form = array();
if (!$owner) {
$configdata['artefactids'] = array();
if (isset($configdata['templateids']) && !empty($configdata['templateids'])) {
$element = self::artefactchooser_element(null, $owner);
foreach ($element['artefacttypes'] as $key => $type) {
if (array_search($type, $configdata['templateids']) !== false) {
$configdata['artefactids'][] = $key;
}
}
$configdata['templateids'] = array();
}
$form['blocktemplatehtml'] = array(
'type' => 'html',
'value' => get_string('blockinstanceconfigownerchange', 'mahara'),
);
$form['blocktemplate'] = array(
'type' => 'hidden',
'value' => 1,
);
}
// Which social profiles does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null, $owner);
$form['settings'] = array(
'type' => 'fieldset',
......@@ -109,22 +139,68 @@ class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
return $form;
}
public static function artefactchooser_element($default=null) {
public static function instance_config_save($values, $instance) {
if (isset($values['blocktemplate']) && !empty($values['blocktemplate'])) {
// Need to adjust info to be a template
$owner = $instance->get_view()->get('owner');
$values['templateids'] = array();
$element = self::artefactchooser_element(null, $owner);
foreach ($element['artefacttypes'] as $key => $type) {
if (array_search($key, $values['artefactids']) !== false) {
$values['templateids'][] = $type;
}
}
$values['artefactids'] = array();
}
return $values;
}
public static function artefactchooser_element($default=null, $owner=true) {
safe_require('artefact', 'internal');
if (!$owner) {
$artefacttypes = ArtefactTypeSocialprofile::$socialnetworks;
}
else {
$artefacttypes = array('socialprofile');
}
return array(
'name' => 'artefactids',
'type' => 'artefactchooser',
'title' => get_string('profilestoshow', 'blocktype.internal/socialprofile'),
'defaultvalue' => $default,
'blocktype' => 'socialprofile',
'blocktemplate' => empty($owner),
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => false,
'search' => false,
'artefacttypes' => array('socialprofile'),
'artefacttypes' => $artefacttypes,
'template' => 'artefact:internal:artefactchooser-element.tpl',
);
}
public static function rewrite_blockinstance_config(View $view, $configdata) {
safe_require('artefact', 'internal');
$configdata['artefactids'] = array();
if ($view->get('owner') !== null) {
if (!empty($configdata['blocktemplate'])) {
if (!empty($configdata['templateids'])) {
$artefactids = get_column_sql('
SELECT a.id FROM {artefact} a
WHERE a.owner = ? AND a.artefacttype = ? AND a.note IN (' . join(',', array_map('db_quote', $configdata['templateids'])) . ')', array($view->get('owner'), 'socialprofile'));
}
else {
$artefactids = array();
}
unset($configdata['blocktemplatehtml']);
unset($configdata['templateids']);
unset($configdata['blocktemplate']);
$configdata['artefactids'] = $artefactids;
}
}
return $configdata;
}
public static function default_copy_type() {
return 'shallow';
}
......@@ -138,7 +214,7 @@ class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
* given view.
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
return true;
}
/**
......
......@@ -15,7 +15,7 @@ $string['title'] = 'Plans';
$string['description1'] = 'Display a plan (see Content -> Plans)';
$string['defaulttitledescription'] = 'If this is left empty, the title of the plan will be used.';
$string['newerplans'] = 'Newer plans';
$string['noplansaddone'] = 'No plans yet. %sAdd one%s!';
$string['noplansselectone'] = 'No plans selected';
$string['olderplans'] = 'Older plans';
$string['planstoshow'] = 'Plan to show';
$string['taskstodisplay'] = 'Tasks to display';
\ No newline at end of file
......@@ -111,7 +111,8 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
$smarty->assign('alltasks', $alltasks);
}
else {
$smarty->assign('noplans','blocktype.plans/plans');
$smarty->assign('editing', $editing);
$smarty->assign('noplans', get_string('noplansselectone', 'blocktype.plans/plans'));
}
$smarty->assign('blockid', $instance->get('id'));
return $smarty->fetch('blocktype:plans:content.tpl');
......@@ -125,17 +126,28 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
public static function instance_config_form(BlockInstance $instance) {
$instance->set('artefactplugin', 'plans');
$configdata = $instance->get('configdata');
$owner = $instance->get_view()->get('owner');
$form = array();
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
$form['count'] = array(
'type' => 'text',
'title' => get_string('taskstodisplay', 'blocktype.plans/plans'),
'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 10,
'size' => 3,
);
if ($owner) {
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
$form['count'] = array(
'type' => 'text',
'title' => get_string('taskstodisplay', 'blocktype.plans/plans'),
'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 10,
'size' => 3,
);
}
else {
$form['blocktemplatehtml'] = array(
'type' => 'html',
'value' => get_string(