Commit 6bd72796 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Template drop-down on create view page

parent 6fbf7077
......@@ -1451,9 +1451,12 @@ class View {
* @param integer $groupid Only return views owned by this group.
* @param string $institution Only return views owned by this institution.
* @param bool $template Only return views marked as templates.
* @param integer $limit
* @param integer $offset
* @param bool $extra
*
*/
public static function view_search($ownerid=null, $groupid=null, $institution=null, $template=null, $limit=10, $offset=0) {
public static function view_search($ownerid=null, $groupid=null, $institution=null, $template=null, $limit=null, $offset=0, $extra=true) {
global $USER;
$admin = $USER->get('admin');
$loggedin = $USER->is_logged_in();
......@@ -1477,10 +1480,14 @@ class View {
AND v.institution = ?';
$ph[] = $institution;
}
if ($template == true) {
if ($template) {
$where .= '
AND v.template = 1';
}
else if ($template === false) {
$where .= '
AND v.template = 0';
}
if ($admin) {
$from = '
......@@ -1563,7 +1570,9 @@ class View {
);
if ($viewdata) {
View::get_extra_view_info($viewdata);
if ($extra) {
View::get_extra_view_info($viewdata);
}
}
else {
$viewdata = array();
......
......@@ -46,6 +46,20 @@ if (empty($id)) {
|| $institution && !$USER->can_edit_institution($institution)) {
throw new AccessDeniedException();
}
// Get templates visible to the user and non-templates owned by
// the owner of the view being created
$templates = View::view_search(null, null, null, true, null, 0, false);
$ownerid = ($group || $institution) ? null : $USER->get('id');
$nontemplates = View::view_search($ownerid, $group, $institution, false, null, 0, false);
$templateoptions = array(0 => 'None');
foreach ($templates->data as $t) {
$templateoptions[$t->id] = $t->title;
}
foreach ($nontemplates->data as $t) {
$templateoptions[$t->id] = $t->title;
}
}
else {
$view = new View($id);
......@@ -128,11 +142,6 @@ $editview = array(
'defaultvalue' => isset($view) ? $view->get('tags') : null,
'help' => true,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(empty($new) ? get_string('save') : get_string('next'), get_string('cancel')),
'confirm' => $new && isset($view) ? array(null, get_string('confirmcancelcreatingview', 'view')) : null,
)
),
);
......@@ -159,6 +168,21 @@ else {
);
}
if ($new && count($templateoptions)) {
$editview['elements']['template'] = array(
'type' => 'select',
'title' => get_string('Template','view'),
'description' => get_string('createfromtemplatedescription','view'),
'options' => $templateoptions,
);
}
$editview['elements']['submit'] = array(
'type' => 'submitcancel',
'value' => array(empty($new) ? get_string('save') : get_string('next'), get_string('cancel')),
'confirm' => $new && isset($view) ? array(null, get_string('confirmcancelcreatingview', 'view')) : null,
);
$editview = pieform($editview);
function editview_cancel_submit() {
......
......@@ -32,7 +32,7 @@ define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'lib/view.php');
require_once(get_config('libroot') . 'view.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('myviews', 'view'));
......
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