Commit b60af91a authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Allow new user default view templates to be edited (Bug #1303551)"

parents a6206ea2 d1765fef
......@@ -25,7 +25,14 @@ define('TITLE', $title);
$offset = param_integer('offset', 0);
$templateviews = View::get_template_views();
list($searchform, $data, $pagination) = View::views_by_owner(null, 'mahara');
if ($data->data) {
$views = array_merge($templateviews, $data->data);
}
else {
$views = $templateviews;
}
$js = <<< EOF
addLoadEvent(function () {
......@@ -54,7 +61,7 @@ $createviewform = pieform(create_view_form(null, 'mahara'));
$smarty = smarty(array('paginator'));
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('views', $data->data);
$smarty->assign('views', $views);
$smarty->assign('institution', 'mahara');
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('query', param_variable('query', null));
......
......@@ -209,6 +209,7 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
}
public static function rewrite_blockinstance_config(View $view, $configdata) {
safe_require('artefact', 'internal');
if ($view->get('owner') !== null) {
$artefacttypes = array_diff(PluginArtefactInternal::get_profile_artefact_types(), array('email'));
$artefactids = get_column_sql('
......
......@@ -519,28 +519,6 @@ class User {
'type' => 'profile',
), $systemprofileviewid, $this->get('id'), false);
// Add about me block
$aboutme = new BlockInstance(0, array(
'blocktype' => 'profileinfo',
'title' => get_string('aboutme', 'blocktype.internal/profileinfo'),
'view' => $view->get('id'),
'row' => 1,
'column' => 1,
'order' => 1,
));
$configdata = array('artefactids' => array());
if ($intro = get_field('artefact', 'id', 'owner', $this->get('id'), 'artefacttype', 'introduction')) {
$configdata['artefactids'][] = $intro;
}
else {
$configdata['introtext'] = '';
}
if ($this->get('profileicon')) {
$configdata['profileicon'] = $this->get('profileicon');
}
$aboutme->set('configdata', $configdata);
$view->addblockinstance($aboutme);
// Set view access
$access = array(
array(
......@@ -1129,6 +1107,9 @@ class User {
if ($owner > 0 && $owner == $this->get('id')) {
return true;
}
if ($owner == "0" && $this->get('admin')) {
return true;
}
$institution = $v->get('institution');
if ($institution && $this->can_edit_institution($institution)) {
return true;
......
......@@ -43,6 +43,10 @@ class PluginBlocktypeGroupMembers extends SystemBlocktype {
public static function render_instance (BlockInstance $instance, $editing = false) {
global $USER;
if ($instance->get_view()->get('owner') == "0") {
return '';
}
$configdata = $instance->get('configdata');
$rows = isset($configdata['rows']) ? $configdata['rows'] : 1;
$columns = isset($configdata['columns']) ? $configdata['columns'] : 6;
......
......@@ -41,6 +41,9 @@ $string['profileviewtitle'] = 'Profile page';
$string['dashboardviewtitle'] = 'Dashboard page';
$string['grouphomepageviewtitle'] = 'Group homepage';
$string['viewname'] = 'Page name';
$string['templatedashboard'] = 'Dashboard template';
$string['templategrouphomepage'] = 'Group homepage template';
$string['templateprofile'] = 'Profile template';
// my views
$string['artefacts'] = 'Artefacts';
......
......@@ -3273,5 +3273,33 @@ function xmldb_core_upgrade($oldversion=0) {
change_field_notnull($table, $field);
}
// Add about me block to existing profile template.
if ($oldversion < 2014043000) {
$systemprofileviewid = get_field('view', 'id', 'owner', 0, 'type', 'profile');
// Find out how many blocks already exist.
$existingblocks = count_records('block_instance',
'view', $systemprofileviewid,
'row', 1,
'column', 1);
// Create the block at the end of the cell.
require_once(get_config('docroot') . 'blocktype/lib.php');
$aboutme = new BlockInstance(0, array(
'blocktype' => 'profileinfo',
'title' => get_string('aboutme', 'blocktype.internal/profileinfo'),
'view' => $systemprofileviewid,
'row' => 1,
'column' => 1,
'order' => $existingblocks + 1,
));
$aboutme->commit();
// Move the block to the start of the cell.
require_once(get_config('libroot') . 'view.php');
$view = new View($systemprofileviewid);
$view->moveblockinstance(array('id' => $aboutme->get('id'), 'row' => 1, 'column' => 1, 'order' => 1));
}
return $status;
}
......@@ -2371,15 +2371,16 @@ function install_system_profile_view() {
$view->set_access(array(array(
'type' => 'loggedin'
)));
$blocktypes = array('myviews' => 1, 'mygroups' => 1, 'myfriends' => 2, 'wall' => 2); // column ids
$blocktypes = array('profileinfo' => 1, 'myviews' => 1, 'mygroups' => 1, 'myfriends' => 2, 'wall' => 2); // column ids
$installed = get_column_sql('SELECT name FROM {blocktype_installed} WHERE name IN (' . join(',', array_map('db_quote', array_keys($blocktypes))) . ')');
$weights = array(1 => 0, 2 => 0);
foreach (array_keys($blocktypes) as $blocktype) {
if (in_array($blocktype, $installed)) {
$weights[$blocktypes[$blocktype]]++;
$title = ($blocktype == 'profileinfo') ? get_string('aboutme', 'blocktype.internal/profileinfo') : get_string('title', 'blocktype.' . $blocktype);
$newblock = new BlockInstance(0, array(
'blocktype' => $blocktype,
'title' => get_string('title', 'blocktype.' . $blocktype),
'title' => $title,
'view' => $view->get('id'),
'row' => 1,
'column' => $blocktypes[$blocktype],
......
......@@ -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 = 2014041600;
$config->version = 2014043000;
$config->release = '1.10.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
......@@ -802,7 +802,7 @@ class View {
}
public function get_owner_object() {
if (is_null($this->owner)) {
if (empty($this->owner)) {
return false;
}
if (!isset($this->ownerobj)) {
......@@ -3135,7 +3135,7 @@ class View {
else if ($owner instanceof User) {
$user = $owner;
}
else if (intval($owner) != 0) {
else if (intval($owner) != 0 || $owner == "0") {
$user = new User();
$user->find_by_id(intval($owner));
}
......@@ -3597,6 +3597,23 @@ class View {
return array();
}
public function get_template_views() {
$views = get_records_sql_array(
"SELECT v.*
FROM {view} v
WHERE v.owner = 0
ORDER BY v.title, v.id", array());
$results = array();
if ($views) {
foreach ($views as $view) {
$view->displaytitle = get_string('template' . $view->type, 'view');
$view->issitetemplate = true;
$results[] = (array)$view;
}
}
return $results;
}
public function get_layoutrows() {
$layoutrows = array();
$owner = $this->get('owner');
......@@ -4308,7 +4325,7 @@ class View {
define('GROUP', $this->group);
define('NOGROUPMENU', 1);
}
else if ($this->institution == 'mahara') {
else if ($this->institution == 'mahara' || $this->owner == "0") {
define('ADMIN', 1);
define('MENUITEM', 'configsite/siteviews');
}
......@@ -4602,7 +4619,10 @@ class View {
* @return string
*/
public function get_url($full=true, $useid=false) {
if ($this->type == 'profile') {
if ($this->owner == "0") {
return null;
}
else if ($this->type == 'profile') {
if (!$useid) {
return profile_url($this->get_owner_object(), $full);
}
......
......@@ -18,20 +18,22 @@
{str tag=editcontent section=view}<span class="accessible-hidden">({str tag=tab}{if $selected == 'content'} {str tag=selected}{/if})</span>
</a>
</li>
{if can_use_skins(null, false, $issiteview)}
<li {if $selected == 'skin'} class="current-tab"{/if}>
<a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">
{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span>
</a>
</li>
{/if}
<li class="displaypage">
<a href="{$displaylink}">{str tag=displayview section=view} &raquo;</a>
</li>
{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 !$issitetemplate}
{if can_use_skins(null, false, $issiteview)}
<li {if $selected == 'skin'} class="current-tab"{/if}>
<a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">
{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span>
</a>
</li>
{/if}
<li class="displaypage">
<a href="{$displaylink}">{str tag=displayview section=view} &raquo;</a>
</li>
{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}
{/if}
</ul>
</div>
......@@ -51,18 +51,24 @@
</form>
<div id="view-wizard-controls" class="center">
<form action="{$WWWROOT}{if $groupid}{if $viewtype == 'grouphomepage'}{$groupurl}{else}view/groupviews.php{/if}{elseif $institution}view/institutionviews.php{else}view/index.php{/if}" method="GET">
{if $groupid}
{if $viewtype == 'grouphomepage'}
<input type="hidden" name="id" value="{$groupid}">
{else}
<input type="hidden" name="group" value="{$groupid}">
{if $issitetemplate}
<form action="{$WWWROOT}admin/site/views.php" method="GET">
<input class="submit" type="submit" value="{str tag='done'}">
</form>
{else}
<form action="{$WWWROOT}{if $groupid}{if $viewtype == 'grouphomepage'}{$groupurl}{else}view/groupviews.php{/if}{elseif $institution}view/institutionviews.php{else}view/index.php{/if}" method="GET">
{if $groupid}
{if $viewtype == 'grouphomepage'}
<input type="hidden" name="id" value="{$groupid}">
{else}
<input type="hidden" name="group" value="{$groupid}">
{/if}
{elseif $institution}
<input type="hidden" name="institution" value="{$institution}">
{/if}
{elseif $institution}
<input type="hidden" name="institution" value="{$institution}">
<input class="submit" type="submit" value="{str tag='done'}">
</form>
{/if}
<input class="submit" type="submit" value="{str tag='done'}">
</form>
</div>
{elseif $block}
......
......@@ -3,7 +3,9 @@
{if $edittitle}<li {if $selected == 'title'} class="current-tab"{/if}><a{if $selected == 'title'} class="current-tab"{/if} href="{$WWWROOT}view/edit.php?id={$viewid}{if $new}&new=1{/if}">{str tag=edittitleanddescription section=view}<span class="accessible-hidden">({str tag=tab}{if $selected == 'title'} {str tag=selected}{/if})</span></a></li>{/if}
<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}<span class="accessible-hidden">({str tag=tab}{if $selected == 'layout'} {str tag=selected}{/if})</span></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}<span class="accessible-hidden">({str tag=tab}{if $selected == 'content'} {str tag=selected}{/if})</span></a></li>
{if can_use_skins(null, false, $issiteview)}<li {if $selected == 'skin'} class="current-tab"{/if}><a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span></a></li>{/if}
<li class="displaypage"><a href="{$displaylink}">{str tag=displayview section=view} &raquo;</a></li>
{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}
{if !$issitetemplate}
{if can_use_skins(null, false, $issiteview)}<li {if $selected == 'skin'} class="current-tab"{/if}><a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span></a></li>{/if}
<li class="displaypage"><a href="{$displaylink}">{str tag=displayview section=view} &raquo;</a></li>
{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}
{/if}
</ul></div>
......@@ -25,7 +25,13 @@
<div id="myviews" class="listing">
{foreach from=$views item=view}
<div class="listrow {cycle values='r0,r1'}">
<h3 class="title"><a href="{$view.fullurl}">{$view.displaytitle}</a></h3>
<h3 class="title">
{if $view.issitetemplate}
{$view.displaytitle}
{else}
<a href="{$view.fullurl}">{$view.displaytitle}</a>
{/if}
</h3>
<div class="fr btns2">
{if !$view.submittedto && (!$view.locked || $editlocked)}
<a href="{$WWWROOT}view/blocks.php?id={$view.id}&{$querystring}" title="{str tag ="editcontentandlayout" section="view"}"><img src="{theme_url filename='images/btn_edit.png'}" alt="{str(tag=editspecific arg1=$view.displaytitle)|escape:html|safe}"></a>
......
......@@ -48,7 +48,7 @@ $group = $view->get('group');
$institution = $view->get('institution');
View::set_nav($group, $institution, true);
if (!$USER->can_edit_view($view)) {
if (!$USER->can_edit_view($view) || $view->get('owner') == "0") {
throw new AccessDeniedException();
}
if ($group && !group_within_edit_window($group)) {
......
......@@ -87,7 +87,9 @@ else if ($view->get('type') == 'dashboard') {
}
else if ($view->get('type') == 'grouphomepage') {
$title = get_string('grouphomepage', 'view');
$groupurl = group_homepage_url(get_record('group', 'id', $view->get('group')), false);
if ($view->get('owner') != "0") {
$groupurl = group_homepage_url(get_record('group', 'id', $view->get('group')), false);
}
define('TITLE', $title . ': ' . get_string('editcontent', 'view'));
}
else if ($new) {
......@@ -247,8 +249,7 @@ if (isset($groupurl)) {
}
$smarty->assign('institution', $institution);
if (get_config('userscanchooseviewthemes')
&& $view->is_themeable()) {
if (get_config('userscanchooseviewthemes') && $view->is_themeable() && $view->get('owner') != "0") {
$smarty->assign('viewtheme', $viewtheme);
$smarty->assign('viewthemes', $allowedthemes);
}
......@@ -272,4 +273,8 @@ else {
}
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
if ($view->get('owner') == "0") {
$smarty->assign('issitetemplate', true);
}
$smarty->display('view/blocks.tpl');
......@@ -17,7 +17,7 @@ $viewid = param_integer('id');
$view = new View($viewid, null);
if (!$view || !$USER->can_edit_view($view)) {
if (!$view || $view->get('owner') == "0" || !$USER->can_edit_view($view)) {
throw new AccessDeniedException(get_string('cantdeleteview', 'view'));
}
$groupid = $view->get('group');
......
......@@ -176,6 +176,9 @@ if (get_config('viewmicroheaders')) {
$smarty->assign('microheadertitle', $view->display_title(true, false));
}
$smarty->assign('issiteview', $view->get('institution') == 'mahara');
if ($view->get('owner') == "0") {
$smarty->assign('issitetemplate', true);
}
$smarty->display('view/layout.tpl');
function viewlayout_validate(Pieform $form, $values) {
......
......@@ -26,6 +26,7 @@ $issiteview = $view->get('institution') == 'mahara';
if (!can_use_skins(null, false, $issiteview)) {
throw new FeatureNotEnabledException();
}
$view->set_edit_nav();
$view->set_user_theme();
// Is page skin already saved/set for current page?
......@@ -61,7 +62,7 @@ $userskins = Skin::get_user_skins();
$favorskins = Skin::get_favorite_skins();
$siteskins = Skin::get_site_skins();
if (!$USER->can_edit_view($view)) {
if (!$USER->can_edit_view($view) || $view->get('owner') == "0") {
throw new AccessDeniedException();
}
......
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