Commit ae9aa271 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes Ifa36651d,Ic6914697,I4d13446f,I69f5cd46

* changes:
  Remove view title display logic from my views template (bug #860154)
  Overwrite the profile view title on the Share page (bug #860154)
  Move the check for deleted groups when creating a View
  Get moderating roles from group function instead of the view
parents 8e71f8a9 d72aeaf3
......@@ -1002,9 +1002,15 @@ class User {
}
$group = $v->get('group');
if ($group) {
$moderatingroles = $v->get('moderatingroles');
$this->reset_grouproles();
return isset($this->grouproles[$group]) && in_array($this->grouproles[$group], $moderatingroles);
if (!isset($this->grouproles[$group])) {
return false;
}
if (($v->get('type') == 'grouphomepage' || $v->get('locked')) && $this->grouproles[$group] != 'admin') {
return false;
}
require_once('group.php');
return group_role_can_moderate_views($group, $this->grouproles[$group]);
}
return false;
}
......
......@@ -182,6 +182,26 @@ function group_role_can_edit_views($group, $role) {
return $editroles != 'admin';
}
function group_role_can_moderate_views($group, $role) {
static $moderatingroles = array();
if (empty($role)) {
return false;
}
if ($role == 'admin') {
return true;
}
if (!isset($moderatingroles[$group])) {
$grouptype = get_field('group', 'grouptype', 'id', $group);
safe_require('grouptype', $grouptype);
$moderatingroles[$group] = call_static_method('GroupType' . ucfirst($grouptype), 'get_view_moderating_roles');
}
return in_array($role, $moderatingroles[$group]);
}
/**
* Returns whether a user is allowed to assess views that have been submitted
* to the given group.
......
......@@ -59,7 +59,6 @@ class View {
private $dirtycolumns; // for when we change stuff
private $tags;
private $categorydata;
private $moderatingroles;
private $template;
private $retainview;
private $copynewuser = 0;
......@@ -117,7 +116,12 @@ class View {
public function __construct($id=0, $data=null) {
if (!empty($id)) {
$tempdata = get_record('view','id',$id);
$tempdata = get_record_sql('
SELECT v.*
FROM {view} v LEFT JOIN {group} g ON v.group = g.id
WHERE v.id = ? AND (v.group IS NULL OR g.deleted = 0)',
array($id)
);
if (empty($tempdata)) {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $id));
}
......@@ -146,14 +150,6 @@ class View {
$this->atime = time();
$this->columns = array();
$this->dirtycolumns = array();
if ($this->group) {
$group = get_record('group', 'id', $this->group);
if ($group->deleted) {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $id));
}
safe_require('grouptype', $group->grouptype);
$this->moderatingroles = call_static_method('GroupType' . ucfirst($group->grouptype), 'get_view_moderating_roles');
}
}
/**
......@@ -2511,7 +2507,7 @@ class View {
$userid = (!$groupid && !$institution) ? $USER->get('id') : null;
$select = '
SELECT v.id,v.title,v.description,v.type,v.mtime,v.locked';
SELECT v.id, v.title, v.description, v.type, v.mtime, v.owner, v.group, v.institution, v.locked';
$from = '
FROM {view} v';
$where = '
......@@ -2556,10 +2552,13 @@ class View {
$data = array();
if ($viewdata) {
for ($i = 0; $i < count($viewdata); $i++) {
$view = new View(0, $viewdata[$i]);
$view->set('dirty', false);
$index[$viewdata[$i]->id] = $i;
$data[$i]['id'] = $viewdata[$i]->id;
$data[$i]['type'] = $viewdata[$i]->type;
$data[$i]['title'] = $viewdata[$i]->title;
$data[$i]['displaytitle'] = $view->display_title_editing();
$data[$i]['url'] = $view->get_url();
$data[$i]['mtime'] = $viewdata[$i]->mtime;
$data[$i]['locked'] = $viewdata[$i]->locked;
$data[$i]['removable'] = self::can_remove_viewtype($viewdata[$i]->type);
......@@ -3537,6 +3536,19 @@ class View {
return $title;
}
public function display_title_editing() {
if ($this->type == 'profile') {
return get_string('profileviewtitle', 'view');
}
if ($this->type == 'dashboard') {
return get_string('dashboardviewtitle', 'view');
}
if ($this->type == 'grouphomepage') {
return get_string('grouphomepage', 'view');
}
return $this->title;
}
public function visit_message() {
$visitcountstart = max(get_config('stats_installation_time'), $this->ctime);
$visitcountend = get_config('viewloglatest');
......@@ -3804,10 +3816,20 @@ class View {
}
foreach ($records as &$r) {
// Construct a View object temporarily just so we can use display_title_editing, get_url
$view = new View(0, array(
'id' => $r->vid,
'title' => $r->vname,
'type' => $r->vtype,
'owner' => $owner,
'group' => $group,
));
$view->set('dirty', false);
$v = array(
'id' => $r->vid,
'type' => $r->vtype,
'name' => $r->vname,
'name' => $view->display_title_editing(),
'url' => $view->get_url(),
'startdate' => $r->startdate,
'stopdate' => $r->stopdate,
'template' => $r->template,
......
<tr class="{cycle values='r0,r1'}">
<td class="cv"><a href="{$WWWROOT}view/view.php?id={$item.viewid}">{$item.name|str_shorten_text:50:true}</a></td>
<td class="cv"><a href="{$item.url}">{$item.name|str_shorten_text:50:true}</a></td>
<td class="al">
{if $item.access}<div>{$item.access}</div>{/if}
{if $item.accessgroups}
......
......@@ -23,16 +23,7 @@
{foreach from=$views item=view}
<tr class="{cycle values='r0,r1'}">
<td>
{if $view.type == 'profile'}
<h3><a href="{$WWWROOT}user/view.php">{str tag=profileviewtitle section=view}</a></h3>
{elseif $view.type == 'dashboard'}
<h3><a href="{$WWWROOT}">{str tag=dashboardviewtitle section=view}</a></h3>
{elseif $view.type == 'grouphomepage'}
<h3><a href="{$WWWROOT}group/view.php?id={$GROUP->id}">{str tag=grouphomepage section=view}</a></h3>
{else}
<h3><a href="{$WWWROOT}view/view.php?id={$view.id}">{$view.title}</a></h3>
{/if}
<h3><a href="{$view.url}">{$view.displaytitle}</a></h3>
{if $view.submittedto}
<div class="submitted-viewitem">{$view.submittedto|clean_html|safe}</div>
{elseif $view.type == 'profile'}
......
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