本文整理汇总了PHP中sql_compare_text函数的典型用法代码示例。如果您正苦于以下问题:PHP sql_compare_text函数的具体用法?PHP sql_compare_text怎么用?PHP sql_compare_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sql_compare_text函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: data_filter
function data_filter($courseid, $text)
{
global $CFG;
static $nothingtodo;
static $contentlist;
if (!empty($nothingtodo)) {
// We've been here in this page already
return $text;
}
// if we don't have a courseid, we can't run the query, so
if (empty($courseid)) {
return $text;
}
// Create a list of all the resources to search for. It may be cached already.
if (empty($contentlist)) {
// We look for text field contents only, and only if the field has
// autolink enabled (param1).
$sql = 'SELECT dc.id AS contentid, ' . 'dr.id AS recordid, ' . 'dc.content AS content, ' . 'd.id AS dataid ' . 'FROM ' . $CFG->prefix . 'data d, ' . $CFG->prefix . 'data_fields df, ' . $CFG->prefix . 'data_records dr, ' . $CFG->prefix . 'data_content dc ' . "WHERE (d.course = '{$courseid}' or d.course = '" . SITEID . "')" . 'AND d.id = df.dataid ' . 'AND df.id = dc.fieldid ' . 'AND d.id = dr.dataid ' . 'AND dr.id = dc.recordid ' . "AND df.type = 'text' " . "AND " . sql_compare_text('df.param1', 1) . " = '1'";
if (!($datacontents = get_records_sql($sql))) {
return $text;
}
$contentlist = array();
foreach ($datacontents as $datacontent) {
$currentcontent = trim($datacontent->content);
$strippedcontent = strip_tags($currentcontent);
if (!empty($strippedcontent)) {
$contentlist[] = new filterobject($currentcontent, '<a class="data autolink" title="' . $strippedcontent . '" href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $datacontent->dataid . '&rid=' . $datacontent->recordid . '" ' . $CFG->frametarget . '>', '</a>', false, true);
}
}
// End foreach
}
return filter_phrases($text, $contentlist);
// Look for all these links in the text
}
示例2: question_cwqpfs_to_update
function question_cwqpfs_to_update($categories = null)
{
global $CFG;
$tofix = array();
$result = true;
//any cats with questions picking from subcats?
if (!($cwqpfs = get_records_sql_menu("SELECT DISTINCT qc.id, 1 " . "FROM {$CFG->prefix}question q, {$CFG->prefix}question_categories qc " . "WHERE q.qtype='random' AND qc.id = q.category AND " . sql_compare_text('q.questiontext') . " = '1'"))) {
return array();
} else {
if ($categories === null) {
$categories = get_records('question_categories');
}
$categorychildparents = array();
foreach ($categories as $id => $category) {
$categorychildparents[$category->course][$id] = $category->parent;
}
foreach ($categories as $id => $category) {
if (FALSE !== array_key_exists($category->parent, $categorychildparents[$category->course])) {
//this is not a top level cat
continue;
//go to next category
} else {
$tofix += question_cwqpfs_check_children($id, $categories, $categorychildparents[$category->course], $cwqpfs);
}
}
}
return $tofix;
}
示例3: generate_sql
function generate_sql($tablealias, $value)
{
$latlong[0] = '';
$latlong[1] = '';
$latlong = explode(',', $value, 2);
$varcharlat = sql_compare_text("{$tablealias}.content");
$varcharlong = sql_compare_text("{$tablealias}.content1");
return " ({$tablealias}.fieldid = {$this->field->id} AND {$varcharlat} = '{$latlong['0']}' AND {$varcharlong} = '{$latlong['1']}') ";
}
示例4: xmldb_qtype_numerical_upgrade
function xmldb_qtype_numerical_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
// In numerical questions, we are changing the 'match anything' answer
// from the empty string to *, to be like short answer questions.
if ($result && $oldversion < 2006121500) {
$result = set_field_select('question_answers', 'answer', '*', sql_compare_text('answer') . " = '" . sql_empty() . "' AND question IN (SELECT id FROM {$CFG->prefix}question WHERE qtype = '" . NUMERICAL . "')");
}
return $result;
}
示例5: restore_create_events
function restore_create_events($restore, $xml_file)
{
global $CFG, $db;
$status = true;
//Check it exists
if (!file_exists($xml_file)) {
$status = false;
}
//Get info from xml
if ($status) {
//events will contain the old_id of every event
//in backup_ids->info will be the real info (serialized)
$events = restore_read_xml_events($restore, $xml_file);
}
//Get admin->id for later use
$admin = get_admin();
$adminid = $admin->id;
//Now, if we have anything in events, we have to restore that
//events
if ($events) {
if ($events !== true) {
//Iterate over each event
foreach ($events as $event) {
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code, "event", $event->id);
//Init variables
$create_event = false;
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//if necessary, write to restorelog and adjust date/time fields
if ($restore->course_startdateoffset) {
restore_log_date_changes('Events', $restore, $info['EVENT']['#'], array('TIMESTART'));
}
//Now build the EVENT record structure
$eve->name = backup_todb($info['EVENT']['#']['NAME']['0']['#']);
$eve->description = backup_todb($info['EVENT']['#']['DESCRIPTION']['0']['#']);
$eve->format = backup_todb($info['EVENT']['#']['FORMAT']['0']['#']);
$eve->courseid = $restore->course_id;
$eve->groupid = backup_todb($info['EVENT']['#']['GROUPID']['0']['#']);
$eve->userid = backup_todb($info['EVENT']['#']['USERID']['0']['#']);
$eve->repeatid = backup_todb($info['EVENT']['#']['REPEATID']['0']['#']);
$eve->modulename = "";
if (!empty($info['EVENT']['#']['MODULENAME'])) {
$eve->modulename = backup_todb($info['EVENT']['#']['MODULENAME']['0']['#']);
}
$eve->instance = 0;
$eve->eventtype = backup_todb($info['EVENT']['#']['EVENTTYPE']['0']['#']);
$eve->timestart = backup_todb($info['EVENT']['#']['TIMESTART']['0']['#']);
$eve->timeduration = backup_todb($info['EVENT']['#']['TIMEDURATION']['0']['#']);
$eve->visible = backup_todb($info['EVENT']['#']['VISIBLE']['0']['#']);
$eve->timemodified = backup_todb($info['EVENT']['#']['TIMEMODIFIED']['0']['#']);
//Now search if that event exists (by name, description, timestart fields) in
//restore->course_id course
//Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
$compare_description_clause = sql_compare_text('description') . "=" . sql_compare_text("'" . $eve->description . "'");
$eve_db = get_record_select("event", "courseid={$eve->courseid} AND name='{$eve->name}' AND {$compare_description_clause} AND timestart={$eve->timestart}");
//If it doesn't exist, create
if (!$eve_db) {
$create_event = true;
}
//If we must create the event
if ($create_event) {
//We must recode the userid
$user = backup_getid($restore->backup_unique_code, "user", $eve->userid);
if ($user) {
$eve->userid = $user->new_id;
} else {
//Assign it to admin
$eve->userid = $adminid;
}
//We have to recode the groupid field
$group = backup_getid($restore->backup_unique_code, "groups", $eve->groupid);
if ($group) {
$eve->groupid = $group->new_id;
} else {
//Assign it to group 0
$eve->groupid = 0;
}
//The structure is equal to the db, so insert the event
$newid = insert_record("event", $eve);
//We must recode the repeatid if the event has it
//The repeatid now refers to the id of the original event. (see Bug#5956)
if ($newid && !empty($eve->repeatid)) {
$repeat_rec = backup_getid($restore->backup_unique_code, "event_repeatid", $eve->repeatid);
if ($repeat_rec) {
//Exists, so use it...
$eve->repeatid = $repeat_rec->new_id;
} else {
//Doesn't exists, calculate the next and save it
$oldrepeatid = $eve->repeatid;
$eve->repeatid = $newid;
backup_putid($restore->backup_unique_code, "event_repeatid", $oldrepeatid, $eve->repeatid);
}
$eve->id = $newid;
// update the record to contain the correct repeatid
update_record('event', $eve);
//.........这里部分代码省略.........
示例6: AND
}
$tables .= ', ' . $CFG->prefix . 'data_content c' . $key . ' ';
$where .= ' AND c' . $key . '.recordid = r.id';
$searchselect .= ' AND (' . $val->sql . ') ';
}
} else {
if ($search) {
$searchselect = " AND (cs.content {$ilike} '%{$search}%' OR u.firstname {$ilike} '%{$search}%' OR u.lastname {$ilike} '%{$search}%' ) ";
} else {
$searchselect = ' ';
}
}
} else {
$sortcontent = $sortfield->get_sort_field();
$sortcontentfull = $sortfield->get_sort_sql('c.' . $sortcontent);
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, ' . sql_compare_text($sortcontentfull) . ' AS _order ';
$count = ' COUNT(DISTINCT c.recordid) ';
$tables = $CFG->prefix . 'data_content c,' . $CFG->prefix . 'data_records r,' . $CFG->prefix . 'data_content cs, ' . $CFG->prefix . 'user u ';
$where = 'WHERE c.recordid = r.id
AND c.fieldid = ' . $sort . '
AND r.dataid = ' . $data->id . '
AND r.userid = u.id
AND cs.recordid = r.id ';
$sortorder = ' ORDER BY _order ' . $order . ' , r.id ASC ';
$searchselect = '';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
if (!empty($advanced)) {
//If advanced box is checked.
示例7: optional_param
$significantchangemade = true;
}
if (optional_param('addrandom', false, PARAM_BOOL) and confirm_sesskey()) {
/// Add random questions to the quiz
$recurse = optional_param('recurse', 0, PARAM_BOOL);
$categoryid = required_param('categoryid', PARAM_INT);
$randomcount = required_param('randomcount', PARAM_INT);
// load category
if (!($category = get_record('question_categories', 'id', $categoryid))) {
error('Category ID is incorrect');
}
$catcontext = get_context_instance_by_id($category->contextid);
require_capability('moodle/question:useall', $catcontext);
$category->name = addslashes($category->name);
// Find existing random questions in this category that are not used by any quiz.
if ($existingquestions = get_records_sql("SELECT * FROM " . $CFG->prefix . "question q\n WHERE qtype = '" . RANDOM . "'\n AND category = {$category->id}\n AND " . sql_compare_text('questiontext') . " = '{$recurse}'\n AND NOT EXISTS (SELECT * FROM " . $CFG->prefix . "quiz_question_instances WHERE question = q.id)\n ORDER BY id")) {
// Take as many of these as needed.
while ($existingquestion = array_shift($existingquestions) and $randomcount > 0) {
quiz_add_quiz_question($existingquestion->id, $quiz);
$randomcount--;
}
}
// If more are needed, create them.
if ($randomcount > 0) {
$form->questiontext = $recurse;
// we use the questiontext field to store the info
// on whether to include questions in subcategories
$form->questiontextformat = 0;
$form->image = '';
$form->defaultgrade = 1;
$form->hidden = 1;
示例8: restore_create_groups
function restore_create_groups($restore, $xml_file)
{
global $CFG;
//Check it exists
if (!file_exists($xml_file)) {
return false;
}
//Get info from xml
if (!($groups = restore_read_xml_groups($restore, $xml_file))) {
//groups will contain the old_id of every group
//in backup_ids->info will be the real info (serialized)
return false;
} else {
if ($groups === true) {
return true;
}
}
$status = true;
//Iterate over each group
foreach ($groups as $group) {
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code, "groups", $group->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GROUP record structure
$gro = new Object();
$gro->courseid = $restore->course_id;
$gro->name = backup_todb($info['GROUP']['#']['NAME']['0']['#']);
$gro->description = backup_todb($info['GROUP']['#']['DESCRIPTION']['0']['#']);
if (isset($info['GROUP']['#']['ENROLMENTKEY']['0']['#'])) {
$gro->enrolmentkey = backup_todb($info['GROUP']['#']['ENROLMENTKEY']['0']['#']);
} else {
$gro->enrolmentkey = backup_todb($info['GROUP']['#']['PASSWORD']['0']['#']);
}
$gro->picture = backup_todb($info['GROUP']['#']['PICTURE']['0']['#']);
$gro->hidepicture = backup_todb($info['GROUP']['#']['HIDEPICTURE']['0']['#']);
$gro->timecreated = backup_todb($info['GROUP']['#']['TIMECREATED']['0']['#']);
$gro->timemodified = backup_todb($info['GROUP']['#']['TIMEMODIFIED']['0']['#']);
//Now search if that group exists (by name and description field) in
//restore->course_id course
//Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
$description_clause = '';
if (!empty($gro->description)) {
/// Only for groups having a description
$literal_description = "'" . $gro->description . "'";
$description_clause = " AND " . sql_compare_text('description') . " = " . sql_compare_text($literal_description);
}
if (!($gro_db = get_record_sql("SELECT *\n FROM {$CFG->prefix}groups\n WHERE courseid = {$restore->course_id} AND\n name = '{$gro->name}'" . $description_clause, true))) {
//If it doesn't exist, create
$newid = insert_record('groups', $gro);
} else {
//get current group id
$newid = $gro_db->id;
}
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code, "groups", $group->id, $newid);
} else {
$status = false;
continue;
}
//Now restore members in the groups_members, only if
//users are included
if ($restore->users != 2) {
if (!restore_create_groups_members($newid, $info, $restore)) {
$status = false;
}
}
}
}
//Now, restore group_files
if ($status) {
$status = restore_group_files($restore);
}
return $status;
}
示例9: question_insert_q_ids
function question_insert_q_ids($backup_unique_code, $info)
{
global $CFG;
//put the ids of the questions from all these categories into the db.
$status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids\n (backup_code, table_name, old_id, info)\n SELECT '{$backup_unique_code}', 'question', q.id, ''\n FROM {$CFG->prefix}question q, {$CFG->prefix}backup_ids bk\n WHERE q.category = bk.old_id AND bk.table_name = 'question_categories' \n AND " . sql_compare_text('bk.info') . " = '{$info}'\n AND bk.backup_code = '{$backup_unique_code}'", false);
return $status;
}
示例10: xmldb_main_upgrade
//.........这里部分代码省略.........
}
if ($result && $oldversion < 2007101546.06) {
unset_config('grade_report_showgroups');
upgrade_main_savepoint($result, 2007101546.06);
}
if ($result && $oldversion < 2007101547) {
// Let's check the status of mandatory mnet_host records, fixing them
// and moving "orphan" users to default localhost record. MDL-16879
notify('Fixing mnet records, this may take a while...', 'notifysuccess');
$db->debug = false;
// Can output too much. Disabling
upgrade_fix_incorrect_mnethostids();
$db->debug = true;
// Restoring debug level
upgrade_main_savepoint($result, 2007101547);
}
if ($result && $oldversion < 2007101551) {
//insert new record for log_display table
//used to record tag update.
if (!record_exists("log_display", "action", "update", "module", "tag")) {
$log_action = new stdClass();
$log_action->module = 'tag';
$log_action->action = 'update';
$log_action->mtable = 'tag';
$log_action->field = 'name';
$result = $result && insert_record('log_display', $log_action);
}
upgrade_main_savepoint($result, 2007101551);
}
if ($result && $oldversion < 2007101561.01) {
// As part of security changes password policy will now be enabled by default.
// If it has not already been enabled then we will enable it... Admins will still
// be able to switch it off after this upgrade
if (record_exists('config', 'name', 'passwordpolicy', sql_compare_text('value'), 0)) {
unset_config('passwordpolicy');
}
$message = get_string('upgrade197notice', 'admin');
if (empty($CFG->passwordsaltmain)) {
$docspath = $CFG->docroot . '/' . str_replace('_utf8', '', current_language()) . '/report/security/report_security_check_passwordsaltmain';
$message .= "\n" . get_string('upgrade197salt', 'admin', $docspath);
}
notify($message, 'notifysuccess');
unset($message);
upgrade_main_savepoint($result, 2007101561.01);
}
if ($result && $oldversion < 2007101561.02) {
$messagesubject = s($SITE->shortname) . ': ' . get_string('upgrade197noticesubject', 'admin');
$message = '<p>' . s($SITE->fullname) . ' (' . s($CFG->wwwroot) . '):</p>' . get_string('upgrade197notice', 'admin');
if (empty($CFG->passwordsaltmain)) {
$docspath = $CFG->docroot . '/' . str_replace('_utf8', '', current_language()) . '/report/security/report_security_check_passwordsaltmain';
$message .= "\n" . get_string('upgrade197salt', 'admin', $docspath);
}
// Force administrators to change password on next login
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, u.imagealt, u.email, u.password, u.mailformat\n FROM {$CFG->prefix}role_capabilities rc\n JOIN {$CFG->prefix}role_assignments ra ON (ra.contextid = rc.contextid AND ra.roleid = rc.roleid)\n JOIN {$CFG->prefix}user u ON u.id = ra.userid\n WHERE rc.capability = 'moodle/site:doanything'\n AND rc.permission = " . CAP_ALLOW . "\n AND u.deleted = 0\n AND rc.contextid = " . $systemcontext->id . " AND (u.auth='manual' OR u.auth='email')";
$adminusers = get_records_sql($sql);
foreach ($adminusers as $adminuser) {
if ($preference = get_record('user_preferences', 'userid', $adminuser->id, 'name', 'auth_forcepasswordchange')) {
if ($preference->value == '1') {
continue;
}
set_field('user_preferences', 'value', '1', 'id', $preference->id);
} else {
$preference = new stdClass();
$preference->userid = $adminuser->id;
$preference->name = 'auth_forcepasswordchange';
示例11: addRandomQuizQuestions
function addRandomQuizQuestions($cmid, $cat_id)
{
global $QTYPES;
$result = true;
$recurse = 1;
list($quiz, $cm) = get_module_from_cmid($cmid);
if ($rs = get_records('question_categories', 'parent', $cat_id, 'sortorder')) {
$course = get_record('course', 'id', $quiz->course);
foreach ($rs as $cat) {
$categoryid = $cat->id;
$randomcount = 1;
// load category
if (!($category = get_record('question_categories', 'id', $categoryid))) {
error('Category ID is incorrect');
}
$catcontext = get_context_instance_by_id($category->contextid);
require_capability('moodle/question:useall', $catcontext);
$category->name = addslashes($category->name);
// Find existing random questions in this category that are not used by any quiz.
if ($existingquestions = get_records_sql("SELECT * FROM " . $CFG->prefix . "question q\n WHERE qtype = '" . RANDOM . "'\n AND category = {$category->id}\n AND " . sql_compare_text('questiontext') . " = '{$recurse}'\n AND NOT EXISTS (SELECT * FROM " . $CFG->prefix . "quiz_question_instances WHERE question = q.id)\n ORDER BY id")) {
// Take as many of these as needed.
while ($existingquestion = array_shift($existingquestions) and $randomcount > 0) {
if (!quiz_add_quiz_question($existingquestion->id, $quiz)) {
$result = false;
}
$randomcount--;
}
}
// If more are needed, create them.
if ($randomcount > 0) {
//echo "NOT EXISTING:".$cat->id."<br/>";
$form->questiontext = $recurse;
// we use the questiontext field to store the info
// on whether to include questions in subcategories
$form->questiontextformat = 0;
$form->image = '';
$form->defaultgrade = 1;
$form->hidden = 1;
for ($i = 0; $i < $randomcount; $i++) {
$form->category = "{$category->id},{$category->contextid}";
$form->stamp = make_unique_id_code();
// Set the unique code (not to be changed)
$question = new stdClass();
$question->qtype = RANDOM;
$question = $QTYPES[RANDOM]->save_question($question, $form, $course);
if (!isset($question->id)) {
error('Could not insert new random question!');
$result = false;
}
//quiz_add_quiz_question($question->id, $quiz);
if (!quiz_add_quiz_question($question->id, $quiz)) {
$result = false;
}
}
}
$significantchangemade = true;
}
}
return $result;
/*
$result = true;
$recurse = 1;
list($quiz, $cm) = get_module_from_cmid($cmid);
if ($rs = get_recordset('question_categories','parent',$cat_id)) {
$course = get_record('course','id',$quiz->course);
foreach ($rs as $category) {
echo $category->name."<br/>";
/// Add random questions to the quiz
// - Source from: /mod/quiz/edit.php
$randomcount = 1;
// load category
//$catcontext = get_context_instance_by_id($category->contextid);
//require_capability('moodle/question:useall', $catcontext);
$category->name = $category->name;
// Find existing random questions in this category that are
// not used by any quiz.
if ($existingquestions = get_records_sql(
"SELECT q.id,q.qtype FROM {question} q
WHERE qtype = '" . RANDOM . "'
AND category = ?
AND " . $DB->sql_compare_text('questiontext') . " = ?
AND NOT EXISTS (SELECT * FROM {quiz_question_instances} WHERE question = q.id)
ORDER BY id", array($category->id, $recurse))) {
// Take as many of these as needed.
while (($existingquestion = array_shift($existingquestions)) && $randomcount > 0) {
//quiz_add_quiz_question($existingquestion->id, $quiz);
if(!quiz_add_quiz_question($existingquestion->id, $quiz)){
$result = false;
}
$randomcount--;
}
}
// If more are needed, create them.
if ($randomcount > 0) {
$form->questiontext = $recurse; // we use the questiontext field
// to store the info on whether to include
// questions in subcategories
$form->questiontextformat = 0;
$form->image = '';
$form->defaultgrade = 1;
//.........这里部分代码省略.........
示例12: AND
$searchselect .= " AND {$val->field} {$ilike} '%{$val->data}%'";
continue;
}
$advtables .= ', ' . $CFG->prefix . 'data_content c' . $key . ' ';
$advwhere .= ' AND c' . $key . '.recordid = r.id';
$advsearchselect .= ' AND (' . $val->sql . ') ';
}
} else {
if ($search) {
$searchselect = " AND (cs.content {$ilike} '%{$search}%' OR u.firstname {$ilike} '%{$search}%' OR u.lastname {$ilike} '%{$search}%' ) ";
} else {
$searchselect = ' ';
}
}
} else {
$sortcontent = sql_compare_text('c.' . $sortfield->get_sort_field());
$sortcontentfull = $sortfield->get_sort_sql($sortcontent);
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, ' . $sortcontentfull . ' AS _order ';
$count = ' COUNT(DISTINCT c.recordid) ';
$tables = $CFG->prefix . 'data_content c,' . $CFG->prefix . 'data_records r,' . $CFG->prefix . 'data_content cs, ' . $CFG->prefix . 'user u ';
$where = 'WHERE c.recordid = r.id
AND c.fieldid = ' . $sort . '
AND r.dataid = ' . $data->id . '
AND r.userid = u.id
AND cs.recordid = r.id ';
$sortorder = ' ORDER BY _order ' . $order . ' , r.id ASC ';
$searchselect = '';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
示例13: restore_create_groups
function restore_create_groups($restore, $xml_file)
{
global $CFG, $db;
$status = true;
$status2 = true;
//Check it exists
if (!file_exists($xml_file)) {
$status = false;
}
//Get info from xml
if ($status) {
//groups will contain the old_id of every group
//in backup_ids->info will be the real info (serialized)
$groups = restore_read_xml_groups($restore, $xml_file);
}
//Now, if we have anything in groups, we have to restore that
//groups
if ($groups) {
if ($groups !== true) {
//Iterate over each group
foreach ($groups as $group) {
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code, "groups", $group->id);
//Init variables
$create_group = false;
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GROUP record structure
$gro = new Object();
///$gro->courseid = backup_todb($info['GROUP']['#']['COURSEID']['0']['#']);
$gro->name = backup_todb($info['GROUP']['#']['NAME']['0']['#']);
$gro->description = backup_todb($info['GROUP']['#']['DESCRIPTION']['0']['#']);
if (isset($info['GROUP']['#']['ENROLMENTKEY']['0']['#'])) {
$gro->enrolmentkey = backup_todb($info['GROUP']['#']['ENROLMENTKEY']['0']['#']);
} else {
//if (! isset($gro->enrolment)) {
$gro->enrolmentkey = backup_todb($info['GROUP']['#']['PASSWORD']['0']['#']);
}
$gro->lang = backup_todb($info['GROUP']['#']['LANG']['0']['#']);
$gro->theme = backup_todb($info['GROUP']['#']['THEME']['0']['#']);
$gro->picture = backup_todb($info['GROUP']['#']['PICTURE']['0']['#']);
$gro->hidepicture = backup_todb($info['GROUP']['#']['HIDEPICTURE']['0']['#']);
$gro->timecreated = backup_todb($info['GROUP']['#']['TIMECREATED']['0']['#']);
$gro->timemodified = backup_todb($info['GROUP']['#']['TIMEMODIFIED']['0']['#']);
//Now search if that group exists (by name and description field) in
//restore->course_id course
//Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
$description_clause = '';
if (!empty($gro->description)) {
/// Only for groups having a description
$literal_description = "'" . $gro->description . "'";
$description_clause = " AND " . sql_compare_text('description') . " = " . sql_compare_text($literal_description);
}
$gro_db = get_record_sql("SELECT *\n FROM {$CFG->prefix}groups g, {$CFG->prefix}groups_courses_groups gcg\n WHERE gcg.courseid = {$restore->course_id} \n AND g.id = gcg.groupid\n AND g.name = '{$gro->name}'" . $description_clause, true);
//If it doesn't exist, create
if (!$gro_db) {
$create_group = true;
}
//If we must create the group
if ($create_group) {
//Me must recode the courseid to the restore->course_id
$gro->courseid = $restore->course_id;
//Check if the theme exists in destination server
$themes = get_list_of_themes();
if (!in_array($gro->theme, $themes)) {
$gro->theme = '';
}
//The structure is equal to the db, so insert the group
$newid = groups_restore_group($restore->course_id, $gro);
} else {
//get current group id
$newid = $gro_db->id;
}
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code, "groups", $group->id, $newid);
}
//Now restore members in the groups_members, only if
//users are included
if ($restore->users != 2) {
$status2 = restore_create_groups_members($newid, $info, $restore);
}
}
}
//Now, restore group_files
if ($status && $status2) {
$status2 = restore_group_files($restore);
}
}
} else {
$status = false;
}
return $status && $status2;
}