// display the edit form for this instance
$mform = new repository_admin_form('', array('plugin' => $plugin, 'instance' => $repositorytype));
$fromform = $mform->get_data();
+
+ //detect if we create a new type without config (in this case if don't want to display a setting page during creation)
+ $createnewtype = false;
+ if (!empty($new)) {
+ $adminconfignames = repository_static_function($new, 'get_admin_option_names');
+ $createnewtype = empty($adminconfignames);
+ }
// end setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
exit;
- } else if (!empty($fromform) || (!empty($new) && !repository_static_function($new,"has_admin_config"))){
+ } else if (!empty($fromform) || $createnewtype){
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
//display instances list and creation form
if ($edit){
- if (repository_static_function($edit,"has_instance_config")
- || repository_static_function($edit,"has_multiple_instances")){
+ if (repository_static_function($edit,"has_multiple_instances")){
repository_display_instances_list(get_context_instance(CONTEXT_SYSTEM), $edit);
}
}
foreach (repository_get_types()
as $repositorytype)
{
- //display setup page for plugins with: general options or instance options or multiple instances
- if (repository_static_function($repositorytype->get_typename(), 'has_admin_config')
- || repository_static_function($repositorytype->get_typename(), 'has_instance_config')
+ //display setup page for plugins with: general options or multiple instances
+ $adminconfignames = repository_static_function($repositorytype->get_typename(), 'get_admin_option_names');
+ if (!empty($adminconfignames)
|| repository_static_function($repositorytype->get_typename(), 'has_multiple_instances')) {
$ADMIN->add('repositorysettings',
new admin_externalpage('repositorysettings'.$repositorytype->get_typename(),
$updowncount=1;
foreach ($instances as $i) {
$settings = '';
- //display edit link only if you can config the type or its instances
- if ( repository_static_function($i->get_typename(), 'has_admin_config')
- || repository_static_function($i->get_typename(), 'has_instance_config')
+ //display edit link only if you can config the type or if it has multiple instances
+ $adminconfignames = repository_static_function($i->get_typename(), 'get_admin_option_names');
+ if ( !empty($adminconfignames)
|| repository_static_function($i->get_typename(), 'has_multiple_instances')) {
$settings .= '<a href="' . $this->baseurl . '&edit=' . $i->get_typename() . '">'
. $settingsstr .'</a>' . "\n";
}
}
- public static function has_admin_config() {
- return true;
- }
-
- public static function has_instance_config() {
- return false;
- }
-
public static function has_multiple_instances() {
return false;
}
+++ /dev/null
-<?php //$Id$
-require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
-require_once($CFG->libdir.'/formslib.php');
-require_once(dirname(dirname(__FILE__)) . '/lib.php');
-require_once(dirname(__FILE__) . '/repository.class.php');
-
-$repositoryid = optional_param('id', 1, PARAM_INT);
-$config = optional_param('config', 1, PARAM_INT);
-$course = optional_param('course', SITEID, PARAM_INT);
-if (! $course = $DB->get_record("course", array("id"=>$course))) {
- print_error('invalidcourseid');
-}
-$user = $USER;
-$fullname = fullname($user);
-$strplugin = get_string('repositoryname', 'repository_boxnet');
-$returnurl = $CFG->wwwroot.'/repository/boxnet/settings.php?id='.$repositoryid;
-
-require_login($course, false);
-
-class boxnet_user_form extends moodleform {
- private $repositoryid;
- private $userid;
- public function definition() {
- global $CFG;
- $box = new repository_boxnet($this->_customdata['repositoryid']);
- $ret = $box->get_login();
- $mform =& $this->_form;
- $mform->addElement('text', 'name', get_string('username', 'repository_boxnet'), array('size'=>'30', 'value'=>$ret->username));
- $mform->addElement('passwordunmask', 'passwd', get_string('password', 'repository_boxnet'), array('size'=>'30', 'value'=>$ret->password));
- $mform->addElement('hidden', 'id', $this->_customdata['repositoryid']);
- $mform->addElement('hidden', 'user', $this->_customdata['userid']);
- $mform->setType('id', PARAM_INT);
- $this->add_action_buttons(true, get_string('savechanges'));
- }
-}
-
-$navlinks[] = array('name' => $fullname, 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id, 'type' => 'misc');
-$navlinks[] = array('name' => get_string('repository', 'repository'), 'link' => $CFG->wwwroot . '/user/repository.php', 'type' => 'misc');
-$navlinks[] = array('name' => $strplugin, 'link' => null, 'type' => 'misc');
-
-$navigation = build_navigation($navlinks);
-
-print_header("$course->fullname: $fullname: $strplugin", $course->fullname,
- $navigation, "", "", true, " ", navmenu($course));
-
-$instance = repository_get_instance($repositoryid);
-$mform = new boxnet_user_form('', array('repositoryid' => $repositoryid, 'userid' => $user->id));
-$box = new repository_boxnet();
-if ($data = data_submitted()){
- if (!confirm_sesskey()) {
- print_error('confirmsesskeybad', '', $baseurl);
- }
- $box = new repository_boxnet($repositoryid);
- $ret = $box->store_login($data->name, $data->passwd, $user->id);
- if ($ret) {
- redirect($returnurl, get_string('saved', 'repository_boxnet'));
- } else {
- print_error('cannotsave', 'repository_boxnet', $returnurl);
- }
- exit;
-} else {
- print_heading(get_string('configplugin', 'repository_boxnet'));
- print_simple_box_start();
- $mform->display();
- print_simple_box_end();
-}
+++ /dev/null
-<?php // $Id$
-
-/////////////////////////////////////////////////////////////////////////////////
-/// Code fragment to define the version of repository plug-in (box.net)
-/////////////////////////////////////////////////////////////////////////////////
-
-$plugin->name = "Box.net Repository";
-$plugin->version = 2008062701; // The current plug-in version (Date: YYYYMMDDXX)
-$plugin->requires = 2007101509; // The current plug-in version (Date: YYYYMMDDXX)
-$plugin->cron = 3600; // Period for cron to check this plug-in (secs)
-
-?>
));
return $dir.$file;
}
- public static function has_admin_config() {
- return true;
- }
public static function has_multiple_instances() {
return false;
}
- public static function has_instance_config() {
- return false;
- }
-
public function instance_config_form(&$mform) {
$mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr'));
$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
if (empty($secret)) {
$secret = '';
}
-/*
- $noticetext = get_string('notice', 'repository_flickr');
- //$noticetext = 'a[';
- //var_dump($noticetext);
- if (strpos($noticetext, '[')==0) {
- $mform->addElement('static', 'notice', '<strong>'.get_string('notice', 'repository').'</strong>', '<i>'.$noticetext.'</i>');
- }
- * */
-
-
$strrequired = get_string('required');
$mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr'), array('value'=>$api_key,'size' => '40'));
return $dir.$file;
}
- public static function has_admin_config() {
- return true;
- }
public static function has_multiple_instances() {
return true;
}
- public static function has_instance_config() {
- return true;
- }
-
public function instance_config_form(&$mform) {
$mform->addElement('text', 'email_address', get_string('emailaddress', 'repository_flickr_public'));
$mform->addRule('email_address', get_string('required'), 'required', null, 'client');
//set options attribut
$this->_options = array();
+ $options = repository_static_function($typename,'get_admin_option_names');
//check that the type can be setup
- if (repository_static_function($typename,"has_admin_config")) {
- $options = repository_static_function($typename,'get_admin_option_names');
+ if (!empty($options)) {
//set the type options
foreach ($options as $config) {
if (array_key_exists($config,$typeoptions)) {
//save the options in DB
$this->update_options();
- //if the plugin type has no multiple and no instance config so it wont
+ //if the plugin type has no multiple so it wont
//be possible for the administrator to create a instance
//in this case we need to create an instance
- if (!repository_static_function($this->_typename,"has_instance_config")
- && !repository_static_function($this->_typename,"has_multiple_instances")) {
+ if (!repository_static_function($this->_typename,"has_multiple_instances")) {
$instanceoptions = array();
$instanceoptions['name'] = $this->_typename;
repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
$record->userid = $userid;
$id = $DB->insert_record('repository_instances', $record);
$options = array();
- if (call_user_func($classname . '::has_instance_config')) {
+ if (call_user_func($classname . '::has_multiple_instances')) {
$configs = call_user_func($classname . '::get_instance_option_names');
foreach ($configs as $config) {
$options[$config] = $params[$config];
}
- public static function add_unremovable_instances(){
-
- }
-
/**
- * Return true if the plugin type has at least one general option field
- * By default: false
- * @return boolean
+ * Edit/Create Admin Settings Moodle form
+ * @param object $ Moodle form (passed by reference)
*/
- public static function has_admin_config() {
- return false;
+ public function admin_config_form(&$mform) {
}
-
- /**
- * Return true if a plugin instance has at least one config field
- * By default: false
- * @return boolean
+
+ /**
+ * Edit/Create Instance Settings Moodle form
+ * @param object $ Moodle form (passed by reference)
*/
- public static function has_instance_config() {
- return false;
+ public function instance_config_form(&$mform) {
}
/**
$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_instance_config')) {
- if (!$this->instance) {
- $result = repository_static_function($this->plugin, 'instance_config_form', $mform);
- } else {
- $result = $this->instance->instance_config_form($mform);
- }
+ //add fields
+ if (!$this->instance) {
+ $result = repository_static_function($this->plugin, 'instance_config_form', $mform);
+ } else {
+ $result = $this->instance->instance_config_form($mform);
}
-
+
// and set the data if we have some.
if ($this->instance) {
$data = array();
$mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->get_typename() : 0);
$mform->addElement('hidden', 'new', $this->plugin);
$mform->addElement('hidden', 'plugin', $this->plugin);
- // let the plugin add the fields they want (either statically or not)
- if (repository_static_function($this->plugin, 'has_admin_config')) {
- if (!$this->instance) {
+ // let the plugin add its specific fields
+ if (!$this->instance) {
$result = repository_static_function($this->plugin, 'admin_config_form', $mform);
} else {
$classname = 'repository_' . $this->instance->get_typename();
$result = call_user_func(array($classname,'admin_config_form'),$mform);
- }
}
// and set the data if we have some.