$hide = optional_param('hide', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$sure = optional_param('sure', '', PARAM_ALPHA);
-$move = optional_param('move', '', PARAM_ALPHA);
-$type = optional_param('type', '', PARAM_ALPHA);
+$type = optional_param('type', '', PARAM_ALPHAEXT);
$context = get_context_instance(CONTEXT_SYSTEM);
-$display = true; // fall through to normal display
-
$pagename = 'repositorycontroller';
if ($edit){
$pagename = 'repositoryinstanceedit';
-}else
-if ($delete) {
+} else if ($delete) {
$pagename = 'repositorydelete';
} else if ($new) {
$pagename = 'repositoryinstancenew';
if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository_get_instance($edit);
+ //if you try to edit an instance set as readonly, display an error message
+ if ($instance->readonly) {
+ throw new repository_exception('readonlyinstance', 'repository');
+ }
$instancetype = repository_get_type_by_id($instance->typeid);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
} else if (!empty($delete)) {
admin_externalpage_print_header();
$instance = repository_get_instance($delete);
+ //if you try to delete an instance set as readonly, display an error message
+ if ($instance->readonly) {
+ throw new repository_exception('readonlyinstance', 'repository');
+ }
if ($sure) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
$string['plugin'] = 'Repository plug-ins';
$string['preview'] = 'Preview';
$string['popup'] = 'Open a popup window to login';
+$string['readonlyinstance'] = 'You cannot edit/delete a read-only instance';
$string['refresh'] = 'Refresh';
$string['removed'] = 'Repository removed';
$string['repository'] = 'Repository';
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20080826" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20080916" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
- <TABLE NAME="repository_instances" COMMENT="This table contains one entry for every configured external repository instance. " PREVIOUS="repository" NEXT="repository_instance_config">
+ <TABLE NAME="repository_instances" COMMENT="This table contains one entry for every configured external repository instance." PREVIOUS="repository" NEXT="repository_instance_config">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="typeid"/>
<FIELD NAME="username" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="contextid" NEXT="password"/>
<FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="username" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="password" NEXT="timemodified"/>
- <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated" NEXT="readonly"/>
+ <FIELD NAME="readonly" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</SENTENCES>
</STATEMENT>
</STATEMENTS>
-</XMLDB>
+</XMLDB>
\ No newline at end of file
upgrade_main_savepoint($result, 2008091000);
}
+ //Add a readonly field to the repository_instances table
+ //in order to support instance created automatically by a repository plugin
+ if ($result && $oldversion < 2008091611) {
+
+ /// Define field readonly to be added to repository_instances
+ $table = new xmldb_table('repository_instances');
+ $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timemodified');
+
+ /// Conditionally launch add field readonly
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2008091611);
+ }
+
return $result;
}
}
}
- public function __construct($repositoryid, $context = SITEID, $options = array()) {
+ public function __construct($repositoryid, $context = SITEID, $options = array(), $readonly=0) {
global $CFG;
$options['page'] = optional_param('p', 1, PARAM_INT);
- parent::__construct($repositoryid, $context, $options);
+ parent::__construct($repositoryid, $context, $options,$readonly);
$this->api_key = $this->get_option('api_key');
$this->flickr = new phpFlickr($this->api_key);
$this->flickr_account = $this->get_option('email_address');
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');
+ $mform->addRule('email_address', get_string('required'), 'required', null, 'client');
}
public static function get_instance_option_names() {
return array('api_key');
}
- public static function type_init() {
+
+ public static function plugin_init() {
//here we create a default instances for this type
+ repository_static_function('flickr_public','create', 'flickr_public', 0, get_system_context(), array('name' => 'default instance','email_address' => null),1);
+ //create(0, get_system_context(), array('name' => 'default instance'),1);
+ /*
+ $success = repository_static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform);
+ $defaultinstance = new repository ();
+ * */
}
}
$instanceoptions['name'] = $this->_typename;
repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
}
+
+ //run init function
+ repository_static_function($this->_typename,"plugin_init");
+
} else {
throw new repository_exception('existingrepository', 'repository');
}
public $id;
public $context;
public $options;
+ public $readonly;
/**
* 1. Initialize context and options
* @param integer $contextid
* @param array $options
*/
- public function __construct($repositoryid, $contextid = SITEID, $options = array()) {
+ public function __construct($repositoryid, $contextid = SITEID, $options = array(), $readonly = 0) {
$this->id = $repositoryid;
$this->context = get_context_instance_by_id($contextid);
+ $this->readonly = $readonly;
$this->options = array();
if (is_array($options)) {
$options = array_merge($this->get_option(), $options);
* @param array $params the options for this instance
* @return <type>
*/
- final public static function create($type, $userid, $context, $params) {
+ final public static function create($type, $userid, $context, $params, $readonly=0) {
global $CFG, $DB;
$params = (array)$params;
require_once($CFG->dirroot . '/repository/'. $type . '/repository.class.php');
$record->timecreated = time();
$record->timemodified = time();
$record->contextid = $context->id;
+ $record->readonly = $readonly;
$record->userid = $userid;
$id = $DB->insert_record('repository_instances', $record);
$options = array();
* a class extended from repository class, the init() for type has been placed
* into the repository.
*/
- public static function type_init(){
+ public static function plugin_init(){
}
$options['type'] = $repo->repositorytype;
$options['typeid'] = $repo->typeid;
$classname = 'repository_' . $repo->repositorytype;
- $ret[] = new $classname($repo->id, $repo->contextid, $options);
+ $ret[] = new $classname($repo->id, $repo->contextid, $options, $repo->readonly);
}
return $ret;
}
$options['typeid'] = $instance->typeid;
$options['type'] = $instance->repositorytype;
$options['name'] = $instance->name;
- return new $classname($instance->id, $instance->contextid, $options);
+ return new $classname($instance->id, $instance->contextid, $options, $instance->readonly);
}
/**
foreach ($instances as $i) {
$settings = '';
- $settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
- $delete = '<a href="' . $baseurl . '&type='.$typename.'&delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
+ $delete = '';
+ if (!$i->readonly) {
+ $settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
+ $delete .= '<a href="' . $baseurl . '&type='.$typename.'&delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
+ }
$type = repository_get_type_by_id($i->typeid);
$table->data[] = array($i->name, $type->get_readablename(), $delete, $settings);
$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) {
if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository_get_instance($edit);
+ //if you try to edit an instance set as readonly, display an error message
+ if ($instance->readonly) {
+ throw new repository_exception('readonlyinstance', 'repository');
+ }
$instancetype = repository_get_type_by_id($instance->typeid);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
} else if (!empty($delete)) {
// admin_externalpage_print_header();
$instance = repository_get_instance($delete);
+ //if you try to delete an instance set as readonly, display an error message
+ if ($instance->readonly) {
+ throw new repository_exception('readonlyinstance', 'repository');
+ }
if ($sure) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2008091500; // YYYYMMDD = date of the last version bump
+ $version = 2008091611; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20080916)'; // Human-friendly version name