Commit 85986e6c authored by Francois Marier's avatar Francois Marier
Browse files

Enable sharing options on profile page



Part of bug #807278

Profile page now behaves more like a normal page/view, with the
following exceptions:
- Not removable
- Title, description and tags not editable
- No advanced sharing options
- Cannot be part of a collection
- Not available in bulk access update options

Change-Id: Ia42cdaee7978fe2e737a89cd79b043feb02ceb0d
Signed-off-by: default avatarEugene Venter <eugene@catalyst.net.nz>
parent eb9c4dae
......@@ -41,7 +41,13 @@ function pieform_element_viewacl(Pieform $form, $element) {
$value = $form->get_value($element);
// Look for the presets and split them into two groups
$public = get_config('allowpublicviews') == '1' && $USER->institution_allows_public_views();
$public = false;
if (get_config('allowpublicviews') && $USER->institution_allows_public_views()) {
$public = true;
}
else if (get_config('allowpublicprofiles') && $element['viewtype'] == 'profile') {
$public = true;
}
$presets = array();
$loggedinindex = 0;
if ($public) {
......
......@@ -3716,22 +3716,23 @@ class View {
* @param integer $group
* @param string $institution
* @param string $matchconfig record all matches with given config hash (see set_access)
* @param boolean $includeprofile include profile view
*
* @return array, array
*/
function get_views_and_collections($owner=null, $group=null, $institution=null, $matchconfig=null) {
function get_views_and_collections($owner=null, $group=null, $institution=null, $matchconfig=null, $includeprofile=true) {
$ownersql = self::owner_sql((object) array('owner' => $owner, 'group' => $group, 'institution' => $institution));
$records = get_records_sql_array("
SELECT v.id AS vid, v.title AS vname, v.accessconf,
$sql = "
SELECT v.id AS vid, v.type AS vtype, v.title AS vname, v.accessconf,
v.startdate, v.stopdate, v.template,
c.id AS cid, c.name AS cname
FROM {view} v
LEFT JOIN {collection_view} cv ON v.id = cv.view
LEFT JOIN {collection} c ON cv.collection = c.id
WHERE v.$ownersql AND v.type = 'portfolio'
ORDER BY c.name, v.title",
array()
);
WHERE v.$ownersql AND v.type IN ('portfolio'";
$sql .= $includeprofile ? ", 'profile') " : ') ';
$sql .= 'ORDER BY c.name, v.title';
$records = get_records_sql_array($sql, array());
$collections = array();
$views = array();
......@@ -3743,6 +3744,7 @@ class View {
foreach ($records as &$r) {
$v = array(
'id' => $r->vid,
'type' => $r->vtype,
'name' => $r->vname,
'startdate' => $r->startdate,
'stopdate' => $r->stopdate,
......@@ -4227,54 +4229,6 @@ function objection_form_cancel_submit(Pieform $form) {
));
}
function togglepublic_form($viewid) {
$view = new View($viewid);
$public = $view->is_public();
$togglepublic = pieform(array(
'name' => 'togglepublic',
'autofocus' => false,
'renderer' => 'div',
'elements' => array(
'changeto' => array(
'type' => 'hidden',
'value' => ($public) ? 'loggedin' : 'public'
),
'id' => array(
'type' => 'hidden',
'value' => $viewid
),
'submit' => array(
'type' => 'submit',
'value' => ($public) ? get_string('loggedinusersonly') : get_string('allowpublicaccess'),
),
),
));
return $togglepublic;
}
function togglepublic_submit(Pieform $form, $values) {
global $SESSION, $userid;
$access = array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
);
if ($values['changeto'] == 'public') {
$access[] = array(
'type' => 'public',
'startdate' => null,
'stopdate' => null,
);
}
$view = new View($values['id']);
$view->set_access($access);
$SESSION->add_ok_msg(get_string('viewaccesseditedsuccessfully', 'view'));
redirect('/view/blocks.php?id=' . $view->get('id'));
}
/**
* display format for author names in views - firstname
......
......@@ -9,7 +9,6 @@
<div class="subpage rel cl">
{if $columns}
{if $togglepublic}<div class="fr">{$togglepublic|safe}</div>{/if}
{str tag="editblockspagedescription" section="view"}
<form action="{$formurl}" method="post">
<input type="submit" name="{$action_name}" id="action-dummy" class="hidden">
......
......@@ -4,5 +4,5 @@
<li {if $selected == 'layout'} class="current-tab"{/if}><a{if $selected == 'layout'} class="current-tab"{/if} href="{$WWWROOT}view/layout.php?id={$viewid}{if $new}&new=1{/if}">{str tag=editlayout section=view}</a></li>
<li {if $selected == 'content'} class="current-tab"{/if}><a{if $selected == 'content'} class="current-tab"{/if} href="{$WWWROOT}view/blocks.php?id={$viewid}{if $new}&new=1{/if}">{str tag=editcontent section=view}</a></li>
<li class="displaypage"><a href="{$displaylink}{if $new}&new=1{/if}">{str tag=displayview section=view} &raquo;</a></li>
{if $edittitle}<li class="sharepage"><a href="{$WWWROOT}view/access.php?id={$viewid}{if $new}&new=1{/if}">{str tag=shareview section=view} &raquo;</a></li>{/if}
{if $edittitle || $viewtype == 'profile'}<li class="sharepage"><a href="{$WWWROOT}view/access.php?id={$viewid}{if $new}&new=1{/if}">{str tag=shareview section=view} &raquo;</a></li>{/if}
</ul></div>
......@@ -88,9 +88,9 @@ $form = array(
// For institution views, force edit access of one view at a time for now. Editing multiple
// institution views requires doing some tricky stuff with the 'copy for new users/groups'
// options, and there's not much room for the 'Share' tab in the admin area anyway
if (!$institution) {
if (!$institution && $view->get('type') != 'profile') {
list($collections, $views) = View::get_views_and_collections(
$view->get('owner'), $group, $institution, $view->get('accessconf')
$view->get('owner'), $group, $institution, $view->get('accessconf'), false
);
}
......@@ -153,6 +153,7 @@ $form['elements']['accesslist'] = array(
$form['elements']['more'] = array(
'type' => 'fieldset',
'class' => $view->get('type') == 'profile' ? 'hidden' : '',
'collapsible' => true,
'collapsed' => true,
'legend' => get_string('moreoptions', 'view'),
......@@ -545,7 +546,20 @@ function editaccess_submit(Pieform $form, $values) {
}
$toupdate[] = $viewid;
}
}
}
else if ($view->get('type') == 'profile') {
// Force default Advanced options
$felements = $form->get_property('elements');
if (!empty($felements['more']['elements'])) {
foreach (array_keys($felements['more']['elements']) as $ename) {
if (property_exists($view, $ename)) {
$viewconfig[$ename] = $view->get($ename);
}
}
}
$toupdate[] = $view->get('id');
}
}
if (!empty($toupdate)) {
......
......@@ -194,9 +194,6 @@ $viewtitle = $view->get('title');
$owner = $view->get('owner');
if ($owner && $viewtype == 'profile') {
$viewtitle = get_string('usersprofile', 'mahara', display_name($view->get('owner'), null, true));
if (get_config('allowpublicprofiles')) {
$smarty->assign('togglepublic', togglepublic_form($viewid));
}
}
if (get_config('viewmicroheaders')) {
......
......@@ -78,6 +78,7 @@ $smarty->assign('form', $layoutform);
$smarty->assign('form_start_tag', $layoutform->get_form_tag());
$smarty->assign('options', $options);
$smarty->assign('viewid', $view->get('id'));
$smarty->assign('viewtype', $view->get('type'));
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('edittitle', $view->can_edit_title());
$smarty->assign('displaylink', $view->get_url());
......
Supports Markdown
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