MDL-15402: modify repository_get_instances() in order to be easier to use
This commit is contained in:
@@ -43,8 +43,10 @@ $string['manageurl'] = 'Manage';
|
||||
$string['manageuserrepository'] = 'Manage individual repository';
|
||||
$string['nopermissiontoaccess'] = 'No permission to access this repository';
|
||||
$string['noenter'] = 'Nothing entered';
|
||||
$string['notyourinstances'] = 'You can not view/edit repository instances of another user';
|
||||
$string['operation'] = 'Operation';
|
||||
$string['openpicker'] = 'Choose a file...';
|
||||
$string['personalrepositories'] = 'Personal repositories';
|
||||
$string['plugin'] = 'Repository plug-ins';
|
||||
$string['preview'] = 'Preview';
|
||||
$string['removed'] = 'Repository removed';
|
||||
|
||||
+18
-18
@@ -1,4 +1,5 @@
|
||||
<?php // $Id$
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
@@ -350,7 +351,7 @@ class repository_type {
|
||||
global $DB;
|
||||
|
||||
//delete all instances of this type
|
||||
$instances = repository_get_instances(null,null,false,$this->_typename);
|
||||
$instances = repository_get_instances(array(),null,false,$this->_typename);
|
||||
foreach($instances as $instance){
|
||||
$instance->delete();
|
||||
}
|
||||
@@ -916,14 +917,14 @@ function repository_check_context($ctx_id){
|
||||
* @global object $DB
|
||||
* @global object $CFG
|
||||
* @global object $USER
|
||||
* @param object $context
|
||||
* @param object $contexts contexts for which the instances are set
|
||||
* @param integer $userid
|
||||
* @param boolean $onlyvisible if visible == true, return visible instances only,
|
||||
* otherwise, return all instances
|
||||
* @param string $type a type name to retrieve
|
||||
* @return array repository instances
|
||||
*/
|
||||
function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null, $nositeinstances=false){
|
||||
function repository_get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null){
|
||||
global $DB, $CFG, $USER;
|
||||
$params = array();
|
||||
$sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE ';
|
||||
@@ -932,20 +933,19 @@ function repository_get_instances($context=null, $userid = null, $onlyvisible =
|
||||
$sql .= ' AND (i.userid = 0 or i.userid = ?)';
|
||||
$params[] = $userid;
|
||||
}
|
||||
if (!empty($context)){
|
||||
if($context->id == SYSCONTEXTID) {
|
||||
$sql .= ' AND (i.contextid = ?)';
|
||||
$params[] = SYSCONTEXTID;
|
||||
foreach ($contexts as $context) {
|
||||
if (empty($firstcontext)){
|
||||
$firstcontext = true;
|
||||
$sql .= ' AND ((i.contextid = ?)';
|
||||
} else {
|
||||
if ($nositeinstances) {
|
||||
$sql .= ' AND i.contextid = ?';
|
||||
} else {
|
||||
$sql .= ' AND (i.contextid = ? or i.contextid = ?)';
|
||||
$params[] = SYSCONTEXTID;
|
||||
}
|
||||
$params[] = $context->id;
|
||||
$sql .= ' OR (i.contextid = ?)';
|
||||
}
|
||||
$params[] = $context->id;
|
||||
}
|
||||
if ($firstcontext) {
|
||||
$sql .=')';
|
||||
}
|
||||
|
||||
if($onlyvisible == true) {
|
||||
$sql .= ' AND (r.visible = 1)';
|
||||
}
|
||||
@@ -1853,7 +1853,7 @@ return _client;
|
||||
})();
|
||||
EOD;
|
||||
|
||||
$repos = repository_get_instances($context);
|
||||
$repos = repository_get_instances(array($context,get_system_context()));
|
||||
foreach($repos as $repo) {
|
||||
$js .= "\r\n";
|
||||
$js .= 'repository_client_'.$suffix.'.repos.push('.json_encode($repo->ajax_info()).');'."\n";
|
||||
@@ -2049,7 +2049,7 @@ function repository_display_instances_list($context, $typename = null){
|
||||
$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&sesskey=' . sesskey();
|
||||
|
||||
}
|
||||
|
||||
|
||||
$namestr = get_string('name');
|
||||
$pluginstr = get_string('plugin', 'repository');
|
||||
$settingsstr = get_string('settings');
|
||||
@@ -2061,7 +2061,7 @@ function repository_display_instances_list($context, $typename = null){
|
||||
//want to display only visible instances, but for every type types. The repository_get_instances()
|
||||
//third parameter displays only visible type. The fifth parameter is a trick that return
|
||||
//instances of the $context + systemcontext.
|
||||
$instances = repository_get_instances($context,null,!$admin,$typename, !$admin);
|
||||
$instances = repository_get_instances(array($context),null,!$admin,$typename);
|
||||
$instancesnumber = count($instances);
|
||||
$alreadyplugins = array();
|
||||
$table = new StdClass;
|
||||
|
||||
@@ -10,7 +10,7 @@ $new = optional_param('new', '', PARAM_FORMAT);
|
||||
$delete = optional_param('delete', 0, PARAM_INT);
|
||||
$sure = optional_param('sure', '', PARAM_ALPHA);
|
||||
$contextid = optional_param('contextid', 0, PARAM_INT);
|
||||
|
||||
//$userid = optional_param('userid', 0, PARAM_INT);
|
||||
$display = true; // fall through to normal display
|
||||
|
||||
if ($edit){
|
||||
@@ -40,6 +40,14 @@ if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$pagename = get_string("personalrepositories",'repository');
|
||||
//is the user looking at its own repository instances
|
||||
if ($USER->id != $context->instanceid){
|
||||
print_error('notyourinstances', 'repository');
|
||||
}
|
||||
$user = $USER;
|
||||
}
|
||||
|
||||
$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $contextid . '&sesskey='. sesskey();
|
||||
|
||||
@@ -68,10 +76,17 @@ if (!empty($course)) {
|
||||
'type' => 'misc');
|
||||
$navlinks[] = array('name' => $pagename,
|
||||
'link' => null,
|
||||
'type' => 'misc');
|
||||
$title = $pagename;
|
||||
'type' => 'misc');
|
||||
$fullname = $course->fullname;
|
||||
}
|
||||
else {
|
||||
$fullname = fullname($user);
|
||||
$strrepos = get_string('repositories', 'repository');
|
||||
$navlinks[] = array('name' => $fullname, 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id, 'type' => 'misc');
|
||||
$navlinks[] = array('name' => $strrepos, 'link' => null, 'type' => 'misc');
|
||||
}
|
||||
|
||||
$title = $pagename;
|
||||
$navigation = build_navigation($navlinks);
|
||||
|
||||
//display page header
|
||||
|
||||
+4
-3
@@ -251,9 +251,10 @@
|
||||
// Repository Tab
|
||||
if (!empty($user) and $user->id == $USER->id) {
|
||||
require_once($CFG->dirroot . '/repository/lib.php');
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
if (repository_get_instances($coursecontext, $USER->id)) {
|
||||
$toprow[] = new tabobject('repositories', $CFG->wwwroot .'/user/repository.php', get_string('repositories', 'repository'));
|
||||
//$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$usercontext = get_context_instance(CONTEXT_USER,$user->id);
|
||||
if (repository_get_instances($usercontext, $USER->id)) {
|
||||
$toprow[] = new tabobject('repositories', $CFG->wwwroot .'/repository/manage_instances.php?contextid='.$usercontext->id, get_string('repositories', 'repository'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user