Skip to content

Commit

Permalink
"MDL-13766, improve user instances list"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Dec 2, 2009
1 parent 064e333 commit 5363905
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 188 deletions.
3 changes: 2 additions & 1 deletion lang/en_utf8/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
$string['noresult'] = 'No search result';
$string['operation'] = 'Operation';
$string['openpicker'] = 'Choose a file...';
$string['personalrepositories'] = 'Personal repositories';
$string['personalrepositories'] = 'Avaiable repository instances';
$string['plugin'] = 'Repository plug-ins';
$string['pluginerror'] = 'Errors in repository plugin.';
$string['preview'] = 'Preview';
Expand Down Expand Up @@ -122,6 +122,7 @@
$string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
$string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context';
$string['wrongcontext'] = 'You cannot access to this context';
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
$string['ziped'] = 'Compress folder successfully';
35 changes: 26 additions & 9 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@ class repository_type {
* Return if the instance is visible in a context
* TODO: check if the context visibility has been overwritten by the plugin creator
* (need to create special functions to be overvwritten in repository class)
* @param objet $contextlevel - context level
* @param objet $context - context
* @return boolean
*/
public function get_contextvisibility($contextlevel) {
public function get_contextvisibility($context) {
global $USER;

if ($contextlevel == CONTEXT_COURSE) {
if ($context->contextlevel == CONTEXT_COURSE) {
return $this->_options['enablecourseinstances'];
}

if ($contextlevel == CONTEXT_USER) {
if ($context->contextlevel == CONTEXT_USER) {
return $this->_options['enableuserinstances'];
}

Expand Down Expand Up @@ -577,7 +578,7 @@ public static function get_editable_types($context = null) {
foreach ($types as $type) {
$instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
if (!empty($instanceoptionnames)) {
if ($type->get_contextvisibility($context->contextlevel)) {
if ($type->get_contextvisibility($context)) {
$editabletypes[]=$type;
}
}
Expand Down Expand Up @@ -1007,6 +1008,7 @@ public static function display_instances_list($context, $typename = null) {
} else {
$baseurl = $CFG->httpswwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&sesskey=' . sesskey();
}
$url = new moodle_url($baseurl);

$namestr = get_string('name');
$pluginstr = get_string('plugin', 'repository');
Expand Down Expand Up @@ -1036,9 +1038,24 @@ public static function display_instances_list($context, $typename = null) {
foreach ($instances as $i) {
$settings = '';
$delete = '';
$settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
if (!$i->readonly) {
$delete .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";

$type = repository::get_type_by_id($i->options['typeid']);

if ($type->get_contextvisibility($context)) {
if (!$i->readonly) {

$url->param('type', $i->options['type']);
$url->param('edit', $i->id);
$link = html_link::make($url->out(), $settingsstr);
$settings .= $OUTPUT->link($link);

$url->remove_params('edit');
$url->param('delete', $i->id);
$link = html_link::make($url->out(), $deletestr);
$delete .= $OUTPUT->link($link);

$url->remove_params('type');
}
}

$type = repository::get_type_by_id($i->options['typeid']);
Expand Down Expand Up @@ -1161,7 +1178,7 @@ public function is_visible() {

if ($type->get_visible()) {
//if the instance is unique so it's visible, otherwise check if the instance has a enabled context
if (empty($instanceoptions) || $type->get_contextvisibility($this->context->contextlevel)) {
if (empty($instanceoptions) || $type->get_contextvisibility($this->context)) {
return true;
}
}
Expand Down
Loading

0 comments on commit 5363905

Please sign in to comment.