本文整理汇总了PHP中count_records函数的典型用法代码示例。如果您正苦于以下问题:PHP count_records函数的具体用法?PHP count_records怎么用?PHP count_records使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了count_records函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send_message
/**
* Processes the message (sends by email).
* @param object $message the message to be sent
*/
function send_message($message)
{
//send an email
//if fails saved as read message
//first try to get preference
$usertoemail = get_user_preferences('message_processor_email_email', '', $message->useridto);
//if fails use user profile default
if ($usertoemail == NULL) {
$userto = get_record('user', 'id', $message->useridto);
$usertoemail = $userto->email;
}
$userfrom = get_record('user', 'id', $message->useridfrom);
if (email_to_user($usertoemail, $userfrom->email, $message->subject, $message->fullmessage, $message->fullmessagehtml)) {
/// Move the entry to the other table
$message->timeread = time();
$messageid = $message->id;
unset($message->id);
//if there is no more processor that want to process this can move message
if (count_records('message_working', array('unreadmessageid' => $messageid)) == 0) {
if (insert_record('message_read', $message)) {
delete_records('message', 'id', $messageid);
}
}
} else {
//delete what we've processed and check if can move message
if (count_records('message_working', 'unreadmessageid', $messageid) == 0) {
if (insert_record('message_read', $message)) {
delete_records('message', 'id', $messageid);
}
}
}
return true;
}
示例2: wiki_check_backup_mods
function wiki_check_backup_mods($course, $user_data = false, $backup_unique_code)
{
//First the course data
$info[0][0] = get_string("modulenameplural", 'wiki');
$info[0][1] = count_records('wiki', "course", "{$course}");
return $info;
}
示例3: game_importsnakes
function game_importsnakes()
{
if (count_records('game_snakes_database') != 0) {
return;
}
unset($newrec);
$newrec->name = '8x8 - 4 Snakes - 4 Ladders';
$newrec->cols = 8;
$newrec->rows = 8;
$newrec->fileboard = 'fidaki.jpg';
$newrec->direction = 1;
$newrec->headerx = 4;
$newrec->headery = 4;
$newrec->footerx = 4;
$newrec->footery = 4;
$newrec->width = 487;
$newrec->height = 487;
$newrec->data = 'L3-18,S5-19,S8-27,L24-39,L29-53,S32-62,S41-58,L48-63';
game_importsnakes_do($newrec);
unset($newrec);
$newrec->name = '6x6 - 3 Snakes - 3 Ladders';
$newrec->cols = 6;
$newrec->rows = 6;
$newrec->fileboard = 'fidaki2.jpg';
$newrec->direction = 1;
$newrec->headerx = 8;
$newrec->headery = 8;
$newrec->footerx = 8;
$newrec->footery = 8;
$newrec->width = 502;
$newrec->height = 436;
$newrec->data = 'L2-25,S4-23,L8-18,S16-20,L19-29,S27-33';
game_importsnakes_do($newrec);
}
示例4: unread_count
/**
* this method is only implemented in internal & is used for the header
*/
public static function unread_count($userid)
{
static $unreadcount = array();
if (!isset($unreadcount[$userid])) {
$unreadcount[$userid] = count_records('notification_internal_activity', 'usr', $userid, 'read', 0);
}
return $unreadcount[$userid];
}
示例5: __construct
public function __construct($path = SEARCH_INDEX_PATH)
{
global $CFG, $db;
$this->path = $path;
//test to see if there is a valid index on disk, at the specified path
try {
$test_index = new Zend_Search_Lucene($this->path, false);
$validindex = true;
} catch (Exception $e) {
$validindex = false;
}
//retrieve file system info about the index if it is valid
if ($validindex) {
$this->size = display_size(get_directory_size($this->path));
$index_dir = get_directory_list($this->path, '', false, false);
$this->filecount = count($index_dir);
$this->indexcount = $test_index->count();
} else {
$this->size = 0;
$this->filecount = 0;
$this->indexcount = 0;
}
$db_exists = false;
//for now
//get all the current tables in moodle
$admin_tables = $db->MetaTables();
//TODO: use new IndexDBControl class for database checks?
//check if our search table exists
if (in_array($CFG->prefix . SEARCH_DATABASE_TABLE, $admin_tables)) {
//retrieve database information if it does
$db_exists = true;
//total documents
$this->dbcount = count_records(SEARCH_DATABASE_TABLE);
//individual document types
// $types = search_get_document_types();
$types = search_collect_searchables(true, false);
sort($types);
foreach ($types as $type) {
$c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type);
$this->types[$type] = (int) $c;
}
} else {
$this->dbcount = 0;
$this->types = array();
}
//check if the busy flag is set
if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
$this->complete = false;
} else {
$this->complete = true;
}
//get the last run date for the indexer
if ($this->valid() && $CFG->search_indexer_run_date) {
$this->time = $CFG->search_indexer_run_date;
} else {
$this->time = 0;
}
}
示例6: questionnaire_upgrade_2006031700
function questionnaire_upgrade_2006031700()
{
/// Upgrade the questionnaire_response table to use integer timestamps.
table_column('questionnaire_response', 'submitted', 'submitted', 'varchar', '20', '', ' ');
/// This will be heavy on the database....
if (($numrecs = count_records('questionnaire_response')) > 0) {
$recstart = 0;
$recstoget = 100;
while ($recstart < $numrecs) {
if ($records = get_records('questionnaire_response', '', '', '', '*', $recstart, $recstoget)) {
foreach ($records as $record) {
$tstampparts = explode(' ', $record->submitted);
$dateparts = explode('-', $tstampparts[0]);
$timeparts = explode(':', $tstampparts[1]);
$time = mktime($timeparts[0], $timeparts[1], $timeparts[2], $dateparts[1], $dateparts[2], $dateparts[0]);
set_field('questionnaire_response', 'submitted', $time, 'id', $record->id);
if ($record->qtype == 'unlimited') {
$qtype = 0;
} else {
if ($record->type == 'once') {
$qtype = 1;
}
}
set_field('questionnaire_response', 'qtype', $qtype, 'id', $record->id);
}
}
$recstart += $recstoget;
}
}
table_column('questionnaire_response', 'submitted', 'submitted', 'integer', '10');
/// This will be heavy on the database....
if (($numrecs = count_records('questionnaire')) > 0) {
$recstart = 0;
$recstoget = 100;
while ($recstart < $numrecs) {
if ($records = get_records('questionnaire', '', '', '', '*', $recstart, $recstoget)) {
foreach ($records as $record) {
if ($record->qtype == 'unlimited') {
$qtype = 0;
} else {
if ($record->qtype == 'once') {
$qtype = 1;
}
}
set_field('questionnaire', 'qtype', $qtype, 'id', $record->id);
}
}
$recstart += $recstoget;
}
}
/// Modify the qtype field of the 'questionnaire' table to be integer instead of enum.
table_column('questionnaire', 'qtype', 'qtype', 'integer', '10');
/// Add response viewing eligibility.
table_column('questionnaire', '', 'resp_view', 'integer', '2', 'unsigned', '0', 'not null', 'resp_eligible');
return true;
}
示例7: question_check_no_rqp_questions
/**
* This test is becuase the RQP question type was included in core
* up to and including Moodle 1.8, and was removed before Moodle 1.9.
*
* Therefore, we want to check whether any rqp questions exist in the database
* before doing the upgrade. However, the check is not relevant if that
* question type was never installed, or if the person has chosen to
* manually reinstall the rqp question type from contrib.
*
* @param $result the result object that can be modified.
* @return null if the test is irrelevant, or true or false depending on whether the test passes.
*/
function question_check_no_rqp_questions($result)
{
global $CFG;
if (empty($CFG->qtype_rqp_version) || is_dir($CFG->dirroot . '/question/type/rqp')) {
return null;
} else {
$result->setStatus(count_records('question', 'qtype', 'rqp') == 0);
}
return $result;
}
示例8: xmldb_blocktype_textbox_upgrade
function xmldb_blocktype_textbox_upgrade($oldversion = 0)
{
if ($oldversion < 2011082200) {
// Convert all textbox html content to artefacts
$tbcount = count_records('block_instance', 'blocktype', 'textbox');
$sql = '
SELECT b.id, b.title, b.configdata, b.view,
v.owner, v.group, v.institution, v.ctime, v.mtime, v.atime
FROM {block_instance} b JOIN {view} v ON b.view = v.id
WHERE b.id > ? AND b.blocktype = ?
ORDER BY b.id';
$done = 0;
$lastid = 0;
if (is_mysql()) {
$mp = mysql_get_variable('max_allowed_packet');
$limit = $mp && is_numeric($mp) && $mp > 1048576 ? $mp / 8192 : 100;
} else {
$limit = 5000;
}
while ($records = get_records_sql_array($sql, array($lastid, 'textbox'), 0, $limit)) {
// Create the new artefacts
$values = array();
foreach ($records as $r) {
$configdata = unserialize($r->configdata);
array_push($values, 'html', $r->ctime, $r->mtime, $r->atime, $r->title, isset($configdata['text']) ? $configdata['text'] : '', $r->owner, $r->group, $r->institution, $r->owner > 0 ? $r->owner : null, $r->owner > 0 ? null : '?', $r->id);
// Dumping the block id in the note column makes it easier to update block_instance later
}
$insertsql = "\n INSERT INTO {artefact}\n (artefacttype, ctime, mtime, atime, title, description, owner, \"group\", institution, author, authorname, note)\n VALUES ";
$insertsql .= join(',', array_fill(0, count($records), '(?,?,?,?,?,?,?,?,?,?,?,?)'));
execute_sql($insertsql, $values);
// Update block_instance configdata to point at the new artefacts
if (is_postgres()) {
execute_sql("\n UPDATE {block_instance}\n SET configdata = 'a:1:{s:10:\"artefactid\";i:' || a.id::text || ';}'\n FROM (\n SELECT id, note FROM {artefact} WHERE artefacttype = 'html' AND note IS NOT NULL\n ) a\n WHERE blocktype = 'textbox' AND {block_instance}.id::text = a.note");
// Update view_artefact table
execute_sql("\n INSERT INTO {view_artefact} (view, block, artefact)\n SELECT b.view, b.id, a.id\n FROM {block_instance} b, {artefact} a\n WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND CAST(b.id AS TEXT) = a.note", array());
} else {
if (is_mysql()) {
execute_sql("\n UPDATE {block_instance}, {artefact}\n SET {block_instance}.configdata = CONCAT('a:1:{s:10:\"artefactid\";i:', {artefact}.id, ';}')\n WHERE\n {artefact}.artefacttype = 'html'\n AND {artefact}.note IS NOT NULL\n AND {block_instance}.blocktype = 'textbox'\n AND {block_instance}.id = {artefact}.note");
// Update view_artefact table
execute_sql("\n INSERT INTO {view_artefact} (view, block, artefact)\n SELECT b.view, b.id, a.id\n FROM {block_instance} b, {artefact} a\n WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND b.id = a.note", array());
}
}
// Remove the dodgy block id in the note column
execute_sql("UPDATE {artefact} SET note = NULL WHERE artefacttype = 'html' AND note IS NOT NULL");
$done += count($records);
log_debug("Upgrading textbox blocks: {$done}/{$tbcount}");
$last = end($records);
$lastid = $last->id;
}
}
return true;
}
示例9: groups_count_groups_in_grouping
/**
* Gets the number of groups in a specified grouping
* @param int $groupingid The grouping specified
* @param int $courseid The related course.
* @return int The number of groups in the grouping
*/
function groups_count_groups_in_grouping($groupingid, $courseid)
{
if (GROUP_NOT_IN_GROUPING == $groupingid) {
$groupids = groups_get_groups_not_in_any_grouping($courseid);
if ($groupids === false) {
return false;
}
return count($groupids);
} elseif (GROUP_ANY_GROUPING == $groupingid) {
return count_records('groups_courses_groups', 'courseid', $courseid);
} else {
return count_records('groups_groupings_groups', 'groupingid ', $groupingid);
}
}
示例10: wwassignment_check_backup_mods
function wwassignment_check_backup_mods($course, $user_data = false, $backup_unique_code, $instances = null)
{
if (!empty($instances) && is_array($instances) && count($instances)) {
$info = array();
foreach ($instances as $id => $instance) {
$info += wwassignment_check_backup_mods_instances($instance, $backup_unique_code);
}
return $info;
}
//First the course data
$info[0][0] = get_string("modulenameplural", "wwassignment");
$info[0][1] = count_records("wwassignment", "course", "{$course}");
return $info;
}
示例11: perform_remove
function perform_remove($userid)
{
// Try to remove the necessary role
$context = get_context_instance(CONTEXT_SYSTEM);
$roleid = $this->check_role();
// Regardless if the user has the role or not, remove the assignment
if ($assign = get_record('block_student_' . $this->type, 'path', $this->path, 'usersid', $userid)) {
$this->remove_assignment($assign);
}
$count = count_records('block_student_' . $this->type, 'usersid', $userid) + count_records('block_student_person', 'usersid', $userid);
// If they don't have any mentor assignments, then remove them from that role
if ($count == 0) {
role_unassign($roleid, $userid, 0, $context->id);
}
}
示例12: get_content
function get_content()
{
global $CFG, $COURSE;
$daysnb = $CFG->block_graph_stats_daysnb;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->footer = '';
if (empty($this->instance)) {
$this->content->text = '';
return $this->content;
}
$this->content->text = '<center><font size=1>' . get_string('graphtitle', 'block_graph_stats', $daysnb) . '</center>';
if (isadmin() or isteacher($COURSE->id)) {
$name = 'popup';
$title = get_string('connectedtoday', 'block_graph_stats');
$url = '/blocks/' . $this->name() . '/details.php';
$options = 'menubar=0,location=0,scrollbars,resizable,width=400,height=500';
$fullscreen = 0;
$linkname = '<img src="' . $CFG->wwwroot . '/blocks/' . $this->name() . '/graph.php?course_id=' . $COURSE->id . '" alt="' . get_string('graphtitle', 'block_graph_stats', $daysnb) . '" />';
$this->content->text .= '<center><a target="' . $name . '" title="' . $title . '" href="' . $CFG->wwwroot . $url . '" ' . "onclick=\"return openpopup('{$url}', '{$name}', '{$options}', {$fullscreen});\">{$linkname}</a></center>";
} else {
$this->content->text .= '<center><img src="' . $CFG->wwwroot . '/blocks/' . $this->name() . '/graph.php?course_id=' . $COURSE->id . '" alt="' . get_string('graphtitle', 'block_graph_stats', $daysnb) . '" /></center>';
}
// Check if we are in a course or on the first page
if ($COURSE->id > 1) {
// In a course
$connections = count_records_select('log', 'time > ' . mktime(0, 0, 0, date("m"), date("d"), date("Y")) . ' AND action = "view" AND course = ' . $COURSE->id . ' ', 'COUNT(DISTINCT(userid))');
$this->content->text .= '<center><font size=1>' . get_string('connectedtoday', 'block_graph_stats') . $connections . '</font></center>';
} else {
// On the first page
$connections = count_records_select('log', 'time > ' . mktime(0, 0, 0, date("m"), date("d"), date("Y")) . ' AND action = "login"', 'COUNT(userid)');
$this->content->text .= '<center><font size=1>' . get_string('connectedtoday', 'block_graph_stats') . $connections . '</font></center>';
// Show details
$users = count_records('user', 'deleted', 0, 'confirmed', 1);
$courses = count_records('course', 'visible', 1);
$this->content->text .= '<hr />';
$this->content->text .= get_string('membersnb', 'block_graph_stats') . $users . '<br />';
$this->content->text .= get_string('coursesnb', 'block_graph_stats') . $courses . '<br />';
}
return $this->content;
}
示例13: validation
function validation($data)
{
global $CFG;
$errors = array();
if (!empty($data['username']) and !empty($data['email']) or empty($data['username']) and empty($data['email'])) {
$errors['username'] = get_string('usernameoremail');
$errors['email'] = get_string('usernameoremail');
} else {
if (!empty($data['email'])) {
if (!validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else {
if (count_records('user', 'email', $data['email']) > 1) {
$errors['email'] = get_string('forgottenduplicate');
} else {
if ($user = get_complete_user_data('email', $data['email'])) {
if (empty($user->confirmed)) {
$errors['email'] = get_string('confirmednot');
}
}
if (!$user and empty($CFG->protectusernames)) {
$errors['email'] = get_string('emailnotfound');
}
}
}
} else {
if ($user = get_complete_user_data('username', $data['username'])) {
if (empty($user->confirmed)) {
$errors['email'] = get_string('confirmednot');
}
}
if (!$user and empty($CFG->protectusernames)) {
$errors['username'] = get_string('usernamenotfound');
}
}
}
if (0 == count($errors)) {
return true;
} else {
return $errors;
}
}
示例14: questionnaire_check_backup_mods
function questionnaire_check_backup_mods($course, $user_data = false, $backup_unique_code, $instances = null)
{
global $CFG;
if (!empty($instances) && is_array($instances) && count($instances)) {
$info = array();
foreach ($instances as $id => $instance) {
$info += questionnaire_check_backup_mods_instances($instance, $backup_unique_code);
}
return $info;
}
//First the course data
$info[0][0] = get_string('modulenameplural', 'questionnaire');
$info[0][1] = count_records('questionnaire', 'course', $course);
//Now, if requested, the user_data
if ($user_data) {
$info[1][0] = get_string('respondents', 'questionnaire');
$sql = 'SELECT COUNT(qa.id) ' . 'FROM ' . $CFG->prefix . 'questionnaire q, ' . $CFG->prefix . 'questionnaire_attempts qa ' . 'WHERE q.course = ' . $course . ' AND qa.qid = q.id';
$info[1][1] = count_records_sql($sql);
}
return $info;
}
示例15: attforblock_restore_mods
function attforblock_restore_mods($mod, $restore)
{
global $CFG, $oldidarray;
$status = true;
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
if (count_records('attforblock', 'course', $restore->course_id)) {
return false;
}
//Now, build the attforblock record structure
$attforblock->course = $restore->course_id;
// $attforblock->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']);
$attforblock->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
if (isset($info['MOD']['#']['GRADE'])) {
$attforblock->grade = backup_todb($info['MOD']['#']['GRADE']['0']['#']);
} else {
$attforblock->grade = 100;
}
//The structure is equal to the db, so insert the attforblock
$newid = insert_record('attforblock', $attforblock);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
attforblock_restore_attendance_statuses($mod->id, $newid, $info, $restore);
attforblock_restore_attendance_sessions($mod->id, $newid, $info, $restore);
//Now check if want to restore user data and do it.
if (restore_userdata_selected($restore, 'attforblock', $mod->id)) {
attforblock_restore_attendance_log($mod->id, $newid, $info, $restore);
}
} else {
$status = false;
}
} else {
$status = false;
}
return $status;
}