MDL-15404: fix few bugs in repository administration, add a beta version of the course repository list

This commit is contained in:
jerome 2008-09-05 06:30:18 +00:00
parent 8238f44f16
commit faaa613d99
8 changed files with 227 additions and 43 deletions

View File

@ -51,11 +51,12 @@ if (!empty($edit) || !empty($new)) {
$CFG->pagepath = 'admin/managerepository/' . $plugin;
// display the edit form for this instance
$mform = new repository_admin_form('', array('plugin' => $plugin, 'instance' => $repositorytype));
$fromform = $mform->get_data();
// end setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
exit;
} else if ($fromform = $mform->get_data() || (!empty($new) && !repository_static_function($new,"has_admin_config"))){
} else if (!empty($fromform) || (!empty($new) && !repository_static_function($new,"has_admin_config"))){
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
@ -92,7 +93,7 @@ if (!empty($edit) || !empty($new)) {
if ($edit){
if (repository_static_function($edit,"has_instance_config")
|| repository_static_function($edit,"has_multiple_instances")){
repository_display_instances_list(get_context_instance(CONTEXT_SYSTEM), true, $edit);
repository_display_instances_list(get_context_instance(CONTEXT_SYSTEM), $edit);
}
}

View File

@ -13,6 +13,8 @@ $sure = optional_param('sure', '', PARAM_ALPHA);
$move = optional_param('move', '', PARAM_ALPHA);
$type = optional_param('type', '', PARAM_ALPHA);
$context = get_context_instance(CONTEXT_SYSTEM);
$display = true; // fall through to normal display
$pagename = 'repositorycontroller';
@ -57,7 +59,7 @@ if (!empty($edit) || !empty($new)) {
}
// display the edit form for this instance
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance));
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance, 'contextid' => $context->id));
// end setup, begin output
if ($mform->is_cancelled()){

View File

@ -186,9 +186,9 @@ class block_admin extends block_list {
}
}
/// Repository Account
if ($course->id !== SITEID) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/repository/manage.php?id='.$USER->id.'&amp;course='.$course->id.'&amp;context=course">'.get_string('repositories').'</a>';
/// Repository Instances
if ($course->id !== SITEID && has_capability('moodle/course:update', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/repository/manage_instances.php?contextid='.$context->id.'">'.get_string('repositories').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/repository.png" alt=""/>';
}

View File

@ -49,6 +49,7 @@ $string['plugin'] = 'Repository plug-ins';
$string['preview'] = 'Preview';
$string['removed'] = 'Repository removed';
$string['repository'] = 'Repository';
$string['repositorycourse'] = 'Course repositories';
$string['repositories'] = 'Repositories';
$string['save'] = 'Save';
$string['saveas'] = 'Save as';
@ -63,6 +64,7 @@ $string['submit'] = 'Submit';
$string['sync'] = 'Sync';
$string['title'] = 'Repository file picker';
$string['thumbview'] = 'View as icons';
$string['typenotvisible'] = 'Type not visible';
$string['updown'] = 'Display order';
$string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...';

View File

@ -5599,11 +5599,16 @@ class admin_setting_managerepository extends admin_setting {
if ( repository_static_function($i->get_typename(), 'has_admin_config')
|| repository_static_function($i->get_typename(), 'has_instance_config')
|| repository_static_function($i->get_typename(), 'has_multiple_instances')) {
$settings .= '<a href="' . $this->baseurl . '&amp;edit=' . $i->get_typename() . '">'. $settingsstr .'</a>' . "\n";
$settings .= '<a href="' . $this->baseurl . '&amp;edit=' . $i->get_typename() . '">'
. $settingsstr .'</a>' . "\n";
}
$delete = '<a href="' . $this->baseurl . '&amp;delete=' . $i->get_typename() . '">' . $deletestr . '</a>' . "\n";
$delete = '<a href="' . $this->baseurl . '&amp;delete=' . $i->get_typename() . '">'
. $deletestr . '</a>' . "\n";
$hiddenshow = ' <a href="' . $this->baseurl . '&amp;hide=' . $i->get_typename() . '"><img src="' . $CFG->pixpath . '/i/' . ($i->get_visible() ? 'hide' : 'show') . '.gif" alt="' . get_string($i->get_visible() ? 'hide' : 'show') . '" /></a>' . "\n";
$hiddenshow = ' <a href="' . $this->baseurl . '&amp;hide=' . $i->get_typename() . '">'
.'<img src="' . $CFG->pixpath . '/i/' . ($i->get_visible() ? 'hide' : 'show') . '.gif"'
.' alt="' . get_string($i->get_visible() ? 'hide' : 'show') . '" />'
.'</a>' . "\n";
// display up/down link
$updown = '';

View File

@ -233,6 +233,14 @@ EOD;
return true;
}
public static function has_multiple_instances() {
return true;
}
public static function has_instance_config() {
return false;
}
public function admin_config_form(&$mform) {
$api_key = get_config('flickr', 'api_key');
if (empty($api_key)) {

View File

@ -923,7 +923,7 @@ function repository_check_context($ctx_id){
* @param string $type a type name to retrieve
* @return array repository instances
*/
function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null){
function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null, $nositeinstances=true){
global $DB, $CFG, $USER;
$params = array();
$sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE ';
@ -937,8 +937,12 @@ function repository_get_instances($context=null, $userid = null, $onlyvisible =
$sql .= ' AND (i.contextid = ?)';
$params[] = SYSCONTEXTID;
} else {
$sql .= ' AND (i.contextid = ? or i.contextid = ?)';
$params[] = SYSCONTEXTID;
if ($nositeinstances) {
$sql .= ' AND i.contextid = ?';
} else {
$sql .= ' AND (i.contextid = ? or i.contextid = ?)';
$params[] = SYSCONTEXTID;
}
$params[] = $context->id;
}
}
@ -1899,6 +1903,7 @@ final class repository_instance_form extends moodleform {
// type of plugin, string
$this->plugin = $this->_customdata['plugin'];
$this->typeid = $this->_customdata['typeid'];
$this->contextid = $this->_customdata['contextid'];
$this->instance = (isset($this->_customdata['instance'])
&& is_subclass_of($this->_customdata['instance'], 'repository'))
? $this->_customdata['instance'] : null;
@ -1910,6 +1915,7 @@ final class repository_instance_form extends moodleform {
$mform->addElement('hidden', 'new', $this->plugin);
$mform->addElement('hidden', 'plugin', $this->plugin);
$mform->addElement('hidden', 'typeid', $this->typeid);
$mform->addElement('hidden', 'contextid', $this->contextid);
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
$mform->addRule('name', $strrequired, 'required', null, 'client');
@ -1924,7 +1930,6 @@ final class repository_instance_form extends moodleform {
}
// and set the data if we have some.
//var_dump($this);
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
@ -2017,7 +2022,6 @@ final class repository_admin_form extends moodleform {
}
$this->set_data($data);
}
$this->add_action_buttons(true, get_string('save','repository'));
}
@ -2029,24 +2033,23 @@ final class repository_admin_form extends moodleform {
* @global object $CFG
* @global object $USER
* @param object $context the context for which we display the instance
* @param boolean $admin if true, so the form is been called by an administration
* page, only one type would be displayed
* @param string $typename if set, we display only one type of instance
*/
function repository_display_instances_list($context, $admin = false, $typename = null){
function repository_display_instances_list($context, $typename = null){
global $CFG, $USER;
if ($admin) {
$output = print_box_start('generalbox','',true);
//if the context is SYSTEM, so we call it from administration page
$admin = ($context->id == SYSCONTEXTID) ? true : false;
if($admin) {
$baseurl = $CFG->wwwroot . '/admin/repositoryinstance.php?sesskey=' . sesskey();
$type = repository_get_type_by_typename($typename);
}
$output = print_simple_box_start(true);
if ($admin) {
$output .= "<div ><h2 style='text-align: center'>" . get_string('siteinstances', 'repository') . " ";
}
$output .= "</h2></div>";
$output .= "</h2></div>";
} else {
$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&amp;sesskey=' . sesskey();
}
$namestr = get_string('name');
$pluginstr = get_string('plugin', 'repository');
$settingsstr = get_string('settings');
@ -2054,10 +2057,11 @@ function repository_display_instances_list($context, $admin = false, $typename =
$updown = get_string('updown', 'repository');
$plugins = get_list_of_plugins('repository');
//retrieve list of instances. In administration context we want to display all
//instances even if the type is not visible. In course/user context we
//want to display only visible instances. The repository_get_instances()
//third parameter displays only visible type.
$instances = repository_get_instances($context,null,!$admin,$typename);
//instances of a type, even if this type is not visible. In course/user context we
//want to display only visible instances, but for every type types. The repository_get_instances()
//third parameter displays only visible type. The fifth parameter is a trick that return
//instances of the $context + systemcontext.
$instances = repository_get_instances($context,null,!$admin,$typename, !$admin);
$instancesnumber = count($instances);
$alreadyplugins = array();
$table = new StdClass;
@ -2070,9 +2074,9 @@ function repository_display_instances_list($context, $admin = false, $typename =
$settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
$delete = '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
$type = repository_get_type_by_id($i->typeid);
$table->data[] = array($i->name, $type->get_readablename(), $delete, $settings);
//display a grey row if the type is defined as not visible
if (isset($type) && !$type->get_visible()){
$table->rowclass[] = 'dimmed_text';
@ -2094,14 +2098,15 @@ function repository_display_instances_list($context, $admin = false, $typename =
$instancehtml .= get_string('createrepository', 'repository');
$instancehtml .= '</h3><ul>';
foreach ($plugins as $p) {
if (!in_array($p, $alreadyplugins)) {
if (repository_static_function($p->get_typename(), 'has_multiple_instances')){
$instancehtml .= '<li><a href="'.$baseurl.'&amp;new='.$p.'">'.get_string('create', 'repository')
.' "'.get_string('repositoryname', 'repository_'.$p).'" '
.get_string('instance', 'repository').'</a></li>';
$addable++;
}
}
$type = repository_get_type_by_typename($p);
if ($type->get_visible()) {
if (repository_static_function($p, 'has_multiple_instances')){
$instancehtml .= '<li><a href="'.$baseurl.'&amp;new='.$p.'">'.get_string('create', 'repository')
.' "'.get_string('repositoryname', 'repository_'.$p).'" '
.get_string('instance', 'repository').'</a></li>';
$addable++;
}
}
}
$instancehtml .= '</ul>';
}
@ -2115,16 +2120,13 @@ function repository_display_instances_list($context, $admin = false, $typename =
}
}
if ($addable) {
$instancehtml .= '</div>';
$output .= $instancehtml;
}
$output .= print_simple_box_end(true);
$output .= print_box_end(true);
//print the list + creation links
print($output);
}

View File

@ -0,0 +1,164 @@
<?php
// $Id$
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->dirroot . '/repository/lib.php');
//require_once($CFG->libdir . '/adminlib.php');
// id of repository
$edit = optional_param('edit', 0, PARAM_INT);
$new = optional_param('new', '', PARAM_FORMAT);
$delete = optional_param('delete', 0, PARAM_INT);
$sure = optional_param('sure', '', PARAM_ALPHA);
$contextid = optional_param('contextid', 0, PARAM_INT);
$display = true; // fall through to normal display
if ($edit){
$pagename = 'repositoryinstanceedit';
}else if ($delete) {
$pagename = 'repositorydelete';
} else if ($new) {
$pagename = 'repositoryinstancenew';
}
else {
$pagename = 'repositorylist';
}
require_login(SITEID, false);
$context = get_context_instance_by_id($contextid);
//security: detect if we are in a course context
if ($context->contextlevel == CONTEXT_COURSE) {
$pagename = get_string("repositorycourse",'repository');
//is the user is allowed to edit this course, he's allowed to edit list of repository instances
require_capability('moodle/course:update', $context);
//retrieve course
//Retrieve the course object
if ( !$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
print_error('invalidcourseid');
}
}
$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $contextid . '&amp;sesskey='. sesskey();
//security: we cannot perform any action if the type is not visible
if (!empty($new)){
$type = repository_get_type_by_typename($new);
} else if (!empty($edit)){
$instance = repository_get_instance($edit);
$type = repository_get_type_by_id($instance->typeid);
} else if (!empty($delete)){
$instance = repository_get_instance($delete);
$type = repository_get_type_by_id($instance->typeid);
}
if (isset($type) && !$type->get_visible()) {
print_error('typenotvisible', 'repository', $baseurl);
}
//Create header crumbtrail
//$streditrepositoryaccount = get_string("editrepositoryinstance",'repository');
$navlinks = array();
if (!empty($course)) {
$navlinks[] = array('name' => $course->shortname,
'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
'type' => 'misc');
$navlinks[] = array('name' => $pagename,
'link' => null,
'type' => 'misc');
$title = $pagename;
$fullname = $course->fullname;
}
$navigation = build_navigation($navlinks);
//display page header
print_header($title, $fullname, $navigation);
print_heading($pagename);
$return = true;
if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository_get_instance($edit);
$instancetype = repository_get_type_by_id($instance->typeid);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
$plugin = $instancetype->get_typename();
$typeid = $instance->typeid;
} else {
$plugin = $new;
$typeid = $new;
$instance = null;
}
// create edit form for this instance
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance, 'contextid' => $contextid));
// end setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
exit;
} else if ($fromform = $mform->get_data()){
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($edit) {
$settings = array();
$settings['name'] = $fromform->name;
foreach($configs as $config) {
$settings[$config] = $fromform->$config;
}
$success = $instance->set_option($settings);
} else {
$success = repository_static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform);
$data = data_submitted();
}
if ($success) {
$savedstr = get_string('configsaved', 'repository');
//admin_externalpage_print_header();
print_heading($savedstr);
redirect($baseurl, $savedstr, 3);
} else {
print_error('instancenotsaved', 'repository', $baseurl);
}
exit;
} else {
// admin_externalpage_print_header();
print_heading(get_string('configplugin', 'repository_'.$plugin));
print_simple_box_start();
$mform->display();
print_simple_box_end();
$return = false;
}
} else if (!empty($delete)) {
// admin_externalpage_print_header();
$instance = repository_get_instance($delete);
if ($sure) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($instance->delete()) {
$deletedstr = get_string('instancedeleted', 'repository');
print_heading($deletedstr);
redirect($baseurl, $deletedstr, 3);
} else {
print_error('instancenotdeleted', 'repository', $baseurl);
}
exit;
}
notice_yesno(get_string('confirmdelete', 'repository', $instance->name), $baseurl . '&amp;delete=' . $delete . '&amp;sure=yes', $baseurl);
$return = false;
} else {
repository_display_instances_list($context);
$return = false;
}
if (!empty($return)) {
redirect($baseurl);
}
//display page footer
print_footer($course);