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

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";
......@@ -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('blockinstanceconfigownerchange', 'mahara'),
);
$form['blocktemplate'] = array(
'type' => 'hidden',
'value' => 1,
);
}
return $form;
}
......@@ -156,6 +168,23 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
}
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
return true;
}
public static function rewrite_blockinstance_config(View $view, $configdata) {
safe_require('artefact', 'plans');
if ($view->get('owner') !== null && !empty($configdata['blocktemplate'])) {
if ($artefactids = get_column_sql('
SELECT a.id FROM {artefact} a
WHERE a.owner = ? AND a.artefacttype = ?', array($view->get('owner'), 'plan'))) {
$configdata['artefactids'] = $artefactids;
}
else {
$configdata['artefactids'] = array();
}
unset($configdata['blocktemplatehtml']);
unset($configdata['blocktemplate']);
}
return $configdata;
}
}
......@@ -15,5 +15,5 @@ $string['addresstag'] = 'Address: %s';
$string['address'] = 'Address';
$string['title'] = 'My entire résumé';
$string['description'] = 'A quick way to show your whole résumé';
$string['noresumeselectone'] = 'Résumé items will automatically display here';
$string['History'] = 'History';
......@@ -32,9 +32,7 @@ class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
public static function render_instance(BlockInstance $instance, $editing=false) {
require_once(get_config('docroot') . 'artefact/lib.php');
$smarty = smarty_core();
// Get data about the resume fields the user has
$return = '';
if ($artefacts = get_records_sql_array('
SELECT va.artefact, a.artefacttype
FROM {view_artefact} va
......@@ -51,6 +49,10 @@ class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
$smarty->assign($artefact->artefacttype, $result);
}
}
else {
$smarty->assign('editing', $editing);
$smarty->assign('noresume', get_string('noresumeselectone', 'blocktype.resume/entireresume'));
}
return $smarty->fetch('blocktype:entireresume:content.tpl');
}
......@@ -59,15 +61,28 @@ class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
}
public static function instance_config_form(BlockInstance $instance) {
$elements = array(
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescblock'),
'defaultvalue' => $instance->get('tags'),
'help' => false,
)
);
$owner = $instance->get_view()->get('owner');
if ($owner) {
$elements = array(
'tags' => array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescblock'),
'defaultvalue' => $instance->get('tags'),
'help' => false,
)
);
}
else {
$elements['blocktemplatehtml'] = array(
'type' => 'html',
'value' => get_string('blockinstanceconfigownerauto', 'mahara'),
);
$elements['blocktemplate'] = array(
'type' => 'hidden',
'value' => 1,
);
}
return $elements;
}
......@@ -121,6 +136,28 @@ class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
}
}
public static function get_artefacts(BlockInstance $instance) {
$configdata = $instance->get('configdata');
$return = array();
safe_require('artefact', 'resume');
$artefacttypes = implode(', ', array_map('db_quote', PluginArtefactResume::get_artefact_types()));
// Get all artefacts that are resume related and belong to the correct owner
if ($artefacts = get_records_sql_array('
SELECT id
FROM {artefact}
WHERE artefacttype IN(' . $artefacttypes . ')
AND "owner" = (
SELECT "owner"
FROM {view}
WHERE id = ?
)', array($instance->get('view')))) {
foreach ($artefacts as $artefact) {
$return[] = $artefact->id;
}
}
return $return;
}
public static function default_copy_type() {
return 'shallow';
}
......@@ -130,7 +167,7 @@ class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
* there's no such thing as group/site resumes
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
return true;
}
}
......@@ -16,5 +16,5 @@ $string['description'] = 'Display any résumé information';
$string['fieldtoshow'] = 'Field to show';
$string['filloutyourresume'] = '%sFill out your résumé%s in order to add more fields.';
$string['noresumeitemselectone'] = 'No résumé item selected';
$string['defaulttitledescription'] = 'If you leave this blank, the name of the field will be used.';
......@@ -43,7 +43,7 @@ class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
require_once(get_config('docroot') . 'artefact/lib.php');
safe_require('artefact', 'resume');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
$configdata['viewid'] = $instance->get('view');
......@@ -57,9 +57,16 @@ class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
$result .= '<script type="application/javascript">' . $rendered['javascript'] . '</script>';
}
$smarty->assign('content', $result);
return $smarty->fetch('blocktype:resumefield:content.tpl');;
}
return '';
else if ($editing && !empty($configdata['templateid'])) {
$result = '<p><strong>' . get_string($configdata['templateid'], 'artefact.resume') . '</strong></p>';
$smarty->assign('content', $result);
}
else {
$smarty->assign('editing', $editing);
$smarty->assign('nodata', get_string('noresumeitemselectone', 'blocktype.resume/resumefield'));
}
return $smarty->fetch('blocktype:resumefield:content.tpl');;
}
public static function has_instance_config() {
......@@ -70,30 +77,64 @@ class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
$configdata = $instance->get('configdata');
$form = array();
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);
$form['message'] = array(
'type' => 'html',
'value' => '<p class="alert alert-info">' . get_string('filloutyourresume', 'blocktype.resume/resumefield', '<a href="' . get_config('wwwroot') . 'artefact/resume/index.php">', '</a>') .'</p>',
);
$form['tags'] = array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescblock'),
'defaultvalue' => $instance->get('tags'),
'help' => false,
);
$owner = $instance->get_view()->get('owner');
if ($owner) {
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);
$form['message'] = array(
'type' => 'html',
'value' => '<p class="alert alert-info">' . get_string('filloutyourresume', 'blocktype.resume/resumefield', '<a href="' . get_config('wwwroot') . 'artefact/resume/index.php">', '</a>') .'</p>',
);
$form['tags'] = array(
'type' => 'tags',
'title' => get_string('tags'),
'description' => get_string('tagsdescblock'),
'defaultvalue' => $instance->get('tags'),
'help' => false,
);
}
else {
if (isset($configdata['templateid']) && !empty($configdata['templateid'])) {
safe_require('artefact', 'resume');
$types = PluginArtefactResume::get_artefact_types();
$configdata['artefactid'] = array_search($configdata['templateid'], $types);
unset($configdata['templateid']);
}
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $owner);
$form['blocktemplatehtml'] = array(
'type' => 'html',
'value' => get_string('blockinstanceconfigownerchange', 'mahara'),
);
$form['blocktemplate'] = array(
'type' => 'hidden',
'value' => 1,
);
}
return $form;
}
public static function instance_config_save($values) {
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['templateid'] = null;
$element = self::artefactchooser_element(null, $owner);
// Because the settings are radio we can treat empty response as picking the first option
if (!empty($element['artefacttypes'][$values['artefactid']])) {
$values['templateid'] = $element['artefacttypes'][$values['artefactid']];
}
else {
$values['templateid'] = $element['artefacttypes'][0];
}
unset($values['artefactid']);
}
unset($values['message']);
return $values;
}
// TODO: make decision on whether this should be abstract or not
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null,$owner=true) {
safe_require('artefact', 'resume');
return array(
'name' => 'artefactid',
......@@ -101,6 +142,7 @@ class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
'title' => get_string('fieldtoshow', 'blocktype.resume/resumefield'),
'defaultvalue' => $default,
'blocktype' => 'resumefield',
'blocktemplate' => empty($owner),
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => true,
'search' => false,
......@@ -118,16 +160,24 @@ class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
return '';
}
public static function rewrite_resume_config(View $view, $configdata) {
public static function rewrite_blockinstance_config(View $view, $configdata) {
$artefactid = null;
if ($view->get('owner') !== null) {
$artefacttype = null;
if (!empty($configdata['artefactid'])) {
if (!empty($configdata['blocktemplate'])) {
if (!empty($configdata['templateid'])) {
$artefacttype = $configdata['templateid'];
}
unset($configdata['blocktemplatehtml']);
unset($configdata['templateid']);
unset($configdata['blocktemplate']);
}
else if (!empty($configdata['artefactid'])) {
$artefacttype = get_field('artefact', 'artefacttype', 'id', $configdata['artefactid']);
}
// @todo get artefacttype from a different field when copying from institution or group view.
if ($artefacttype) {
$artefactid = get_field('artefact', 'id', 'artefacttype', $artefacttype, 'owner', $ownerid);
$artefactid = get_field('artefact', 'id', 'artefacttype', $artefacttype, 'owner', $view->get('owner'));
}
}
$configdata['artefactid'] = $artefactid;
......@@ -143,7 +193,7 @@ class PluginBlocktypeResumefield extends MaharaCoreBlocktype {
* there's no such thing as group/site resumes
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
return true;
}
/**
......
......@@ -836,12 +836,18 @@ class BlockInstance {
// make sure that user is allowed to publish artefact. This is to stop
// hacking of form value to attach other users private data.
$badattachment = false;
if (!empty($values['artefactid'])) {
$badattachment = !$this->verify_attachment_permissions($values['artefactid']);
if (isset($values['blocktemplate']) && !empty($values['blocktemplate'])) {
// Ignore check on artefactids as they are not relating to actual artefacts
}
if (!empty($values['artefactids'])) {
$badattachment = !$this->verify_attachment_permissions($values['artefactids']);
else {
if (!empty($values['artefactid'])) {
$badattachment = !$this->verify_attachment_permissions($values['artefactid']);
}
if (!empty($values['artefactids'])) {
$badattachment = !$this->verify_attachment_permissions($values['artefactids']);
}
}
if ($badattachment) {
$result['message'] = get_string('unrecoverableerror', 'error');
$form->set_error(null, $result['message']);
......
......@@ -56,7 +56,7 @@ $string['nbadges'] = array('1 badge', '%s badges');
$string['nobackpack'] = 'No Backpack found.<br> Please add your <a href="%s">Backpack</a> email address to your <a href="%s">profile</a>.';
$string['nobadgegroups'] = 'No public badge collections / badges found.';
$string['nobadgesselectone'] = 'No badges selected';
$string['nobackpackidin1'] = 'Your email %s is not found in the service %s.';
$string['nobadgegroupsin1'] = 'No public badge collections / badges found in the service %s for email %s.';
......
......@@ -113,7 +113,7 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
$html .= '<ul>' . implode('', array_map(function ($item) { return "<li>{$item}</li>"; }, $items)) . '</ul>';
}
else {
$html .= get_string('nobadgegroups', 'blocktype.openbadgedisplayer');
$html .= '<p class="editor-description">' . get_string('nobadgesselectone', 'blocktype.openbadgedisplayer') . '</p>';
}
return $html;
......@@ -253,7 +253,7 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
public static function instance_config_form(BlockInstance $instance) {
global $USER;
$owner = $instance->get_view()->get('owner');
$sources = self::get_backpack_source();
if ($sources === false) {
$fields = array(
......@@ -267,7 +267,10 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
}
$configdata = $instance->get('configdata');
$addresses = get_column('artefact_internal_profile_email', 'email', 'owner', $USER->id, 'verified', 1);
$addresses = array();
if ($owner) {
$addresses = get_column('artefact_internal_profile_email', 'email', 'owner', $USER->id, 'verified', 1);
}
$current_values = array();
if (isset($configdata['badgegroup'])) {
......@@ -294,14 +297,13 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
$sourcelinks[] = '<a href="' . $url . '">' . $title . '</a>';
}
}
$fields = array(
'message' => array(
'type' => 'html',
'class' => '',
'value' => '<p class="message">'. get_string('confighelp', 'blocktype.openbadgedisplayer', implode(', ', $sourcelinks)) .'</p>'
),
'badgegroups' => array(
$fields['message'] = array(
'type' => 'html',
'class' => '',
'value' => '<p class="message">'. get_string('confighelp', 'blocktype.openbadgedisplayer', implode(', ', $sourcelinks)) .'</p>'
);
if ($owner) {
$fields['badgegroups'] = array(
'type' => 'container',
'class' => '',
'elements' => array(
......@@ -324,14 +326,24 @@ class PluginBlocktypeOpenbadgedisplayer extends SystemBlocktype {
'value' => json_encode($current_values),