mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-15114 resource mod converted
This commit is contained in:
parent
1b81b0a412
commit
5f5cd33c1d
6 changed files with 61 additions and 71 deletions
|
@ -18,12 +18,12 @@
|
||||||
|
|
||||||
//This function executes all the backup procedure about this mod
|
//This function executes all the backup procedure about this mod
|
||||||
function resource_backup_mods($bf,$preferences) {
|
function resource_backup_mods($bf,$preferences) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$status = true;
|
$status = true;
|
||||||
|
|
||||||
////Iterate over resource table
|
////Iterate over resource table
|
||||||
$resources = get_records ("resource","course",$preferences->backup_course,"id");
|
$resources = $DB->get_records ("resource", array("course"=>$preferences->backup_course),"id");
|
||||||
if ($resources) {
|
if ($resources) {
|
||||||
foreach ($resources as $resource) {
|
foreach ($resources as $resource) {
|
||||||
if (backup_mod_selected($preferences,'resource',$resource->id)) {
|
if (backup_mod_selected($preferences,'resource',$resource->id)) {
|
||||||
|
@ -35,11 +35,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function resource_backup_one_mod($bf,$preferences,$resource) {
|
function resource_backup_one_mod($bf,$preferences,$resource) {
|
||||||
|
global $CFG, $DB;
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
if (is_numeric($resource)) {
|
if (is_numeric($resource)) {
|
||||||
$resource = get_record('resource','id',$resource);
|
$resource = $DB->get_record('resource', array('id'=>$resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = true;
|
$status = true;
|
||||||
|
@ -124,12 +123,11 @@
|
||||||
|
|
||||||
//Returns an array of resources id
|
//Returns an array of resources id
|
||||||
function resource_ids ($course) {
|
function resource_ids ($course) {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
global $CFG;
|
return $DB->get_records_sql("SELECT a.id, a.course
|
||||||
|
FROM {resource} a
|
||||||
return get_records_sql ("SELECT a.id, a.course
|
WHERE a.course = ?", array($course));
|
||||||
FROM {$CFG->prefix}resource a
|
|
||||||
WHERE a.course = '$course'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resource_backup_files($bf,$preferences,$resource) {
|
function resource_backup_files($bf,$preferences,$resource) {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
// using the functions defined in lib/ddllib.php
|
// using the functions defined in lib/ddllib.php
|
||||||
|
|
||||||
function xmldb_resource_upgrade($oldversion=0) {
|
function xmldb_resource_upgrade($oldversion=0) {
|
||||||
|
|
||||||
global $CFG, $THEME, $DB;
|
global $CFG, $THEME, $DB;
|
||||||
|
|
||||||
$result = true;
|
$result = true;
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
//Williams, Stronk7, Martin D
|
//Williams, Stronk7, Martin D
|
||||||
|
|
||||||
function resource_filter($courseid, $text) {
|
function resource_filter($courseid, $text) {
|
||||||
|
global $CFG, $DB;
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
// Trivial-cache - keyed on $cachedcourseid
|
// Trivial-cache - keyed on $cachedcourseid
|
||||||
static $nothingtodo;
|
static $nothingtodo;
|
||||||
|
@ -38,17 +37,15 @@
|
||||||
* link to the top resource first.
|
* link to the top resource first.
|
||||||
*/
|
*/
|
||||||
$resource_sql = "SELECT r.id, r.name
|
$resource_sql = "SELECT r.id, r.name
|
||||||
FROM {$CFG->prefix}resource r,
|
FROM {resource} r, {course_modules} cm, {modules} m
|
||||||
{$CFG->prefix}course_modules cm,
|
WHERE m.name = 'resource' AND
|
||||||
{$CFG->prefix}modules m
|
cm.module = m.id AND
|
||||||
WHERE m.name = 'resource' AND
|
cm.visible = 1 AND
|
||||||
cm.module = m.id AND
|
r.id = cm.instance AND
|
||||||
cm.visible = 1 AND
|
cm.course = ?
|
||||||
r.id = cm.instance AND
|
ORDER BY CHAR_LENGTH(r.name) DESC, cm.section ASC";
|
||||||
cm.course = {$courseid}
|
|
||||||
ORDER BY CHAR_LENGTH(r.name) DESC, cm.section ASC;";
|
|
||||||
|
|
||||||
if (!$resources = get_records_sql($resource_sql) ){
|
if (!$resources = $DB->get_records_sql($resource_sql, array($courseid)) ){
|
||||||
$nothingtodo = true;
|
$nothingtodo = true;
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ class resource_base {
|
||||||
* @param cmid integer, the current course module id - not set for new resources
|
* @param cmid integer, the current course module id - not set for new resources
|
||||||
*/
|
*/
|
||||||
function resource_base($cmid=0) {
|
function resource_base($cmid=0) {
|
||||||
|
global $CFG, $COURSE, $DB;
|
||||||
|
|
||||||
global $CFG, $COURSE;
|
|
||||||
$this->navlinks = array();
|
$this->navlinks = array();
|
||||||
|
|
||||||
if ($cmid) {
|
if ($cmid) {
|
||||||
|
@ -42,11 +42,11 @@ class resource_base {
|
||||||
print_error("Course Module ID was incorrect");
|
print_error("Course Module ID was incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->course = get_record("course", "id", $this->cm->course)) {
|
if (! $this->course = $DB->get_record("course", array("id"=>$this->cm->course))) {
|
||||||
print_error("Course is misconfigured");
|
print_error("Course is misconfigured");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->resource = get_record("resource", "id", $this->cm->instance)) {
|
if (! $this->resource = $DB->get_record("resource", array("id"=>$this->cm->instance))) {
|
||||||
print_error("Resource ID was incorrect");
|
print_error("Resource ID was incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +80,7 @@ class resource_base {
|
||||||
*/
|
*/
|
||||||
function display_course_blocks_start() {
|
function display_course_blocks_start() {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG, $USER, $THEME;
|
||||||
global $USER;
|
|
||||||
global $THEME;
|
|
||||||
|
|
||||||
require_once($CFG->libdir.'/blocklib.php');
|
require_once($CFG->libdir.'/blocklib.php');
|
||||||
require_once($CFG->libdir.'/pagelib.php');
|
require_once($CFG->libdir.'/pagelib.php');
|
||||||
|
@ -151,9 +149,7 @@ class resource_base {
|
||||||
* Finish displaying the resource with the course blocks
|
* Finish displaying the resource with the course blocks
|
||||||
*/
|
*/
|
||||||
function display_course_blocks_end() {
|
function display_course_blocks_end() {
|
||||||
|
global $CFG, $THEME;
|
||||||
global $CFG;
|
|
||||||
global $THEME;
|
|
||||||
|
|
||||||
$PAGE = $this->PAGE;
|
$PAGE = $this->PAGE;
|
||||||
$pageblocks = blocks_setup($PAGE);
|
$pageblocks = blocks_setup($PAGE);
|
||||||
|
@ -299,8 +295,10 @@ function resource_delete_instance($id) {
|
||||||
|
|
||||||
|
|
||||||
function resource_user_outline($course, $user, $mod, $resource) {
|
function resource_user_outline($course, $user, $mod, $resource) {
|
||||||
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
global $DB;
|
||||||
AND action='view' AND info='$resource->id'", "time ASC")) {
|
|
||||||
|
if ($logs = $DB->get_records("log", array('userid'=>$user->id, 'module'=>'resource',
|
||||||
|
'action'=>'view', 'info'=>$resource->id), "time ASC")) {
|
||||||
|
|
||||||
$numviews = count($logs);
|
$numviews = count($logs);
|
||||||
$lastlog = array_pop($logs);
|
$lastlog = array_pop($logs);
|
||||||
|
@ -316,10 +314,10 @@ function resource_user_outline($course, $user, $mod, $resource) {
|
||||||
|
|
||||||
|
|
||||||
function resource_user_complete($course, $user, $mod, $resource) {
|
function resource_user_complete($course, $user, $mod, $resource) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
if ($logs = $DB->get_records("log", array('userid'=>$user->id, 'module'=>'resource',
|
||||||
AND action='view' AND info='$resource->id'", "time ASC")) {
|
'action'=>'view', 'info'=>$resource->id), "time ASC")) {
|
||||||
$numviews = count($logs);
|
$numviews = count($logs);
|
||||||
$lastlog = array_pop($logs);
|
$lastlog = array_pop($logs);
|
||||||
|
|
||||||
|
@ -347,12 +345,11 @@ function resource_get_coursemodule_info($coursemodule) {
|
||||||
///
|
///
|
||||||
/// See get_array_of_activities() in course/lib.php
|
/// See get_array_of_activities() in course/lib.php
|
||||||
///
|
///
|
||||||
|
global $CFG, $DB;
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
$info = NULL;
|
$info = NULL;
|
||||||
|
|
||||||
if ($resource = get_record("resource", "id", $coursemodule->instance, '', '', '', '', 'id, popup, reference, type, name')) {
|
if ($resource = $DB->get_record("resource", array("id"=>$coursemodule->instance), 'id, popup, reference, type, name')) {
|
||||||
$info = new object();
|
$info = new object();
|
||||||
$info->name = $resource->name;
|
$info->name = $resource->name;
|
||||||
if (!empty($resource->popup)) {
|
if (!empty($resource->popup)) {
|
||||||
|
@ -568,7 +565,7 @@ function resource_get_post_actions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function resource_renamefiles($course, $wdir, $oldname, $name) {
|
function resource_renamefiles($course, $wdir, $oldname, $name) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$status = '<p align=\"center\"><strong>'.get_string('affectedresources', 'resource').':</strong><ul>';
|
$status = '<p align=\"center\"><strong>'.get_string('affectedresources', 'resource').':</strong><ul>';
|
||||||
$updates = false;
|
$updates = false;
|
||||||
|
@ -577,30 +574,29 @@ function resource_renamefiles($course, $wdir, $oldname, $name) {
|
||||||
$new = trim($wdir.'/'.$name, '/');
|
$new = trim($wdir.'/'.$name, '/');
|
||||||
|
|
||||||
$sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
|
$sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
|
||||||
FROM {$CFG->prefix}resource r,
|
FROM {resource} r, {course_modules} cm, {modules} m
|
||||||
{$CFG->prefix}course_modules cm,
|
WHERE r.course = :courseid
|
||||||
{$CFG->prefix}modules m
|
AND m.name = 'resource'
|
||||||
WHERE r.course = '{$course->id}'
|
AND cm.module = m.id
|
||||||
AND m.name = 'resource'
|
AND cm.instance = r.id
|
||||||
AND cm.module = m.id
|
AND (r.type = 'file' OR r.type = 'directory')
|
||||||
AND cm.instance = r.id
|
AND (r.reference LIKE :old1 OR r.reference = :old2)";
|
||||||
AND (r.type = 'file' OR r.type = 'directory')
|
$params = array('courseid'=>$course->id, 'old1'=>"{$old}/%", 'old2'=>$old);
|
||||||
AND (r.reference LIKE '{$old}/%' OR r.reference = '{$old}')";
|
if ($resources = $DB->get_records_sql($sql, $params)) {
|
||||||
if ($resources = get_records_sql($sql)) {
|
|
||||||
foreach ($resources as $resource) {
|
foreach ($resources as $resource) {
|
||||||
$r = new object();
|
$r = new object();
|
||||||
$r->id = $resource->id;
|
$r->id = $resource->id;
|
||||||
$r->reference = '';
|
$r->reference = '';
|
||||||
if ($resource->reference == $old) {
|
if ($resource->reference == $old) {
|
||||||
$r->reference = addslashes($new);
|
$r->reference = $new;
|
||||||
} else {
|
} else {
|
||||||
$r->reference = addslashes(preg_replace('|^'.preg_quote($old, '|').'/|', $new.'/', $resource->reference));
|
$r->reference = preg_replace('|^'.preg_quote($old, '|').'/|', $new.'/', $resource->reference);
|
||||||
}
|
}
|
||||||
if ($r->reference !== '') {
|
if ($r->reference !== '') {
|
||||||
$updates = true;
|
$updates = true;
|
||||||
$status .= "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference ==> $r->reference</li>";
|
$status .= "<li><a href=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->cmid\" target=\"_blank\">$resource->name</a>: $resource->reference ==> $r->reference</li>";
|
||||||
if (!empty($CFG->resource_autofilerename)) {
|
if (!empty($CFG->resource_autofilerename)) {
|
||||||
if (!update_record('resource', $r)) {
|
if (!$DB->update_record('resource', $r)) {
|
||||||
print_error("Error updating resource with ID $r->id.");
|
print_error("Error updating resource with ID $r->id.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -618,7 +614,7 @@ function resource_renamefiles($course, $wdir, $oldname, $name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function resource_delete_warning($course, $files) {
|
function resource_delete_warning($course, $files) {
|
||||||
global $CFG;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$found = array();
|
$found = array();
|
||||||
|
|
||||||
|
@ -626,15 +622,15 @@ function resource_delete_warning($course, $files) {
|
||||||
$files[$key] = trim($file, '/');
|
$files[$key] = trim($file, '/');
|
||||||
}
|
}
|
||||||
$sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
|
$sql = "SELECT r.id, r.reference, r.name, cm.id AS cmid
|
||||||
FROM {$CFG->prefix}resource r,
|
FROM {resource} r,
|
||||||
{$CFG->prefix}course_modules cm,
|
{course_modules} cm,
|
||||||
{$CFG->prefix}modules m
|
{modules} m
|
||||||
WHERE r.course = '{$course->id}'
|
WHERE r.course = ?
|
||||||
AND m.name = 'resource'
|
AND m.name = 'resource'
|
||||||
AND cm.module = m.id
|
AND cm.module = m.id
|
||||||
AND cm.instance = r.id
|
AND cm.instance = r.id
|
||||||
AND (r.type = 'file' OR r.type = 'directory')";
|
AND (r.type = 'file' OR r.type = 'directory')";
|
||||||
if ($resources = get_records_sql($sql)) {
|
if ($resources = $DB->get_records_sql($sql, array($course->id))) {
|
||||||
foreach ($resources as $resource) {
|
foreach ($resources as $resource) {
|
||||||
if ($resource->reference == '') {
|
if ($resource->reference == '') {
|
||||||
continue; // top shared directory does not prevent anything
|
continue; // top shared directory does not prevent anything
|
||||||
|
|
|
@ -45,9 +45,9 @@
|
||||||
$inpopup = optional_param ('inpopup', 0, PARAM_BOOL);
|
$inpopup = optional_param ('inpopup', 0, PARAM_BOOL);
|
||||||
|
|
||||||
/// Fetch some records from DB
|
/// Fetch some records from DB
|
||||||
$course = get_record ('course', 'id', $courseid);
|
$course = $DB->get_record ('course', array('id'=>$courseid));
|
||||||
$cm = get_coursemodule_from_id('resource', $cmid);
|
$cm = get_coursemodule_from_id('resource', $cmid);
|
||||||
$resource = get_record ('resource', 'id', $cm->instance);
|
$resource = $DB->get_record ('resource', array('id'=>$cm->instance));
|
||||||
|
|
||||||
/// Get some needed strings
|
/// Get some needed strings
|
||||||
$strdeploy = get_string('deploy','resource');
|
$strdeploy = get_string('deploy','resource');
|
||||||
|
@ -73,9 +73,9 @@
|
||||||
|
|
||||||
/// Security Constraints (sesskey and isteacheredit)
|
/// Security Constraints (sesskey and isteacheredit)
|
||||||
if (!confirm_sesskey()) {
|
if (!confirm_sesskey()) {
|
||||||
error(get_string('confirmsesskeybad', 'error'));
|
print_error('confirmsesskeybad', 'error');
|
||||||
} else if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
} else if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
|
||||||
error(get_string('onlyeditingteachers', 'error'));
|
print_error('onlyeditingteachers', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
$r = optional_param('r', 0, PARAM_INT); // Resource
|
$r = optional_param('r', 0, PARAM_INT); // Resource
|
||||||
|
|
||||||
if ($r) { // Two ways to specify the resource
|
if ($r) { // Two ways to specify the resource
|
||||||
if (! $resource = get_record('resource', 'id', $r)) {
|
if (! $resource = $DB->get_record('resource', array('id'=>$r))) {
|
||||||
print_error('Resource ID was incorrect');
|
print_error('Resource ID was incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,14 @@
|
||||||
print_error('Course Module ID was incorrect');
|
print_error('Course Module ID was incorrect');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $resource = get_record('resource', 'id', $cm->instance)) {
|
if (! $resource = $DB->get_record('resource', array('id'=>$cm->instance))) {
|
||||||
print_error('Resource ID was incorrect');
|
print_error('Resource ID was incorrect');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print_error('No valid parameters!!');
|
print_error('No valid parameters!!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $course = get_record('course', 'id', $cm->course)) {
|
if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
|
||||||
print_error('Incorrect course id');
|
print_error('Incorrect course id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue