mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-14679 converted some count_records
This commit is contained in:
parent
a5d424df7c
commit
c7da43571b
@ -110,18 +110,18 @@
|
||||
echo '<div class="fitemtitle"><label>'.get_string("statistics")."<br />(".get_string("notpublic").')'.'</label></div>';
|
||||
echo '<div class="felement ftext">';
|
||||
|
||||
$count = count_records('course')-1;
|
||||
$count = $DB->count_records('course')-1;
|
||||
echo get_string("courses").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"courses\" value=\"$count\" />\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('user', 'deleted', 0);
|
||||
$count = $DB->count_records('user', array('deleted'=>0));
|
||||
echo get_string("users").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"users\" value=\"$count\" />\n";
|
||||
echo '<br />';
|
||||
|
||||
// total number of role assignments
|
||||
$count = count_records('role_assignments');
|
||||
$count = $DB->count_records('role_assignments');
|
||||
echo get_string('roleassignments', 'role').": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"roleassignments\" value=\"$count\" />\n";
|
||||
echo '<br />';
|
||||
@ -129,29 +129,29 @@
|
||||
// first find all distinct roles with mod/course:update
|
||||
// please change the name and strings to something appropriate to reflect the new data collected
|
||||
$sql = "SELECT COUNT(DISTINCT u.id)
|
||||
FROM {$CFG->prefix}role_capabilities rc,
|
||||
{$CFG->prefix}role_assignments ra,
|
||||
{$CFG->prefix}user u
|
||||
WHERE (rc.capability = 'moodle/course:update' or rc.capability='moodle/site:doanything')
|
||||
FROM {role_capabilities} rc,
|
||||
{role_assignments} ra,
|
||||
{user} u
|
||||
WHERE (rc.capability = 'moodle/course:update' or rc.capability='moodle/site:doanything')
|
||||
AND rc.roleid = ra.roleid
|
||||
AND u.id = ra.userid";
|
||||
|
||||
$count = count_records_sql($sql);
|
||||
$count = $DB->count_records_sql($sql);
|
||||
echo get_string("teachers").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"courseupdaters\" value=\"$count\" />\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('forum_posts');
|
||||
$count = $DB->count_records('forum_posts');
|
||||
echo get_string("posts", 'forum').": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"posts\" value=\"$count\" />\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('question');
|
||||
$count = $DB->count_records('question');
|
||||
echo get_string("questions", 'quiz').": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"questions\" value=\"$count\" />\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('resource');
|
||||
$count = $DB->count_records('resource');
|
||||
echo get_string("modulenameplural", "resource").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"resources\" value=\"$count\" />\n";
|
||||
echo '</div>';
|
||||
|
@ -194,7 +194,7 @@ class block_admin extends block_list {
|
||||
require_once($CFG->dirroot.'/enrol/authorize/const.php');
|
||||
$paymenturl = '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?course='.$course->id.'">'.get_string('payments').'</a> ';
|
||||
if (has_capability('enrol/authorize:managepayments', $context)) {
|
||||
if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
|
||||
if ($cnt = $DB->count_records('enrol_authorize', array('status'=>AN_STATUS_AUTH, 'courseid'=>$course->id))) {
|
||||
$paymenturl .= '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH.'&course='.$course->id.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class block_course_list extends block_list {
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
global $THEME, $CFG, $USER;
|
||||
global $THEME, $CFG, $USER, $DB;
|
||||
|
||||
if($this->content !== NULL) {
|
||||
return $this->content;
|
||||
@ -62,7 +62,7 @@ class block_course_list extends block_list {
|
||||
|
||||
$categories = get_categories("0"); // Parent = 0 ie top-level categories only
|
||||
if ($categories) { //Check we have categories
|
||||
if (count($categories) > 1 || (count($categories) == 1 && count_records('course') > 200)) { // Just print top level category links
|
||||
if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links
|
||||
foreach ($categories as $category) {
|
||||
$linkcss = $category->visible ? "" : " class=\"dimmed\" ";
|
||||
$this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">" . format_string($category->name) . "</a>";
|
||||
|
@ -631,7 +631,7 @@
|
||||
* get the count of viewable entries, easiest way is to count blog_fetch_entries
|
||||
* this is used for print_paging_bar
|
||||
* this is not ideal, but because of the UNION in the sql in blog_fetch_entries,
|
||||
* it is hard to use count_records_sql
|
||||
* it is hard to use $DB->count_records_sql
|
||||
*/
|
||||
function get_viewable_entry_count($postid='', $fetchlimit=10,
|
||||
$fetchstart='', $filtertype='', $filterselect='', $tagid='',
|
||||
|
@ -104,7 +104,7 @@
|
||||
|
||||
/// Print headings
|
||||
|
||||
$numcategories = count_records("course_categories");
|
||||
$numcategories = $DB->count_records("course_categories");
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strcategories = get_string("categories");
|
||||
|
@ -142,7 +142,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
|
||||
}
|
||||
|
||||
// Print headings
|
||||
$numcategories = count_records("course_categories");
|
||||
$numcategories = $DB->count_records("course_categories");
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strcategories = get_string("categories");
|
||||
|
@ -52,7 +52,7 @@ class course_reset_form extends moodleform {
|
||||
if ($allmods = $DB->get_records('modules') ) {
|
||||
foreach ($allmods as $mod) {
|
||||
$modname = $mod->name;
|
||||
if (!count_records($modname, 'course', $COURSE->id)) {
|
||||
if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
|
||||
continue; // skip mods with no instances
|
||||
}
|
||||
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
||||
|
@ -219,7 +219,7 @@
|
||||
if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
|
||||
print_heading_block(get_string('mycourses'));
|
||||
print_my_moodle();
|
||||
} else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
|
||||
} else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
|
||||
// admin should not see list of courses when there are too many of them
|
||||
print_heading_block(get_string('availablecourses'));
|
||||
print_courses(0);
|
||||
|
@ -2481,6 +2481,7 @@ class admin_setting_courselist_frontpage extends admin_setting {
|
||||
}
|
||||
|
||||
function load_choices() {
|
||||
global $DB;
|
||||
if (is_array($this->choices)) {
|
||||
return true;
|
||||
}
|
||||
@ -2489,7 +2490,7 @@ class admin_setting_courselist_frontpage extends admin_setting {
|
||||
FRONTPAGECATEGORYNAMES => get_string('frontpagecategorynames'),
|
||||
FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'),
|
||||
'none' => get_string('none'));
|
||||
if ($this->name == 'frontpage' and count_records('course') > FRONTPAGECOURSELIMIT) {
|
||||
if ($this->name == 'frontpage' and $DB->count_records('course') > FRONTPAGECOURSELIMIT) {
|
||||
unset($this->choices[FRONTPAGECOURSELIST]);
|
||||
}
|
||||
return true;
|
||||
|
@ -100,9 +100,9 @@ class eventslib_test extends UnitTestCase {
|
||||
* Tests the installation of event handlers from file
|
||||
*/
|
||||
function test__events_update_definition__install() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbcount = count_records('events_handlers', 'handlermodule', 'unittest');
|
||||
$dbcount = $DB->count_records('events_handlers', array('handlermodule'=>'unittest'));
|
||||
$handlers = array();
|
||||
require($CFG->libdir.'/simpletest/fixtures/events.php');
|
||||
$filecount = count($handlers);
|
||||
@ -113,8 +113,10 @@ class eventslib_test extends UnitTestCase {
|
||||
* Tests the uninstallation of event handlers from file
|
||||
*/
|
||||
function test__events_update_definition__uninstall() {
|
||||
global $DB;
|
||||
|
||||
events_uninstall('unittest');
|
||||
$this->assertEqual(0, count_records('events_handlers', 'handlermodule', 'unittest'), 'All handlers should be uninstalled: %s');
|
||||
$this->assertEqual(0, count_records('events_handlers', array('handlermodule'=>'unittest')), 'All handlers should be uninstalled: %s');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,19 +88,21 @@ class mnet_peer {
|
||||
}
|
||||
|
||||
function delete() {
|
||||
global $DB;
|
||||
|
||||
if ($this->deleted) return true;
|
||||
|
||||
$users = count_records('user','mnethostid', $this->id);
|
||||
$users = $DB->count_records('user', array('mnethostid'=>$this->id));
|
||||
if ($users > 0) {
|
||||
$this->deleted = 1;
|
||||
}
|
||||
|
||||
$actions = count_records('mnet_log','hostid', $this->id);
|
||||
$actions = $DB->count_records('mnet_log', array('hostid'=>$this->id));
|
||||
if ($actions > 0) {
|
||||
$this->deleted = 1;
|
||||
}
|
||||
|
||||
$obj = delete_records('mnet_rpc2host', 'host_id', $this->id);
|
||||
$obj = $DB->delete_records('mnet_rpc2host', array('host_id'=>$this->id));
|
||||
|
||||
$this->delete_all_sessions();
|
||||
|
||||
@ -108,27 +110,29 @@ class mnet_peer {
|
||||
// provides a foreign key, then we can delete the record. Otherwise, we
|
||||
// just mark it as deleted.
|
||||
if (0 == $this->deleted) {
|
||||
delete_records('mnet_host', "id", $this->id);
|
||||
$DB->delete_records('mnet_host', array("id"=>$this->id));
|
||||
} else {
|
||||
$this->commit();
|
||||
}
|
||||
}
|
||||
|
||||
function count_live_sessions() {
|
||||
global $DB;
|
||||
$obj = $this->delete_expired_sessions();
|
||||
return count_records('mnet_session','mnethostid', $this->id);
|
||||
return $DB->count_records('mnet_session', array('mnethostid'=>$this->id));
|
||||
}
|
||||
|
||||
function delete_expired_sessions() {
|
||||
global $DB;
|
||||
$now = time();
|
||||
return delete_records_select('mnet_session', " mnethostid = '{$this->id}' AND expires < '$now' ");
|
||||
return $DB->delete_records_select('mnet_session', " mnethostid = ? AND expires < ? ", array($this->id, $now));
|
||||
}
|
||||
|
||||
function delete_all_sessions() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
// TODO: Expires each PHP session individually
|
||||
// $sessions = get_records('mnet_session', 'mnethostid', $this->id);
|
||||
$sessions = get_records('mnet_session', 'mnethostid', $this->id);
|
||||
$sessions = $DB->get_records('mnet_session', array('mnethostid'=>$this->id));
|
||||
|
||||
if (count($sessions) > 0 && file_exists($CFG->dirroot.'/auth/mnet/auth.php')) {
|
||||
require_once($CFG->dirroot.'/auth/mnet/auth.php');
|
||||
@ -136,7 +140,7 @@ class mnet_peer {
|
||||
$auth->end_local_sessions($sessions);
|
||||
}
|
||||
|
||||
$deletereturn = delete_records_select('mnet_session', " mnethostid = '{$this->id}'");
|
||||
$deletereturn = $DB->delete_records('mnet_session', array('mnethostid'=>$this->id));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -171,6 +175,7 @@ class mnet_peer {
|
||||
}
|
||||
|
||||
function commit() {
|
||||
global $DB;
|
||||
$obj = new stdClass();
|
||||
|
||||
$obj->wwwroot = $this->wwwroot;
|
||||
@ -187,9 +192,9 @@ class mnet_peer {
|
||||
|
||||
if (isset($this->id) && $this->id > 0) {
|
||||
$obj->id = $this->id;
|
||||
return update_record('mnet_host', $obj);
|
||||
return $DB->update_record('mnet_host', $obj);
|
||||
} else {
|
||||
$this->id = insert_record('mnet_host', $obj);
|
||||
$this->id = $DB->insert_record('mnet_host', $obj);
|
||||
return $this->id > 0;
|
||||
}
|
||||
}
|
||||
@ -216,9 +221,9 @@ class mnet_peer {
|
||||
}
|
||||
|
||||
function set_wwwroot($wwwroot) {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
$hostinfo = get_record('mnet_host', 'wwwroot', $wwwroot);
|
||||
$hostinfo = $DB->get_record('mnet_host', array('wwwroot'=>$wwwroot));
|
||||
|
||||
if ($hostinfo != false) {
|
||||
$this->populate($hostinfo);
|
||||
@ -228,7 +233,7 @@ class mnet_peer {
|
||||
}
|
||||
|
||||
function set_id($id) {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
if (clean_param($id, PARAM_INT) != $id) {
|
||||
$this->errno[] = 1;
|
||||
@ -240,11 +245,11 @@ class mnet_peer {
|
||||
SELECT
|
||||
h.*
|
||||
FROM
|
||||
{$CFG->prefix}mnet_host h
|
||||
{mnet_host} h
|
||||
WHERE
|
||||
h.id = '". $id ."'";
|
||||
h.id = ?";
|
||||
|
||||
if ($hostinfo = get_record_sql($sql)) {
|
||||
if ($hostinfo = $DB->get_record_sql($sql, array($id))) {
|
||||
$this->populate($hostinfo);
|
||||
return true;
|
||||
}
|
||||
@ -259,6 +264,7 @@ class mnet_peer {
|
||||
* @return void
|
||||
*/
|
||||
function populate($hostinfo) {
|
||||
global $DB;
|
||||
$this->id = $hostinfo->id;
|
||||
$this->wwwroot = $hostinfo->wwwroot;
|
||||
$this->ip_address = $hostinfo->ip_address;
|
||||
@ -271,7 +277,7 @@ class mnet_peer {
|
||||
$this->force_theme = $hostinfo->force_theme;
|
||||
$this->theme = $hostinfo->theme;
|
||||
$this->applicationid = $hostinfo->applicationid;
|
||||
$this->application = get_record('mnet_application', 'id', $this->applicationid);
|
||||
$this->application = $DB->get_record('mnet_application', array('id'=>$this->applicationid));
|
||||
}
|
||||
|
||||
function get_public_key() {
|
||||
|
@ -243,7 +243,7 @@ function profile_delete_category($id) {
|
||||
}
|
||||
|
||||
/// Does the category contain any fields
|
||||
if (count_records('user_info_field', 'categoryid', $category->id)) {
|
||||
if ($DB->count_records('user_info_field', array('categoryid'=>$category->id))) {
|
||||
if (array_key_exists($category->sortorder-1, $categories)) {
|
||||
$newcategory = $categories[$category->sortorder-1];
|
||||
} else if (array_key_exists($category->sortorder+1, $categories)) {
|
||||
@ -423,7 +423,7 @@ function profile_edit_category($id, $redirect) {
|
||||
if ($data = $categoryform->get_data(false)) {
|
||||
if (empty($data->id)) {
|
||||
unset($data->id);
|
||||
$data->sortorder = count_records('user_info_category') + 1;
|
||||
$data->sortorder = $DB->count_records('user_info_category') + 1;
|
||||
if (!$DB->insert_record('user_info_category', $data, false)) {
|
||||
print_error('There was a problem adding the record to the database');
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ switch ($action) {
|
||||
}
|
||||
|
||||
//ask for confirmation
|
||||
$fieldcount = count_records('user_info_field', 'categoryid', $id);
|
||||
$fieldcount = $DB->count_records('user_info_field', array('categoryid'=>$id));
|
||||
$optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletecategory', 'sesskey'=>sesskey());
|
||||
admin_externalpage_print_header();
|
||||
print_heading('profiledeletecategory', 'admin');
|
||||
@ -67,7 +67,7 @@ switch ($action) {
|
||||
}
|
||||
|
||||
//ask for confirmation
|
||||
$datacount = count_records('user_info_data', 'fieldid', $id);
|
||||
$datacount = $DB->count_records('user_info_data', array('fieldid'=>$id));
|
||||
$optionsyes = array ('id'=>$id, 'confirm'=>1, 'action'=>'deletefield', 'sesskey'=>sesskey());
|
||||
admin_externalpage_print_header();
|
||||
print_heading('profiledeletefield', 'admin');
|
||||
|
@ -478,7 +478,7 @@
|
||||
|
||||
if (!empty($CFG->messaging) and !isguest() and has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (!empty($USER->id) and ($USER->id == $user->id)) {
|
||||
if ($countmessages = count_records('message', 'useridto', $user->id)) {
|
||||
if ($countmessages = $DB->count_records('message', array('useridto'=>$user->id))) {
|
||||
$messagebuttonname = get_string("messages", "message")."($countmessages)";
|
||||
} else {
|
||||
$messagebuttonname = get_string("messages", "message");
|
||||
|
Loading…
x
Reference in New Issue
Block a user