Commit ffdbc6f2 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix copy view to institution & group views

parent db64d3aa
......@@ -1468,15 +1468,15 @@ class View {
}
public static function owner_sql($userid=null, $groupid=null, $institution=null) {
if ($institution) {
return 'institution = ' . db_quote($institution);
public static function owner_sql($ownerobj) {
if (!empty($ownerobj->institution)) {
return 'institution = ' . db_quote($ownerobj->institution);
}
if ($groupid) {
return '"group" = ' . (int)$groupid;
if (!empty($ownerobj->group)) {
return '"group" = ' . (int)$ownerobj->group;
}
if ($userid) {
return 'owner = ' . (int)$userid;
if (!empty($ownerobj->user)) {
return 'owner = ' . (int)$ownerobj->user;
}
return '';
}
......@@ -1516,12 +1516,12 @@ class View {
WHERE TRUE';
if ($ownedby) {
$where .= ' AND v.' . self::owner_sql($ownedby->user, $ownedby->group, $ownedby->institution);
$where .= ' AND v.' . self::owner_sql($ownedby);
}
if ($copyableby) {
$where .= '
AND (v.template = 1 OR (v.' . self::owner_sql($copyableby->user, $copyableby->group, $copyableby->institution) . '))';
AND (v.template = 1 OR (v.' . self::owner_sql($copyableby) . '))';
}
if ($query) {
......@@ -1917,7 +1917,7 @@ class View {
$taken = get_column_sql('
SELECT title
FROM {view}
WHERE ' . self::owner_sql($user, $group, $institution) . "
WHERE ' . self::owner_sql((object) array('user' => $user, 'group' => $group, 'institution' => $institution)) . "
AND title LIKE ? || '%'", array($title));
$ext = ''; $i = 0;
if ($taken) {
......@@ -1935,6 +1935,12 @@ class View {
if (!empty($search->query)) {
$params[] = 'ownerquery=' . $search->query;
}
if (!empty($search->group)) {
$params[] = 'group=' . $search->group;
}
if (!empty($search->institution)) {
$params[] = 'institution=' . $search->institution;
}
$params[] = 'ownerlimit=' . $search->limit;
$qstring = join('&', $params);
......@@ -1974,6 +1980,12 @@ class View {
if (!empty($search->query)) {
$params[] = 'viewquery=' . $search->query;
}
if (!empty($search->group)) {
$params[] = 'group=' . $search->group;
}
if (!empty($search->institution)) {
$params[] = 'institution=' . $search->institution;
}
$params[] = 'viewlimit=' . $search->limit;
$smarty = smarty_core();
......@@ -2056,7 +2068,6 @@ function create_view_form($group=null, $institution=null, $template=null) {
'type' => 'hidden',
'value' => $template,
);
$form['name'] .= $template;
$form['elements']['submit']['value'] = get_string('copyview', 'view');
}
return $form;
......@@ -2075,6 +2086,7 @@ function createview_submit(Pieform $form, $values) {
|| $institution && !$USER->can_edit_institution($institution)) {
throw new AccessDeniedException();
}
log_debug($group);
// Create a new view
$data = (object) array(
......
......@@ -45,6 +45,12 @@ $owners->query = trim(param_variable('ownerquery', ''));
$owners->template = null;
$owners->offset = param_integer('owneroffset', 0);
$owners->limit = param_integer('ownerlimit', 10);
if ($group) {
$owners->group = $group;
}
else if ($institution) {
$owners->institution = $institution;
}
View::get_viewownersearch_data($owners);
$views = new StdClass;
......@@ -56,7 +62,13 @@ if ($ownertype = param_alpha('owntype', null)) {
$views->ownedby = (object) array($ownertype => param_alphanum('ownid'));
}
$views->copyableby = (object) array('group' => $group, 'institution' => $institution, 'user' => null);
if (!($group || $institution)) {
if ($group) {
$views->group = $group;
}
else if ($institution) {
$views->institution = $institution;
}
else {
$views->copyableby->user = $USER->get('id');
}
View::get_templatesearch_data($views);
......
......@@ -33,9 +33,11 @@ $group = param_integer('group', null);
$institution = param_alphanum('institution', null);
$views = new StdClass;
$views->query = trim(param_variable('viewquery', ''));
$views->offset = param_integer('viewoffset', 0);
$views->limit = param_integer('viewlimit', 10);
$views->query = trim(param_variable('viewquery', ''));
$views->offset = param_integer('viewoffset', 0);
$views->limit = param_integer('viewlimit', 10);
$views->group = param_integer('group', null);
$views->institution = param_alphanum('institution', null);
$views->ownedby = null;
if ($ownertype = param_alpha('owntype', null)) {
$views->ownedby = (object) array($ownertype => param_alphanum('ownid'));
......
......@@ -30,10 +30,12 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
$owners = new StdClass;
$owners->query = trim(param_variable('ownerquery', ''));
$owners->template = null;
$owners->offset = param_integer('owneroffset', 0);
$owners->limit = param_integer('ownerlimit', 10);
$owners->query = trim(param_variable('ownerquery', ''));
$owners->template = null;
$owners->offset = param_integer('owneroffset', 0);
$owners->limit = param_integer('ownerlimit', 10);
$owners->group = param_integer('group', null);
$owners->institution = param_alphanum('institution', null);
View::get_viewownersearch_data($owners);
json_reply(false, array(
......
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