Skip to content

Commit

Permalink
MDL-15109 glossary dml conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 8, 2008
1 parent ea05eeb commit ae8c356
Show file tree
Hide file tree
Showing 27 changed files with 561 additions and 631 deletions.
7 changes: 4 additions & 3 deletions mod/glossary/approve.php
Expand Up @@ -13,11 +13,11 @@
print_error('invalidcoursemodule');
}

if (! $course = get_record("course", "id", $cm->course)) {
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf');
}

if (! $glossary = get_record("glossary", "id", $cm->instance)) {
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary');
}

Expand All @@ -26,11 +26,12 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:approve', $context);

$newentry = new object();
$newentry->id = $eid;
$newentry->approved = 1;
$newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0

if (! update_record("glossary_entries", $newentry)) {
if (! $DB->update_record("glossary_entries", $newentry)) {
print_error('cantupdateglossary', 'glossary');
} else {
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id);
Expand Down
70 changes: 28 additions & 42 deletions mod/glossary/backuplib.php
Expand Up @@ -29,13 +29,12 @@
//----------------------------------------------------------------------------------

function glossary_backup_mods($bf,$preferences) {

global $CFG;
global $CFG, $DB;

$status = true;

//Iterate over glossary table
$glossaries = get_records ("glossary","course",$preferences->backup_course,"mainglossary");
$glossaries = $DB->get_records ("glossary", array("course"=>$preferences->backup_course), "mainglossary");
if ($glossaries) {
foreach ($glossaries as $glossary) {
if (backup_mod_selected($preferences,'glossary',$glossary->id)) {
Expand All @@ -47,11 +46,10 @@ function glossary_backup_mods($bf,$preferences) {
}

function glossary_backup_one_mod($bf,$preferences,$glossary) {

global $CFG;
global $CFG, $DB;

if (is_numeric($glossary)) {
$glossary = get_record('glossary','id',$glossary);
$glossary = $DB->get_record('glossary', array('id'=>$glossary));
}

$status = true;
Expand Down Expand Up @@ -100,12 +98,11 @@ function glossary_backup_one_mod($bf,$preferences,$glossary) {

//Backup glossary_categories and entries_categories contents (executed from glossary_backup_mods)
function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) {

global $CFG;
global $CFG, $DB;

$status = true;

$glossary_categories = get_records("glossary_categories","glossaryid",$glossary,"id");
$glossary_categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary),"id");
//If there is categories
if ($glossary_categories) {
$status =fwrite ($bf,start_tag("CATEGORIES",4,true));
Expand Down Expand Up @@ -137,12 +134,11 @@ function backup_glossary_categories ($bf,$preferences,$glossary, $userinfo) {

//Backup entries_categories contents (executed from backup_glossary_categories)
function backup_glossary_entries_categories ($bf,$preferences,$categoryid) {

global $CFG;
global $CFG, $DB;

$status = true;

$entries = get_records("glossary_entries_categories","categoryid",$categoryid);
$entries = $DB->get_records("glossary_entries_categories", array("categoryid"=>$categoryid));
if ($entries) {
$status =fwrite ($bf,start_tag("ENTRIES",6,true));
foreach ($entries as $entry) {
Expand All @@ -157,12 +153,11 @@ function backup_glossary_entries_categories ($bf,$preferences,$categoryid) {

//Backup glossary_entries contents (executed from glossary_backup_mods)
function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {

global $CFG;
global $CFG, $DB;

$status = true;

$glossary_entries = get_records("glossary_entries","glossaryid",$glossary,"id");
$glossary_entries = $DB->get_records("glossary_entries", array("glossaryid"=>$glossary),"id");
//If there is entries
if ($glossary_entries) {
$dumped_entries = 0;
Expand Down Expand Up @@ -219,12 +214,11 @@ function backup_glossary_entries ($bf,$preferences,$glossary, $userinfo) {

//Backup glossary_comments contents (executed from backup_glossary_entries)
function backup_glossary_comments ($bf,$preferences,$entryid) {

global $CFG;
global $CFG, $DB;

$status = true;

$comments = get_records("glossary_comments","entryid",$entryid);
$comments = $DB->get_records("glossary_comments", array("entryid"=>$entryid));
if ($comments) {
$status =fwrite ($bf,start_tag("COMMENTS",6,true));
foreach ($comments as $comment) {
Expand All @@ -245,12 +239,11 @@ function backup_glossary_comments ($bf,$preferences,$entryid) {

//Backup glossary_ratings contents (executed from backup_glossary_entries)
function backup_glossary_ratings ($bf,$preferences,$entryid) {

global $CFG;
global $CFG, $DB;

$status = true;

$ratings = get_records("glossary_ratings","entryid",$entryid);
$ratings = $DB->get_records("glossary_ratings", array("entryid"=>$entryid));
if ($ratings) {
$status =fwrite ($bf,start_tag("RATINGS",6,true));
foreach ($ratings as $rating) {
Expand All @@ -270,12 +263,11 @@ function backup_glossary_ratings ($bf,$preferences,$entryid) {

//Backup glossary_alias contents (executed from backup_glossary_entries)
function backup_glossary_aliases ($bf,$preferences,$entryid) {

global $CFG;
global $CFG, $DB;

$status = true;

$aliases = get_records("glossary_alias","entryid",$entryid);
$aliases = $DB->get_records("glossary_alias", array("entryid"=>$entryid));
if ($aliases) {
$status =fwrite ($bf,start_tag("ALIASES",6,true));
foreach ($aliases as $alias) {
Expand All @@ -293,7 +285,6 @@ function backup_glossary_aliases ($bf,$preferences,$entryid) {
//Backup glossary files because we've selected to backup user info
//or current entry is a teacher entry
function backup_glossary_files($bf,$preferences,$glossary,$entry) {

global $CFG;

$status = true;
Expand Down Expand Up @@ -399,33 +390,28 @@ function glossary_encode_content_links ($content,$preferences) {

//Returns an array of glossaries id
function glossary_ids ($course) {
global $DB;

global $CFG;

return get_records_sql ("SELECT a.id, a.course
FROM {$CFG->prefix}glossary a
WHERE a.course = '$course'");
return $DB->get_records_sql ("SELECT a.id, a.course
FROM {glossary} a
WHERE a.course = ?", array($course));
}

//Returns an array of glossary_answers id
function glossary_entries_ids_by_course ($course) {
global $DB;

global $CFG;

return get_records_sql ("SELECT s.id , s.glossaryid
FROM {$CFG->prefix}glossary_entries s,
{$CFG->prefix}glossary a
WHERE a.course = '$course' AND
s.glossaryid = a.id");
return $DB->get_records_sql ("SELECT s.id , s.glossaryid
FROM {glossary_entries} s, {glossary} a
WHERE a.course = ? AND s.glossaryid = a.id", array($course));
}

//Returns an array of glossary_answers id
function glossary_entries_ids_by_instance ($instanceid) {
global $DB;

global $CFG;

return get_records_sql ("SELECT s.id , s.glossaryid
FROM {$CFG->prefix}glossary_entries s
WHERE s.glossaryid = $instanceid");
return $DB->get_records_sql ("SELECT s.id , s.glossaryid
FROM {glossary_entries} s
WHERE s.glossaryid = ?", array($instanceid));
}
?>
38 changes: 19 additions & 19 deletions mod/glossary/comment.php
Expand Up @@ -28,20 +28,20 @@
* Add new comment
*/
function glossary_comment_add() {
global $USER;
global $USER, $DB;

$eid = optional_param('eid', 0, PARAM_INT); // Entry ID

if (!$entry = get_record('glossary_entries', 'id', $eid)) {
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$eid))) {
print_error('invalidentry');
}
if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
print_error('invalidid', 'glossary');
}
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
print_error('invalidcoursemodule');
}
if (!$course = get_record('course', 'id', $cm->course)) {
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}

Expand All @@ -59,7 +59,7 @@ function glossary_comment_add() {
redirect("comments.php?id=$cm->id&eid=$entry->id");
}

if ($data = $mform->get_data()) {
if ($data = $mform->get_data(false)) {
trusttext_after_edit($data->entrycomment, $context);

$newcomment = new object();
Expand All @@ -69,7 +69,7 @@ function glossary_comment_add() {
$newcomment->timemodified = time();
$newcomment->userid = $USER->id;

if (!$newcomment->id = insert_record('glossary_comments', $newcomment)) {
if (!$newcomment->id = $DB->insert_record('glossary_comments', $newcomment)) {
print_error('cannotinsertcomment');
} else {
add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newcomment->id", $cm->id);
Expand All @@ -88,24 +88,24 @@ function glossary_comment_add() {
* Deleting existing comments
*/
function glossary_comment_delete() {
global $USER;
global $USER, $DB;

$cid = optional_param('cid', 0, PARAM_INT); // Comment ID
$confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation

if (!$comment = get_record('glossary_comments', 'id', $cid)) {
if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
print_error('invalidcomment');
}
if (!$entry = get_record('glossary_entries', 'id', $comment->entryid)) {
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
print_error('invalidentry');
}
if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
print_error('invalidid', 'glossary');
}
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
print_error('invalidcoursemodule');
}
if (!$course = get_record('course', 'id', $cm->course)) {
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}

Expand All @@ -119,7 +119,7 @@ function glossary_comment_delete() {
}

if (data_submitted() and $confirm) {
delete_records('glossary_comments','id', $cid);
$DB->delete_records('glossary_comments', array('id'=>$cid));
add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&eid=$entry->id", "$comment->id",$cm->id);
redirect("comments.php?id=$cm->id&eid=$entry->id");

Expand All @@ -142,23 +142,23 @@ function glossary_comment_delete() {
* Edit existing comments
*/
function glossary_comment_edit() {
global $CFG, $USER;
global $CFG, $USER, $DB;

$cid = optional_param('cid', 0, PARAM_INT); // Comment ID

if (!$comment = get_record('glossary_comments', 'id', $cid)) {
if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
print_error('invalidcomment');
}
if (!$entry = get_record('glossary_entries', 'id', $comment->entryid)) {
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
print_error('invalidentry');
}
if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
print_error('invalidid', 'glossary');
}
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
print_error('invalidcoursemodule');
}
if (!$course = get_record('course', 'id', $cm->course)) {
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}

Expand All @@ -179,7 +179,7 @@ function glossary_comment_edit() {
trusttext_prepare_edit($comment->entrycomment, $comment->format, can_use_html_editor(), $context);
$mform->set_data(array('cid'=>$cid, 'action'=>'edit', 'entrycomment'=>$comment->entrycomment, 'format'=>$comment->format));

if ($data = $mform->get_data()) {
if ($data = $mform->get_data(false)) {
trusttext_after_edit($data->entrycomment, $context);

$updatedcomment = new object();
Expand All @@ -188,7 +188,7 @@ function glossary_comment_edit() {
$updatedcomment->format = $data->format;
$updatedcomment->timemodified = time();

if (!update_record('glossary_comments', $updatedcomment)) {
if (!$DB->update_record('glossary_comments', $updatedcomment)) {
print_error('cannotupdatecomment');
} else {
add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$updatedcomment->id",$cm->id);
Expand Down
10 changes: 4 additions & 6 deletions mod/glossary/comments.php
Expand Up @@ -7,21 +7,19 @@
$id = required_param('id', PARAM_INT); // Course Module ID
$eid = required_param('eid', PARAM_INT); // Entry ID

global $USER, $CFG;

if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('invalidcoursemodule');
}

if (! $course = get_record("course", "id", $cm->course)) {
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf');
}

if (! $glossary = get_record("glossary", "id", $cm->instance)) {
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidcousemodule');
}

if (! $entry = get_record("glossary_entries", "id", $eid)) {
if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) {
print_error('invalidentry');
}

Expand Down Expand Up @@ -61,7 +59,7 @@
print_heading("<a href=\"comment.php?action=add&amp;eid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>");
}

if ($comments = get_records("glossary_comments","entryid",$entry->id,"timemodified ASC")) {
if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) {
foreach ($comments as $comment) {
glossary_print_comment($course, $cm, $glossary, $entry, $comment);
echo '<br />';
Expand Down

0 comments on commit ae8c356

Please sign in to comment.