Just tidying as I read it. Main problem with it now is that huge block of JS

This commit is contained in:
moodler 2008-09-15 07:56:26 +00:00
parent c65dd2fe99
commit 7a3b93c18a

View file

@ -228,8 +228,7 @@ class repository_type {
$instanceoptions['name'] = $this->_typename; $instanceoptions['name'] = $this->_typename;
repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions); repository_static_function($this->_typename, 'create', $this->_typename, 0, get_system_context(), $instanceoptions);
} }
} } else {
else {
throw new repository_exception('existingrepository', 'repository'); throw new repository_exception('existingrepository', 'repository');
} }
} }
@ -310,10 +309,10 @@ class repository_type {
*/ */
public function move_order($move) { public function move_order($move) {
global $DB; global $DB;
//retrieve all types
$types = repository_get_types();
//retrieve this type into the returned array $types = repository_get_types(); // retrieve all types
/// retrieve this type into the returned array
$i = 0; $i = 0;
while (!isset($indice) && $i<count($types)) { while (!isset($indice) && $i<count($types)) {
if ($types[$i]->get_typename() == $this->_typename) { if ($types[$i]->get_typename() == $this->_typename) {
@ -322,7 +321,7 @@ class repository_type {
$i++; $i++;
} }
//retrieve adjacent indice /// retrieve adjacent indice
switch ($move) { switch ($move) {
case "up": case "up":
$adjacentindice = $indice - 1; $adjacentindice = $indice - 1;
@ -735,6 +734,7 @@ abstract class repository {
*/ */
public function set_option($options = array()) { public function set_option($options = array()) {
global $DB; global $DB;
if (!empty($options['name'])) { if (!empty($options['name'])) {
$r = new object(); $r = new object();
$r->id = $this->id; $r->id = $this->id;
@ -931,8 +931,10 @@ class repository_exception extends moodle_exception {
*/ */
function repository_check_context($ctx_id) { function repository_check_context($ctx_id) {
global $USER; global $USER;
$context = get_context_instance_by_id($ctx_id); $context = get_context_instance_by_id($ctx_id);
$level = $context->contextlevel; $level = $context->contextlevel;
if ($level == CONTEXT_COURSE) { if ($level == CONTEXT_COURSE) {
if (!has_capability('moodle/course:view', $context)) { if (!has_capability('moodle/course:view', $context)) {
return false; return false;
@ -983,13 +985,16 @@ function repository_get_editable_types(){
*/ */
function repository_get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null) { function repository_get_instances($contexts=array(), $userid = null, $onlyvisible = true, $type=null) {
global $DB, $CFG, $USER; global $DB, $CFG, $USER;
$params = array(); $params = array();
$sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE '; $sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE ';
$sql .= 'i.typeid = r.id '; $sql .= 'i.typeid = r.id ';
if (!empty($userid) && is_numeric($userid)) { if (!empty($userid) && is_numeric($userid)) {
$sql .= ' AND (i.userid = 0 or i.userid = ?)'; $sql .= ' AND (i.userid = 0 or i.userid = ?)';
$params[] = $userid; $params[] = $userid;
} }
foreach ($contexts as $context) { foreach ($contexts as $context) {
if (empty($firstcontext)) { if (empty($firstcontext)) {
$firstcontext = true; $firstcontext = true;
@ -999,6 +1004,7 @@ function repository_get_instances($contexts=array(), $userid = null, $onlyvisibl
} }
$params[] = $context->id; $params[] = $context->id;
} }
if ($firstcontext) { if ($firstcontext) {
$sql .=')'; $sql .=')';
} }
@ -1006,18 +1012,20 @@ function repository_get_instances($contexts=array(), $userid = null, $onlyvisibl
if ($onlyvisible == true) { if ($onlyvisible == true) {
$sql .= ' AND (r.visible = 1)'; $sql .= ' AND (r.visible = 1)';
} }
if (isset($type)) { if (isset($type)) {
$sql .= ' AND (r.type = ?)'; $sql .= ' AND (r.type = ?)';
$params[] = $type; $params[] = $type;
} }
$sql .= ' order by r.sortorder, i.name'; $sql .= ' order by r.sortorder, i.name';
if (!$repos = $DB->get_records_sql($sql, $params)) { if (!$repos = $DB->get_records_sql($sql, $params)) {
$repos = array(); $repos = array();
} }
$ret = array(); $ret = array();
foreach ($repos as $repo) { foreach ($repos as $repo) {
require_once($CFG->dirroot . '/repository/'. $repo->repositorytype require_once($CFG->dirroot . '/repository/'. $repo->repositorytype.'/repository.class.php');
. '/repository.class.php');
$options['visible'] = $repo->visible; $options['visible'] = $repo->visible;
$options['name'] = $repo->name; $options['name'] = $repo->name;
$options['type'] = $repo->repositorytype; $options['type'] = $repo->repositorytype;
@ -2216,7 +2224,6 @@ final class repository_admin_form extends moodleform {
} }
$this->add_action_buttons(true, get_string('save','repository')); $this->add_action_buttons(true, get_string('save','repository'));
} }
} }
@ -2239,7 +2246,6 @@ function repository_display_instances_list($context, $typename = null){
$output .= "</h2></div>"; $output .= "</h2></div>";
} else { } else {
$baseurl = $CFG->httpswwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&amp;sesskey=' . sesskey(); $baseurl = $CFG->httpswwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&amp;sesskey=' . sesskey();
} }
$namestr = get_string('name'); $namestr = get_string('name');
@ -2255,11 +2261,14 @@ function repository_display_instances_list($context, $typename = null){
$instances = repository_get_instances(array($context),null,!$admin,$typename); $instances = repository_get_instances(array($context),null,!$admin,$typename);
$instancesnumber = count($instances); $instancesnumber = count($instances);
$alreadyplugins = array(); $alreadyplugins = array();
$table = new StdClass; $table = new StdClass;
$table->head = array($namestr, $pluginstr, $deletestr, $settingsstr); $table->head = array($namestr, $pluginstr, $deletestr, $settingsstr);
$table->align = array('left', 'left', 'center','center'); $table->align = array('left', 'left', 'center','center');
$table->data = array(); $table->data = array();
$updowncount = 1; $updowncount = 1;
foreach ($instances as $i) { foreach ($instances as $i) {
$settings = ''; $settings = '';
$settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n"; $settings .= '<a href="' . $baseurl . '&amp;type='.$typename.'&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
@ -2300,10 +2309,8 @@ function repository_display_instances_list($context, $typename = null){
} }
} }
$instancehtml .= '</ul>'; $instancehtml .= '</ul>';
}
//create a unique type of instance } else if (repository_static_function($typename, 'has_multiple_instances')) { //create a unique type of instance
else {
if (repository_static_function($typename, 'has_multiple_instances')){
$addable = 1; $addable = 1;
$instancehtml .= "<form action='".$baseurl."&amp;new=".$typename."' method='post'> $instancehtml .= "<form action='".$baseurl."&amp;new=".$typename."' method='post'>
<p style='text-align:center'><input type='submit' value='".get_string('createinstance', 'repository')."'/></p> <p style='text-align:center'><input type='submit' value='".get_string('createinstance', 'repository')."'/></p>