From: skodak Date: Mon, 2 Jun 2008 20:15:51 +0000 (+0000) Subject: MDL-14679 towards blocks conversion X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f28f2d9022de092a1568ac2a9f40e44f0833c025;p=moodle.git MDL-14679 towards blocks conversion --- diff --git a/blocks/glossary_random/block_glossary_random.php b/blocks/glossary_random/block_glossary_random.php index 6fa57e51a2..0923d2d74b 100644 --- a/blocks/glossary_random/block_glossary_random.php +++ b/blocks/glossary_random/block_glossary_random.php @@ -13,7 +13,7 @@ class block_glossary_random extends block_base { } function specialization() { - global $CFG, $COURSE; + global $CFG, $COURSE, $DB; $this->course = $COURSE; // load userdefined title and make sure it's never empty @@ -35,8 +35,8 @@ class block_glossary_random extends block_base { if (time() > $this->config->nexttime) { // place glossary concept and definition in $pref->cache - if (!$numberofentries = count_records('glossary_entries','glossaryid',$this->config->glossary, - 'approved',1)) { + if (!$numberofentries = $DB->count_records('glossary_entries', + array('glossaryid'=>$this->config->glossary, 'approved'=>1))) { $this->config->cache = get_string('noentriesyet','block_glossary_random'); $this->instance_config_commit(); } @@ -72,11 +72,10 @@ class block_glossary_random extends block_base { break; } - if ($entry = get_records_sql(' SELECT concept, definition, format '. - ' FROM '.$CFG->prefix.'glossary_entries'. - ' WHERE glossaryid = '.$this->config->glossary. - ' AND approved = 1 '. - 'ORDER BY timemodified '.$SORT, $limitfrom, $limitnum)) { + if ($entry = $DB->get_records_sql("SELECT concept, definition, format + FROM {glossary_entries} + WHERE glossaryid = ? AND approved = 1 + ORDER BY timemodified $SORT", array($this->config->glossary), $limitfrom, $limitnum)) { $entry = reset($entry); @@ -153,7 +152,7 @@ class block_glossary_random extends block_base { } function get_content() { - global $USER, $CFG, $COURSE; + global $USER, $CFG, $COURSE, $DB; if (empty($this->config->glossary)) { $this->content->text = get_string('notyetconfigured','block_glossary_random'); @@ -166,7 +165,7 @@ class block_glossary_random extends block_base { if ($this->course->id == $COURSE->id) { $course = $COURSE; } else { - $course = get_record('course', 'id', $this->course->id); + $course = $DB->get_record('course', array('id'=>$this->course->id)); } require_once($CFG->dirroot.'/course/lib.php'); diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php index e894deae2f..2086c49f11 100755 --- a/blocks/html/block_html.php +++ b/blocks/html/block_html.php @@ -65,16 +65,16 @@ class block_html extends block_base { * @return boolean **/ function decode_content_links_caller($restore) { - global $CFG; + global $CFG, $DB; - if ($restored_blocks = get_records_select("backup_ids","table_name = 'block_instance' AND backup_code = $restore->backup_unique_code AND new_id > 0", "", "new_id")) { + if ($restored_blocks = $DB->get_records_select("backup_ids", "table_name = 'block_instance' AND backup_code = ? AND new_id > 0", array($restore->backup_unique_code), "", "new_id")) { $restored_blocks = implode(',', array_keys($restored_blocks)); $sql = "SELECT bi.* - FROM {$CFG->prefix}block_instance bi - JOIN {$CFG->prefix}block b ON b.id = bi.blockid + FROM {block_instance} bi + JOIN {block} b ON b.id = bi.blockid WHERE b.name = 'html' AND bi.id IN ($restored_blocks)"; - if ($instances = get_records_sql($sql)) { + if ($instances = $DB->get_records_sql($sql)) { foreach ($instances as $instance) { $blockobject = block_instance('html', $instance); $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text); diff --git a/blocks/mentees/block_mentees.php b/blocks/mentees/block_mentees.php index 87a85e40cf..cf645fe4e1 100755 --- a/blocks/mentees/block_mentees.php +++ b/blocks/mentees/block_mentees.php @@ -20,21 +20,19 @@ class block_mentees extends block_base { } function get_content() { - - global $CFG, $USER; + global $CFG, $USER, $DB; + if ($this->content !== NULL) { return $this->content; } // get all the mentees, i.e. users you have a direct assignment to - if ($usercontexts = get_records_sql("SELECT c.instanceid, c.instanceid, u.firstname, u.lastname - FROM {$CFG->prefix}role_assignments ra, - {$CFG->prefix}context c, - {$CFG->prefix}user u - WHERE ra.userid = $USER->id - AND ra.contextid = c.id - AND c.instanceid = u.id - AND c.contextlevel = ".CONTEXT_USER)) { + if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, u.firstname, u.lastname + FROM {role_assignments} ra, {context} c, {user} u + WHERE ra.userid = ? + AND ra.contextid = c.id + AND c.instanceid = u.id + AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) { $this->content->text = '