--- /dev/null
+<?php
+
+require_once(dirname(dirname(__FILE__)) . '/config.php');
+require_once($CFG->dirroot . '/repository/lib.php');
+require_once($CFG->libdir . '/adminlib.php');
+
+
+$CFG->pagepath = 'admin/managerepositories';
+
+// id of repository
+$edit = optional_param('edit', 0, PARAM_INT);
+$new = optional_param('new', '', PARAM_FORMAT);
+$hide = optional_param('hide', 0, PARAM_INT);
+$delete = optional_param('delete', 0, PARAM_INT);
+$sure = optional_param('sure', '', PARAM_ALPHA);
+
+$display = true; // fall through to normal display
+
+$pagename = 'repositorycontroller';
+
+if ($edit) {
+ $pagename = 'repositorysettings' . $edit;
+} else if ($delete) {
+ $pagename = 'repositorydelete';
+} else if ($new) {
+ $pagename = 'repositorynew';
+}
+admin_externalpage_setup($pagename);
+require_login(SITEID, false);
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
+
+$sesskeyurl = $CFG->wwwroot . '/' . $CFG->admin . '/repository.php?sesskey=' . sesskey();
+$baseurl = $CFG->wwwroot . '/admin/settings.php?section=managerepositories';
+
+$configstr = get_string('managerepositories', 'repository');
+
+$return = true;
+
+if (!empty($edit) || !empty($new)) {
+ if (!empty($edit)) {
+ $instance = repository_instance($edit);
+ $configs = $instance->get_option_names();
+ $plugin = $instance->type;
+ } else {
+ $plugin = $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));
+ // 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_system_context(), $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($hide)) {
+ if (!confirm_sesskey()) {
+ print_error('confirmsesskeybad', '', $baseurl);
+ }
+ $instance = repository_instance($hide);
+ $instance->hide();
+ $return = true;
+} else if (!empty($delete)) {
+ admin_externalpage_print_header();
+ $instance = repository_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), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
+ $return = false;
+}
+
+
+if (!empty($return)) {
+ redirect($baseurl);
+}
+admin_externalpage_print_footer();
$url . ' ?edit=' . $portfolio->get('id')
);
}
+
+ // repository setting
+ require_once("$CFG->dirroot/repository/lib.php");
+ $catname =get_string('repositories', 'repository');
+ $manage = get_string('manage', 'repository');
+ $url = "$CFG->wwwroot/$CFG->admin/repository.php";
+ $ADMIN->add('modules', new admin_category('repositorysettings', $catname));
+ $temp = new admin_settingpage('managerepositories', $manage);
+ $temp->add(new admin_setting_managerepository());
+ $ADMIN->add('repositorysettings', $temp);
+ $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
+ get_string('createrepository', 'repository'), $url, 'moodle/site:config', true),
+ '', $url);
+ $ADMIN->add('repositorysettings', new admin_externalpage('repositorydelete',
+ get_string('deleterepository', 'repository'), $url, 'moodle/site:config', true),
+ '', $url);
+ $ADMIN->add('repositorysettings', new admin_externalpage('repositorycontroller',
+ get_string('managerepositories', 'repository'), $url, 'moodle/site:config', true),
+ '', $url);
+ foreach (repository_instances(get_context_instance(CONTEXT_SYSTEM),
+ null, false) as $repository)
+ {
+ if ($repository->has_admin_config()) {
+ $ADMIN->add('repositorysettings',
+ new admin_externalpage('repositorysettings'.$repository->id,
+ $repository->name,
+ $url . '?edit=' . $repository->id),
+ 'moodle/site:config');
+ }
+ }
}
-?>
<?php //$Id$
-$string['add'] = 'Add';
+$string['add'] = 'Add a repository:';
$string['activaterep'] = 'Active repositories';
$string['back'] = '< Back';
$string['close'] = 'Close';
+$string['configsaved'] = 'Configuration saved!';
+$string['confirmdelete'] = 'Are you sure to delete this repository - $a?';
+$string['createrepository'] = 'Create a repository';
+$string['deleterepository'] = 'Delete this repository';
$string['download'] = 'Download';
$string['downloadsucc'] = 'Download Successfully!';
$string['filename'] = 'Filename';
$string['filesaved'] = 'File Saved!';
$string['invalidrepositoryid'] = 'Invalid Repository ID';
$string['invalidplugin'] = 'Invalid Repository Plug-in';
+$string['manage'] = 'Manage repositories';
$string['manageuserrepository'] = 'Manage individual repository';
$string['noenter'] = 'Nothing entered';
$string['plugin'] = 'Repository Plug-ins';
}
+class admin_setting_managerepository extends admin_setting {
+ private $baseurl;
+ function admin_setting_managerepository() {
+ global $CFG;
+ parent::admin_setting('managerepository', get_string('managerepository', 'repository'), '', '');
+ $this->baseurl = $CFG->wwwroot . '/' . $CFG->admin . '/repository.php?sesskey=' . sesskey();
+ }
+
+ function get_setting() {
+ return true;
+ }
+
+ function get_defaultsetting() {
+ return true;
+ }
+
+ function get_full_name() {
+ return 's_managerepository';
+ }
+
+ function write_setting($data) {
+ $url = $this->baseurl . '&new=' . $data;
+ // TODO
+ // Should not use redirect and exit here
+ // Find a better way to do this.
+ // redirect($url);
+ // exit;
+ }
+
+ function is_related($query) {
+ if (parent::is_related($query)) {
+ return true;
+ }
+
+ $textlib = textlib_get_instance();
+ $repositories= get_list_of_plugins('repository');
+ foreach ($repositories as $p) {
+ if (strpos($p, $query) !== false) {
+ return true;
+ }
+ }
+ foreach (repository_instances(get_context_instance(CONTEXT_SYSTEM), null, false) as $instance) {
+ $title = $instance->name;
+ if (strpos($textlib->strtolower($title), $query) !== false) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function output_html($data, $query='') {
+ global $CFG, $USER;
+ $output = print_simple_box_start(true);
+ $namestr = get_string('name');
+ $pluginstr = get_string('plugin', 'repository');
+ $plugins = get_list_of_plugins('repository');
+ $instances = repository_instances(get_context_instance(CONTEXT_SYSTEM), null, false);
+ $alreadyplugins = array();
+ $table = new StdClass;
+ $table->head = array($namestr, $pluginstr, '');
+ $table->data = array();
+
+ foreach ($instances as $i) {
+ $row = '';
+ $row .= '<a href="' . $this->baseurl . '&edit=' . $i->id . '"><img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . get_string('edit') . '" /></a>' . "\n";
+ $row .= '<a href="' . $this->baseurl . '&delete=' . $i->id . '"><img src="' . $CFG->pixpath . '/t/delete.gif" alt="' . get_string('delete') . '" /></a>' . "\n";
+ $row .= ' <a href="' . $this->baseurl . '&hide=' . $i->id . '"><img src="' . $CFG->pixpath . '/t/' . ($i->visible ? 'hide' : 'show') . '.gif" alt="' . get_string($i->visible ? 'hide' : 'show') . '" /></a>' . "\n";
+ $table->data[] = array($i->name, $i->type, $row);
+ if (!in_array($i->type, $alreadyplugins)) {
+ $alreadyplugins[] = $i->name;
+ }
+ }
-?>
+ $output .= print_table($table, true);
+ $instancehtml = '<div><p>';
+ $addable = 0;
+ $instancehtml .= get_string('add', 'repository');
+ $instancehtml .= '</p>';
+ $addable = 0;
+ foreach ($plugins as $p) {
+ $instancehtml .= '<a href="'.$CFG->wwwroot.'/admin/repository.php?sesskey='.$USER->sesskey.'&new='.$p.'">'.$p.'</a><br/>';
+ $addable++;
+ }
+
+ if ($addable) {
+ $instancehtml .= '</div>';
+ $output .= $instancehtml;
+ }
+
+ $output .= print_simple_box_end(true);
+
+ return highlight($query, $output);
+ }
+}
<?php
+$string['apikey'] = 'API Key';
$string['repositoryname'] = 'Box.net';
$string['repositorydesc'] = 'Repository for box.net';
$string['configplugin'] = 'Box.net configuration';
class repository_boxnet extends repository{
private $box;
- public $type = 'boxnet';
public function __construct($repositoryid, $context = SITEID, $options = array()){
global $SESSION, $action;
// reset session
$reset = optional_param('reset', 0, PARAM_INT);
if(!empty($reset)) {
+ // TODO
+ // think about muliti-instance
+ // must improve!
unset($SESSION->box_token);
}
// do login
public function get_login(){
global $DB;
- if ($entry = $DB->get_record('repository', array('id'=>$this->repositoryid))) {
+ if ($entry = $DB->get_record('repository', array('id'=>$this->id))) {
$ret->username = $entry->username;
$ret->password = $entry->password;
} else {
$str .= '<form id="moodle-repo-login">';
$str .= '<input type="hidden" name="ticket" value="'.
$t['ticket'].'" />';
- $str .= '<input type="hidden" name="id" value="'.$this->repositoryid.'" />';
+ $str .= '<input type="hidden" name="id" value="'.$this->id.'" />';
$str .= '<label for="box_username">Username: <label><br/>';
$str .= '<input type="text" id="box_username" name="username" value="'.$ret->username.'" />';
$str .= '<br/>';
$e2->type = 'hidden';
$e2->name = 'repo_id';
- $e2->value = $this->repositoryid;
+ $e2->value = $this->id;
$e3->label = get_string('username', 'repository_boxnet');
$e3->id = 'box_username';
public function print_search(){
return false;
}
+ public static function has_admin_config() {
+ return true;
+ }
+ public function admin_config_form(&$mform) {
+ $strrequired = get_string('required');
+ $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'));
+ $mform->addRule('api_key', $strrequired, 'required', null, 'client');
+ }
+ public static function get_option_names(){
+ return array('api_key');
+ }
}
?>
<?php
+$string['configplugin'] = 'Flickr configureation';
$string['repositoryname'] = 'Flickr';
$string['repositorydesc'] = 'Repository for flickr.com';
$string['notitle'] = 'notitle';
class repository_flickr extends repository{
private $flickr;
public $photos;
- public $type = 'flickr';
public function __construct($repositoryid, $context = SITEID, $options = array()){
global $SESSION, $action, $CFG;
<form id="moodle-repo-login">
<label for="account">Account (Email)</label><br/>
<input type='text' name='flickrmail' id='account' />
-<input type='hidden' name='id' value='$this->repositoryid' /><br/>
+<input type='hidden' name='id' value='$this->id' /><br/>
<input type='checkbox' name='remember' id="keepid" value='true' /> <label for="keepid">Remember? </label>
<p><input type='button' onclick="repository_client.login()" value="Go" /></p>
</form>
$e3->type = 'hidden';
$e3->name = 'repo_id';
- $e3->value = $this->repositoryid;
+ $e3->value = $this->id;
$ret['l'] = array($e1, $e2, $e3);
return $ret;
}else{
EOD;
$str .= '<div id="paging">';
for($i=1; $i <= $this->photos['pages']; $i++) {
- $str .= '<a href="###" onclick="cr('.$this->repositoryid.', '.$i.', 0)">';
+ $str .= '<a href="###" onclick="cr('.$this->id.', '.$i.', 0)">';
$str .= $i;
$str .= '</a> ';
}
));
return $dir.$file;
}
+ public static function has_admin_config() {
+ return true;
+ }
+ public function admin_config_form(&$mform) {
+ $strrequired = get_string('required');
+ $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'));
+ $mform->addRule('api_key', $strrequired, 'required', null, 'client');
+ }
+ public static function get_option_names(){
+ return array('api_key');
+ }
}
*/
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once(dirname(dirname(__FILE__)).'/lib/filelib.php');
+require_once(dirname(dirname(__FILE__)).'/lib/formslib.php');
abstract class repository {
- protected $options;
- public $name;
- public $context;
- public $repositoryid;
- public $listing;
+ public $id;
+ public $context;
+ public $options;
/**
* Take an array as a parameter, which contains necessary information
* @return array the list of files, including meta infomation
*/
public function __construct($repositoryid, $contextid = SITEID, $options = array()){
- $this->repositoryid = $repositoryid;
- $this->context = get_context_instance_by_id($contextid);
- $this->options = array();
+ $this->id = $repositoryid;
+ $this->context = get_context_instance_by_id($contextid);
+ $this->options = array();
if (is_array($options)) {
- $options = array_merge(repository_get_option($repositoryid), $options);
- foreach ($options as $n => $v) {
- $this->options[$n] = $v;
- }
+ $options = array_merge($this->get_option(), $options);
+ } else {
+ $options = $this->get_option();
+ }
+ foreach ($options as $n => $v) {
+ $this->options[$n] = $v;
}
}
public function __toString() {
return 'Repository class: '.__CLASS__;
}
+
/**
* Given a URL, get a file from there.
* @param string $url the url of file
return $dir.$file;
}
- /**
- * Given a path, and perhaps a search, get a list of files.
- *
- * @param string $parent The parent path, this parameter can
- * a folder name, or a identification of folder
- * @param string $search The text will be searched.
- * @return array the list of files, including meta infomation
- */
- abstract public function get_listing($parent = '/', $search = '');
-
/**
* Print a list or return string
*
}
/**
- * Show the login screen, if required
- * This is an abstract function, it must be overriden.
- *
+ * Return data for creating ajax request
+ * @return object
*/
- abstract public function print_login();
+ public function ajax_info() {
+ global $CFG;
+ $repo = new stdclass;
+ $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;
+ }
/**
- * Show the search screen, if required
- *
- * @return null
+ * delete a repository instance
*/
- abstract public function print_search();
+ public function delete(){
+ global $DB;
+ $DB->delete_records('repository', array('id'=>$this->id));
+ return true;
+ }
+ /**
+ * Hide/Show a repository
+ * @param boolean
+ */
+ public function hide($hide = 'toggle'){
+ global $DB;
+ if ($entry = $DB->get_record('repository', array('id'=>$this->id))) {
+ if ($hide === 'toggle' ) {
+ if (!empty($entry->visible)) {
+ $entry->visible = 0;
+ } else {
+ $entry->visible = 1;
+ }
+ } else {
+ if (!empty($hide)) {
+ $entry->visible = 0;
+ } else {
+ $entry->visible = 1;
+ }
+ }
+ return $DB->update_record('repository', $entry);
+ }
+ return false;
+ }
/**
* Cache login details for repositories
global $DB;
$repository = new stdclass;
- if (!empty($this->repositoryid)) {
- $repository->id = $this->repositoryid;
+ if (!empty($this->id)) {
+ $repository->id = $this->id;
} else {
$repository->userid = $userid;
$repository->repositorytype = $this->type;
}
/**
- * Defines operations that happen occasionally on cron
+ * Save settings for repository instance
+ * $repo->set_option(array('api_key'=>'f2188bde132',
+ * 'name'=>'dongsheng'));
*
+ * @param array settings
+ * @return int Id of the record
*/
- public function cron() {
- return true;
+ 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);
+ }
+ return false;
}
-}
-/**
- * exception class for repository api
- *
- */
+ /**
+ * Get settings for repository instance
+ *
+ * @param int repository Id
+ * @return array Settings
+ */
+ 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;
+ }
+ $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);
+ }
+ }
+ }
+ if (!empty($config)) {
+ return $ret[$config];
+ } else {
+ return $ret;
+ }
+ }
-class repository_exception extends moodle_exception {
-}
+ /**
+ * Given a path, and perhaps a search, get a list of files.
+ *
+ * @param string $parent The parent path, this parameter can
+ * a folder name, or a identification of folder
+ * @param string $search The text will be searched.
+ * @return array the list of files, including meta infomation
+ */
+ abstract public function get_listing($parent = '/', $search = '');
-/**
- * Listing object describing a listing of files and directories
- */
-abstract class repository_listing {
-}
+ /**
+ * Show the login screen, if required
+ * This is an abstract function, it must be overriden.
+ *
+ */
+ abstract public function print_login();
-/**
- * Save settings for repository instance
- *
- * @param int repository Id
- * @param int from 1 to 5
- * @param array settings
- * @return int Id of the record
- */
-function repository_set_option($id, $position, $config = array()){
- global $DB;
- $repository = new stdclass;
- $position = (int)$position;
- $config = serialize($config);
- if( $position < 1 || $position > 5){
- print_error('invalidoption', 'repository', '', $position);
+ /**
+ * Show the search screen, if required
+ *
+ * @return null
+ */
+ abstract public function print_search();
+
+ public static function has_admin_config() {
+ return false;
+ }
+
+ public static function create($type, $userid, $context, $params) {
+ global $CFG, $DB;
+ $params = (array)$params;
+ require_once($CFG->dirroot . '/repository/'. $type . '/repository.class.php');
+ $classname = 'repository_' . $type;
+ if (self::has_admin_config()) {
+ $configs = self::get_option_names();
+ $options = array();
+ foreach ($configs as $config) {
+ $options[$config] = $params[$config];
+ }
+ $record->data1 = serialize($options);
+ }
+ $record = new stdclass;
+ $record->repositoryname = $params['name'];
+ $record->repositorytype = $type;
+ $record->timecreated = time();
+ $record->timemodified = time();
+ $record->contextid = $context->id;
+ $record->visible = 1;
+ $record->userid = $userid;
+ $id = $DB->insert_record('repository', $record);
+ if (!empty($id)) {
+ return $id;
+ } else {
+ return null;
+ }
}
- if ($entry = $DB->get_record('repository', array('id'=>$id))) {
- $option = 'data'.$position;
- $repository->id = $entry->id;
- $repository->$option = $config;
- return $DB->update_record('repository', $repository);
+
+ /**
+ * Defines operations that happen occasionally on cron
+ *
+ */
+ public function cron() {
+ return true;
}
- return false;
}
/**
- * Get settings for repository instance
+ * exception class for repository api
*
- * @param int repository Id
- * @return array Settings
*/
-function repository_get_option($id){
- global $DB;
- $entry = $DB->get_record('repository', array('id'=>$id));
- if (!empty($entry->visible)) {
- $ret['visible'] = 1;
- } else {
- $ret['visible'] = 0;
- }
- 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);
- }
- }
- }
- return $ret;
+
+class repository_exception extends moodle_exception {
}
+
/**
- * Get user's repositories
+ * Return repository instances
*
- * @param object context object
- * @return array repository list
+ * @param object context
+ * @param int userid
+ * @param boolean if visible == true, return visible instances only,
+ * otherwise, return all instances
+ * @return array repository instances
*/
-function repository_user_instances($context){
+function repository_instances($context, $userid = null, $visible = true){
global $DB, $CFG, $USER;
$params = array();
$sql = 'SELECT * FROM {repository} r WHERE ';
- $sql .= ' (r.userid = 0 or r.userid = ?) ';
- $params[] = $USER->id;
- if($context->id == SITEID) {
- $sql .= 'AND (r.contextid = ?)';
- $params[] = SITEID;
+ if (!empty($userid) && is_numeric($userid)) {
+ $sql .= ' (r.userid = 0 or r.userid = ?) AND ';
+ $params[] = $userid;
+ }
+ if($context->id == SYSCONTEXTID) {
+ $sql .= ' (r.contextid = ?)';
+ $params[] = SYSCONTEXTID;
} else {
- $sql .= 'AND (r.contextid = ? or r.contextid = ?)';
- $params[] = SITEID;
+ $sql .= ' (r.contextid = ? or r.contextid = ?)';
+ $params[] = SYSCONTEXTID;
$params[] = $context->id;
}
+ if($visible == true) {
+ $sql .= ' AND (r.visible = 1)';
+ }
if(!$repos = $DB->get_records_sql($sql, $params)) {
$repos = array();
}
- return $repos;
+ $ret = array();
+ foreach($repos as $repo) {
+ require_once($CFG->dirroot . '/repository/'. $repo->repositorytype
+ . '/repository.class.php');
+ $classname = 'repository_' . $repo->repositorytype;
+ $ret[] = new $classname($repo->id, $repo->contextid);
+ }
+ return $ret;
}
/**
return new $classname($instance->id, $instance->contextid);
}
-/**
- * Get list of repository plugin
- *
- * @return array repository plugin list
- */
-function repository_get_plugins(){
+function repository_static_function($plugin, $function) {
global $CFG;
- $repo = $CFG->dirroot.'/repository/';
- $ret = array();
- if($dir = opendir($repo)){
- while (false !== ($file = readdir($dir))) {
- if(is_dir($file) && $file != '.' && $file != '..'
- && file_exists($repo.$file.'/repository.class.php')){
- require_once($repo.$file.'/version.php');
- $ret[] = array('name'=>$plugin->name,
- 'version'=>$plugin->version,
- 'path'=>$repo.$file,
- 'settings'=>file_exists($repo.$file.'/settings.php'));
- }
- }
+
+ $pname = null;
+ if (is_object($plugin) || is_array($plugin)) {
+ $plugin = (object)$plugin;
+ $pname = $plugin->name;
+ } else {
+ $pname = $plugin;
}
- return $ret;
+
+ $args = func_get_args();
+ if (count($args) <= 2) {
+ $args = array();
+ }
+ else {
+ array_shift($args);
+ array_shift($args);
+ }
+
+ require_once($CFG->dirroot . '/repository/' . $plugin . '/repository.class.php');
+ return call_user_func_array(array('repository_' . $plugin, $function), $args);
}
/**
var link = document.createElement('a');
link.href = '###';
link.id = 'repo-call-$suffix-'+repo.id;
- link.innerHTML = ' '+repo.repositoryname;
+ link.innerHTML = ' '+repo.name;
link.className = 'repo-name';
link.onclick = function(){
var re = /repo-call-$suffix-(\d+)/i;
})();
EOD;
- $repos = repository_user_instances($context);
+ $repos = repository_instances($context);
foreach($repos as $repo) {
- $repo->icon = $CFG->wwwroot.'/repository/'.$repo->repositorytype.'/icon.png';
$js .= "\r\n";
- $js .= 'repository_client_'.$suffix.'.repos.push('.json_encode($repo).');'."\n";
+ $js .= 'repository_client_'.$suffix.'.repos.push('.json_encode($repo->ajax_info()).');'."\n";
}
$js .= "\r\n";
EOD;
return array('html'=>$html, 'js'=>$js, 'suffix'=>$suffix);
}
+
+final class repository_admin_form extends moodleform {
+ protected $instance;
+ protected $plugin;
+
+ public function definition() {
+ global $CFG;
+ // type of plugin, string
+ $this->plugin = $this->_customdata['plugin'];
+ $this->instance = (isset($this->_customdata['instance'])
+ && is_subclass_of($this->_customdata['instance'], 'repository'))
+ ? $this->_customdata['instance'] : null;
+
+ $mform =& $this->_form;
+ $strrequired = get_string('required');
+
+ $mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->id : 0);
+ $mform->addElement('hidden', 'new', $this->plugin);
+ $mform->addElement('hidden', 'plugin', $this->plugin);
+
+ $mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
+ $mform->addRule('name', $strrequired, 'required', null, 'client');
+
+ // let the plugin add the fields they want (either statically or not)
+ if (repository_static_function($this->plugin, 'has_admin_config')) {
+ if (!$this->instance) {
+ $result = repository_static_function($this->plugin, 'admin_config_form', $mform);
+ } else {
+ $result = $this->instance->admin_config_form($mform);
+ }
+ }
+
+ // and set the data if we have some.
+ if ($this->instance) {
+ $data = array();
+ $data['name'] = $this->instance->name;
+ foreach ($this->instance->get_option_names() as $config) {
+ $data[$config] = $this->instance->$config;
+ }
+ $this->set_data($data);
+ }
+ $this->add_action_buttons(true, get_string('submit'));
+ }
+
+ public function validation($data) {
+ global $DB;
+
+ $errors = array();
+ if ($DB->count_records('repository', array('repositoryname' => $data['name'], 'repositorytype' => $data['plugin'])) > 1) {
+ $errors = array('name' => get_string('err_uniquename', 'repository'));
+ }
+
+ $pluginerrors = array();
+ if ($this->instance) {
+ //$pluginerrors = $this->instance->admin_config_validation($data);
+ } else {
+ //$pluginerrors = repository_static_function($this->plugin, 'admin_config_validation', $data);
+ }
+ if (is_array($pluginerrors)) {
+ $errors = array_merge($errors, $pluginerrors);
+ }
+ return $errors;
+ }
+}
*/
class repository_local extends repository{
- public $type = 'local';
public function __construct($repositoryid, $context = SITEID, $options = array()){
global $SESSION, $action, $CFG;
// get the parameter from client side
// $this->context can be used here.
}
+
public function print_login($ajax = true){
global $SESSION;
// TODO
print_heading($configstr);
print_simple_box_start();
-if (!$instances = repository_user_instances($COURSE->context)) {
+if (!$instances = repository_instances($COURSE->context, $USER->id)) {
print_error('noinstances', 'repository', $CFG->wwwroot . '/user/view.php');
}
$table->data = array();
foreach ($instances as $i) {
- $path = '/repository/'.$i->repositorytype.'/settings.php';
+ $path = '/repository/'.$i->type.'/settings.php';
$settings = file_exists($CFG->dirroot.$path);
- $table->data[] = array($i->repositoryname, $i->repositorytype,
+ $table->data[] = array($i->name, $i->type,
$settings ? '<a href="'.$CFG->wwwroot.$path.'">'
.get_string('settings', 'repository').'</a>' : '');
}
// Repository Tab
if ($user->id == $USER->id) {
require_once($CFG->dirroot . '/repository/lib.php');
- if (repository_user_instances($COURSE->context)) {
+ if (repository_instances($COURSE->context, $USER->id)) {
$toprow[] = new tabobject('repositories', $CFG->wwwroot .'/user/repository.php', get_string('repositories', 'repository'));
}
}