From: dongsheng Date: Tue, 26 Aug 2008 07:20:56 +0000 (+0000) Subject: MDL-13766 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=27051e4319a3dcd4287bde3525d6f058ec5bc460;p=moodle.git MDL-13766 1. Chanage database, create 2 more tables for repository 2. One-step download in file picker --- diff --git a/admin/repository.php b/admin/repository.php index f43670b9a0..18bde9fca4 100644 --- a/admin/repository.php +++ b/admin/repository.php @@ -40,13 +40,15 @@ if (!empty($edit) || !empty($new)) { $instance = repository_instance($edit); $configs = $instance->get_option_names(); $plugin = $instance->type; + $typeid = $instance->typeid; } else { $plugin = $new; + $typeid = $new; $instance = null; } $CFG->pagepath = 'admin/managerepository/' . $plugin; // display the edit form for this instance - $mform = new repository_admin_form('', array('plugin' => $plugin, 'instance' => $instance)); + $mform = new repository_admin_form('', array('plugin' => $plugin, 'typeid'=> $typeid, 'instance' => $instance)); // end setup, begin output if ($mform->is_cancelled()){ diff --git a/lib/db/install.xml b/lib/db/install.xml index 22f23a1ef0..707fa3318b 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -1776,7 +1776,7 @@ - +
@@ -1798,29 +1798,7 @@
- - - - - - - - - - - - - - - - - - - - - -
- +
@@ -1949,7 +1927,7 @@
- +
@@ -1961,6 +1939,44 @@
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 1ec8bec714..32a52dd944 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -699,6 +699,75 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint($result, 2008081900); } + if ($result && $oldversion < 2008082600) { + + /// Define table repository to be dropped + $table = new xmldb_table('repository'); + + /// Conditionally launch drop table for repository + if ($dbman->table_exists($table)) { + $dbman->drop_table($table); + } + + /// Define table repository to be created + $table = new xmldb_table('repository'); + + /// Adding fields to table repository + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1'); + $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + + /// Adding keys to table repository + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Conditionally launch create table for repository + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + /// Define table repository_instances to be created + $table = new xmldb_table('repository_instances'); + + /// Adding fields to table repository_instances + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); + $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); + $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); + + /// Adding keys to table repository_instances + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Conditionally launch create table for repository_instances + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Define table repository_instance_config to be created + $table = new xmldb_table('repository_instance_config'); + + /// Adding fields to table repository_instance_config + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); + + /// Adding keys to table repository_instance_config + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Conditionally launch create table for repository_instance_config + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008082600); + } + return $result; } diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index 50685416d3..f1afae2806 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -14,20 +14,21 @@ class repository_boxnet extends repository{ private $box; public function set_option($options = array()){ - $ret = parent::set_option($options); if (!empty($options['api_key'])) { set_config('api_key', $options['api_key'], 'boxnet'); } + unset($options['api_key']); + $ret = parent::set_option($options); return $ret; } public function get_option($config = ''){ - $options = parent::get_option($config); if($config==='api_key'){ return get_config('boxnet', 'api_key'); } else { $options['api_key'] = get_config('boxnet', 'api_key'); } + $options = parent::get_option($config); return $options; } diff --git a/repository/flickr/repository.class.php b/repository/flickr/repository.class.php index f8ec9cc1fa..d7b3d0fd56 100755 --- a/repository/flickr/repository.class.php +++ b/repository/flickr/repository.class.php @@ -14,6 +14,25 @@ class repository_flickr extends repository{ private $flickr; public $photos; + public function set_option($options = array()){ + if (!empty($options['api_key'])) { + set_config('api_key', $options['api_key'], 'flickr'); + } + unset($options['api_key']); + $ret = parent::set_option($options); + return $ret; + } + + public function get_option($config = ''){ + if($config==='api_key'){ + return get_config('flickr', 'api_key'); + } else { + $options['api_key'] = get_config('flickr', 'api_key'); + } + $options = parent::get_option($config); + return $options; + } + public function __construct($repositoryid, $context = SITEID, $options = array()){ global $SESSION, $action, $CFG; $options['page'] = optional_param('p', 1, PARAM_INT); diff --git a/repository/lib.php b/repository/lib.php index 0eef70fad2..3eae7694d5 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -179,9 +179,9 @@ abstract class repository { final public function ajax_info() { global $CFG; $repo = new stdclass; + $repo->id = $this->id; $repo->name = $this->options['name']; $repo->type = $this->options['type']; - $repo->id = $this->options['id']; $repo->icon = $CFG->wwwroot.'/repository/'.$repo->type.'/icon.png'; return $repo; } @@ -297,21 +297,30 @@ abstract class repository { */ public function set_option($options = array()){ global $DB; - if (is_array($options)) { - $options = array_merge($this->get_option(), $options); - } else { - $options = $this->get_option(); - } - $repository = new stdclass; - $position = 1; - $options = serialize($options); - if ($entry = $DB->get_record('repository', array('id'=>$this->id))) { - $field = 'data'.$position; - $repository->id = $entry->id; - $repository->$field = $options; - return $DB->update_record('repository', $repository); + $r = new object(); + $r->id = $this->id; + $r->name = $options['name']; + $DB->update_record('repository_instances', $r); + unset($options['name']); + foreach ($options as $name=>$value) { + if ($id = $DB->get_field('repository_instance_config', 'id', array('name'=>$name, 'instanceid'=>$this->id))) { + if ($value===null) { + return $DB->delete_records('repository_instance_config', array('name'=>$name, 'instanceid'=>$this->id)); + } else { + return $DB->set_field('repository_instance_config', 'value', $value, array('id'=>$id)); + } + } else { + if ($value===null) { + return true; + } + $config = new object(); + $config->instanceid = $this->id; + $config->name = $name; + $config->value = $value; + return $DB->insert_record('repository_instance_config', $config); + } } - return false; + return true; } /** @@ -322,23 +331,13 @@ abstract class repository { */ public function get_option($config = ''){ global $DB; - $entry = $DB->get_record('repository', array('id'=>$this->id)); - if (!empty($entry->visible)) { - $ret['visible'] = 1; - } else { - $ret['visible'] = 0; + $entries = $DB->get_records('repository_instance_config', array('instanceid'=>$this->id)); + $ret = array(); + if (empty($entries)) { + return $ret; } - $ret['type'] = $entry->repositorytype; - $ret['name'] = $entry->repositoryname; - $ret['id'] = $entry->id; - for ($i=1;$i<6;$i++) { - $field = 'data'.$i; - $data = unserialize($entry->$field); - if (!empty($data)) { - if (is_array($data)) { - $ret = array_merge($ret, $data); - } - } + foreach($entries as $entry){ + $ret[$entry->name] = $entry->value; } if (!empty($config)) { return $ret[$config]; @@ -438,16 +437,17 @@ class repository_exception extends moodle_exception { function repository_instances($context, $userid = null, $visible = true){ global $DB, $CFG, $USER; $params = array(); - $sql = 'SELECT * FROM {repository} r WHERE '; + $sql = 'SELECT i.*, r.type AS repositorytype, r.visible FROM {repository} r, {repository_instances} i WHERE '; + $sql .= 'i.typeid = r.id AND '; if (!empty($userid) && is_numeric($userid)) { - $sql .= ' (r.userid = 0 or r.userid = ?) AND '; + $sql .= ' (i.userid = 0 or i.userid = ?) AND '; $params[] = $userid; } if($context->id == SYSCONTEXTID) { - $sql .= ' (r.contextid = ?)'; + $sql .= ' (i.contextid = ?)'; $params[] = SYSCONTEXTID; } else { - $sql .= ' (r.contextid = ? or r.contextid = ?)'; + $sql .= ' (i.contextid = ? or i.contextid = ?)'; $params[] = SYSCONTEXTID; $params[] = $context->id; } @@ -461,8 +461,12 @@ function repository_instances($context, $userid = null, $visible = true){ foreach($repos as $repo) { require_once($CFG->dirroot . '/repository/'. $repo->repositorytype . '/repository.class.php'); + $options['visible'] = $repo->visible; + $options['name'] = $repo->name; + $options['type'] = $repo->repositorytype; + $options['typeid'] = $repo->typeid; $classname = 'repository_' . $repo->repositorytype; - $ret[] = new $classname($repo->id, $repo->contextid); + $ret[] = new $classname($repo->id, $repo->contextid, $options); } return $ret; } @@ -475,14 +479,20 @@ function repository_instances($context, $userid = null, $visible = true){ */ function repository_instance($id){ global $DB, $CFG; + $sql = 'SELECT i.*, r.type AS repositorytype, r.visible FROM {repository} r, {repository_instances} i WHERE '; + $sql .= 'i.typeid = r.id AND '; + $sql .= 'i.id = '.$id; - if (!$instance = $DB->get_record('repository', array('id' => $id))) { + if(!$instance = $DB->get_record_sql($sql)) { return false; } require_once($CFG->dirroot . '/repository/'. $instance->repositorytype . '/repository.class.php'); $classname = 'repository_' . $instance->repositorytype; - return new $classname($instance->id, $instance->contextid); + $options['typeid'] = $instance->typeid; + $options['type'] = $instance->repositorytype; + $options['name'] = $instance->name; + return new $classname($instance->id, $instance->contextid, $options); } function repository_static_function($plugin, $function) { @@ -587,8 +597,9 @@ function get_repository_client($context){ #list-$suffix li a:hover{ background: gray; color:white; } #repo-list-$suffix .repo-name{} #repo-list-$suffix li{margin-bottom: 1em} -#paging-$suffix{margin:10px 5px; clear:both} -#paging-$suffix a{padding: 4px; border: 1px solid gray} +#paging-$suffix{margin:10px 5px; clear:both;} +#paging-$suffix a{padding: 4px;border: 1px solid #CCC} +#path-$suffix a{padding: 4px;background: gray} #panel-$suffix{padding:0;margin:0; text-align:left;} p.upload{text-align:right;margin: 5px} p.upload a{font-size: 14px;background: #ccc;color:black;padding: 3px} @@ -827,6 +838,7 @@ _client.navbar = function(){ var str = ''; str += _client.uploadcontrol(); str += _client.makepage(); + str += _client.makepath(); return str; } // TODO @@ -1008,6 +1020,21 @@ _client.makepage = function(){ } return str; } +_client.makepath = function(){ + var str = ''; + var p = _client.ds.path; + if(p && p.length!=0){ + str += '
'; + if(p.path && p.name) + for(var i = 0; i < _client.ds.path.length; i++) { + str += ''; + str += _client.ds.path[i].name; + str += ' '; + } + str += '
'; + } + return str; +} // send download request _client.download = function(){ var title = document.getElementById('newname-$suffix').value; @@ -1121,16 +1148,7 @@ _client.dlfile = { panel.get('element').innerHTML = ret.e; return; } - var title = document.createElement('h1'); - title.innerHTML = '$strdownload'; - var btn = document.createElement('button'); - btn.innerHTML = '$stradd'; - btn.onclick = function(){ - repository_client_$suffix.end(ret); - } - panel.get('element').innerHTML = ''; - panel.get('element').appendChild(title); - panel.get('element').appendChild(btn); + repository_client_$suffix.end(ret); } } // request file list or login @@ -1197,6 +1215,7 @@ final class repository_admin_form extends moodleform { global $CFG; // type of plugin, string $this->plugin = $this->_customdata['plugin']; + $this->typeid = $this->_customdata['typeid']; $this->instance = (isset($this->_customdata['instance']) && is_subclass_of($this->_customdata['instance'], 'repository')) ? $this->_customdata['instance'] : null; @@ -1207,6 +1226,7 @@ final class repository_admin_form extends moodleform { $mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->id : 0); $mform->addElement('hidden', 'new', $this->plugin); $mform->addElement('hidden', 'plugin', $this->plugin); + $mform->addElement('hidden', 'typeid', $this->typeid); $mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"'); $mform->addRule('name', $strrequired, 'required', null, 'client'); @@ -1225,7 +1245,11 @@ final class repository_admin_form extends moodleform { $data = array(); $data['name'] = $this->instance->name; foreach ($this->instance->get_option_names() as $config) { - $data[$config] = $this->instance->$config; + if (!empty($this->instance->$config)) { + $data[$config] = $this->instance->$config; + } else { + $data[$config] = ''; + } } $this->set_data($data); } @@ -1236,7 +1260,7 @@ final class repository_admin_form extends moodleform { global $DB; $errors = array(); - if ($DB->count_records('repository', array('repositoryname' => $data['name'], 'repositorytype' => $data['plugin'])) > 1) { + if ($DB->count_records('repository_instances', array('name' => $data['name'], 'typeid' => $data['typeid'])) > 1) { $errors = array('name' => get_string('err_uniquename', 'repository')); } diff --git a/repository/ws.php b/repository/ws.php index 2db658682a..a6be573de8 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -34,11 +34,11 @@ if(!$repository = $DB->get_record('repository', array('id'=>$repo_id))) } if(file_exists($CFG->dirroot.'/repository/'. - $repository->repositorytype.'/repository.class.php')) + $repository->type.'/repository.class.php')) { require_once($CFG->dirroot.'/repository/'. - $repository->repositorytype.'/repository.class.php'); - $classname = 'repository_' . $repository->repositorytype; + $repository->type.'/repository.class.php'); + $classname = 'repository_' . $repository->type; try{ $repo = new $classname($repo_id, $ctx_id, array('ajax'=>true)); } catch (repository_exception $e){ diff --git a/version.php b/version.php index bd18a45588..43dda17780 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008082600; // YYYYMMDD = date of the last version bump + $version = 2008082601; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20080826)'; // Human-friendly version name