} else { $glossary->usedynalink = $CFG->glossary_linkentries; } if (isset($xmlglossary['DEFAULTAPPROVAL'][0]['#'])) { $glossary->defaultapproval = $xmlglossary['DEFAULTAPPROVAL'][0]['#']; } else { $glossary->defaultapproval = $CFG->glossary_defaultapproval; } // These fields were not included in export, assume zero. $glossary->assessed = 0; $glossary->availability = null; // New glossary is to be inserted in section 0, it is always visible. $glossary->section = 0; $glossary->visible = 1; // Include new glossary and return the new ID if (!($glossary = add_moduleinfo($glossary, $course))) { echo $OUTPUT->notification("Error while trying to create the new glossary."); glossary_print_tabbed_table_end(); echo $OUTPUT->footer(); exit; } else { echo $OUTPUT->box(get_string("newglossarycreated", "glossary"), 'generalbox boxaligncenter boxwidthnormal'); } } else { echo $OUTPUT->notification("Error while trying to create the new glossary."); echo $OUTPUT->footer(); exit; } } $xmlentries = $xml['GLOSSARY']['#']['INFO'][0]['#']['ENTRIES'][0]['#']['ENTRY']; $sizeofxmlentries = sizeof($xmlentries);
public function execute() { //some variables you may want to use //$this->cwd - the directory where moosh command was executed //$this->mooshDir - moosh installation directory //$this->expandedOptions - commandline provided options, merged with defaults //$this->topDir - top Moodle directory global $CFG, $DB, $USER; require_once $CFG->dirroot . '/course/lib.php'; require_once $CFG->dirroot . '/course/modlib.php'; $length = 64; if ($this->expandedOptions['include-text']) { $split = rand(0, $length); $text = generate_html_page($split) . $this->expandedOptions['include-text'] . generate_html_page($length - $split); } else { $text = generate_html_page($length); } $moduleinfo = new \stdClass(); $moduleinfo->introeditor = array('text' => $text, 'format' => '1', 'itemid' => NULL); $moduleinfo->visible = '1'; $moduleinfo->course = $this->arguments[0]; $moduleinfo->coursemodule = 0; //choose random section from a course $sections = $DB->get_records('course_sections', array('course' => $this->arguments[0]), '', 'section'); $moduleinfo->section = array_rand($sections); $moduleinfo->module = 12; $moduleinfo->modulename = 'label'; $moduleinfo->instance = 0; $moduleinfo->add = 'label'; $moduleinfo->update = 0; $moduleinfo->return = 0; $moduleinfo->sr = 0; //$moduleinfo->submitbutton2=> 'Save and return to course'; $course = $DB->get_record('course', array('id' => $this->arguments[0]), '*', MUST_EXIST); add_moduleinfo($moduleinfo, $course); }
/** * Create a module. * * It includes: * - capability checks and other checks * - create the module from the module info * * @param object $module * @return object the created module info * @throws moodle_exception if user is not allowed to perform the action or module is not allowed in this course */ function create_module($moduleinfo) { global $DB, $CFG; require_once $CFG->dirroot . '/course/modlib.php'; // Check manadatory attributs. $mandatoryfields = array('modulename', 'course', 'section', 'visible'); if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true)) { $mandatoryfields[] = 'introeditor'; } foreach ($mandatoryfields as $mandatoryfield) { if (!isset($moduleinfo->{$mandatoryfield})) { throw new moodle_exception('createmodulemissingattribut', '', '', $mandatoryfield); } } // Some additional checks (capability / existing instances). $course = $DB->get_record('course', array('id' => $moduleinfo->course), '*', MUST_EXIST); list($module, $context, $cw) = can_add_moduleinfo($course, $moduleinfo->modulename, $moduleinfo->section); // Add the module. $moduleinfo->module = $module->id; $moduleinfo = add_moduleinfo($moduleinfo, $course, null); return $moduleinfo; }
/** * Create a new entry in the facetoface_sessions table */ function facetoface_add_session($session, $sessiondates, $fromform) { global $USER, $DB, $CFG; //$face2face=$DB->get_record('facetoface',array('id'=>$session->facetoface)); //$actual_sessions=$face2face->actualsessions+1; //print_object($face2face);exit; $session->timecreated = time(); $session = cleanup_session_data($session); $wiziq=new stdClass(); if (empty($sessiondates)) { // Insert a dummy date record. $date = new stdClass(); $date->sessionid = $new_session; $date->timestart = 0; $date->timefinish = 0; $date->sessiontimezone = ''; //commented by niranjan for adding session in multiple dates // $DB->insert_record('facetoface_sessions_dates', $date); } else { foreach ($sessiondates as $date) { //Niranjan added this to add session in date loop $new_session= $DB->insert_record('facetoface_sessions', $session); $date->sessionid = $new_session; $wiziq->wiziq_datetime=$date->timestart; $wiziq->wiziq_timezone=$date->sessiontimezone; $wiziq->class_timezone=$date->sessiontimezone; $DB->insert_record('facetoface_sessions_dates', $date); if (!facetoface_save_session_room($new_session, $fromform)) { print_error('error:couldnotsaveroom', 'facetoface'); } /*If online session is enabled. */ if($session->onlinesession ==1){ require_once($CFG->dirroot.'/mod/wiziq/locallib.php'); require_once($CFG->dirroot . '/course/modlib.php'); $wiziq->name=$DB->get_field('facetoface','name',array('id'=>$session->facetoface)); $wiziq->modulename='wiziq'; $wiziq->course=1; $wiziq->duration=$session->duration; $wiziq->timezone=wiziq_timezone(); //$wiziq->wiziq_timezone='Asia/Kolkata'; // $wiziq->class_timezone = 'Asia/Kolkata'; $wiziq->timenow=time(); $wiziq->datetime=time(); $wiziq->recording=1; $wiziq->groupinid=0; $wiziq->module=$DB->get_field('modules','id',array('name'=>$wiziq->modulename));; $wiziq->section=1; $wiziq->batchid=$session->facetoface; $wiziq->sessionid=$new_session; $wiziq->visible=1; $courseid = $DB->get_record('course', array('id'=>$wiziq->course), '*', MUST_EXIST); add_moduleinfo($wiziq, $courseid, $mform = null); //$wiziq= wiziq_add_instance($wiziq, $mform = null); } /** * Add a record to the facetoface submissions table and sends out an * email confirmation * * @param class $session record from the facetoface_sessions table * @param class $facetoface record from the facetoface table * @param class $course record from the course table * @param string $discountcode code entered by the user * @param integer $notificationtype type of notifications to send to user * @see {{MDL_F2F_INVITE}} * @param integer $statuscode Status code to set * @param integer $userid user to signup * @param bool $notifyuser whether or not to send an email confirmation * * facetoface_user_signup($session, $facetoface, $course, $discountcode, $notificationtype, $statuscode, $userid = false, $notifyuser = true) { $users = facetoface_get_attendees($session->id); if ($users) { // No/deleted session dates if (empty($session->datetimeknown)) { // Convert any bookings to waitlists foreach ($users as $user) { if ($user->statuscode == MDL_F2F_STATUS_BOOKED) { if (!facetoface_user_signup($session, $facetoface, $course, $user->discountcode, $user->notificationtype, MDL_F2F_STATUS_WAITLISTED, $user->id)) { // rollback_sql(); return false; } } } $eventtype = $user->statuscode == MDL_F2F_STATUS_BOOKED ? 'booking' : 'session'; * @param bool $displayerrors whether or not to return an error page on errors*/ /*==========================Started by rajut for batch users are assigne as signup users (date:17-11-2015)==========*/ $assigned_users=$DB->get_records_sql("SELECT * FROM {local_batch_users} WHERE f2fid=$session->facetoface"); $assigned_course=$DB->get_records_sql("SELECT * FROM {local_batch_courses} WHERE batchid=$session->facetoface"); $newsession=$DB->get_record('facetoface_sessions',array('id'=>$new_session)); $face2face=$DB->get_record('facetoface',array('id'=>$session->facetoface)); //print_object($assigned_users); foreach($assigned_users as $assigned_user){ $course=$DB->get_record('course',array('id'=>$assigned_course->courseid)); $statuscode = MDL_F2F_STATUS_BOOKED; $notifytype = ((int)$notificationtype == MDL_F2F_NONE ? false : true); facetoface_user_signup($newsession,$face2face,$course,$discountcode, $notifytype,$statuscode,$assigned_user->userid, $notifyuser = false); } //* Strated by rajut no.of sessions avialble for batch update in fcae2fcae table when each session created o batch*// $total_sessions=$DB->get_field_sql("SELECT count(id) FROM {facetoface_sessions} where facetoface=$session->facetoface"); if($total_sessions){ $DB->execute('update {facetoface} SET totalsessions='.$total_sessions.' WHERE id='.$session->facetoface.''); } //print_object($face2face);exit; if($face2face){ $actual_sessions=$face2face->actualsessions+1; $DB->execute('update {facetoface} SET actualsessions='.$actual_sessions.' WHERE id='.$session->facetoface.''); } //* Ended by rajut no.of sessions avialble for batch update in fcae2fcae table when each session created o batch*// /*==========================ended by rajut for batch users are assigne as signup users (date:17-11-2015)==========*/ } /* End of the dates loop */ } /* End of the else loop */ return $new_session; }
$mformclassname = 'mod_' . $module->name . '_mod_form'; $mform = new $mformclassname($data, $cw->section, $cm, $course); $mform->set_data($data); if ($mform->is_cancelled()) { if ($return && !empty($cm->id)) { redirect("{$CFG->wwwroot}/mod/{$module->name}/view.php?id={$cm->id}"); } else { redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn))); } } else { if ($fromform = $mform->get_data()) { if (!empty($fromform->update)) { list($cm, $fromform) = update_moduleinfo($cm, $fromform, $course, $mform); } else { if (!empty($fromform->add)) { $fromform = add_moduleinfo($fromform, $course, $mform); } else { print_error('invaliddata'); } } if (isset($fromform->submitbutton)) { if (empty($fromform->showgradingmanagement)) { redirect("{$CFG->wwwroot}/mod/{$module->name}/view.php?id={$fromform->coursemodule}"); } else { $returnurl = new moodle_url("/mod/{$module->name}/view.php", array('id' => $fromform->coursemodule)); redirect($fromform->gradingman->get_management_url($returnurl)); } } else { redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn))); } exit;
/** * If user has attached a url to a post, we must create a module with type url * * @param string $url the url string * @return record the created module of type url. */ protected function create_mod_url($url) { global $CFG, $COURSE, $DB; require_once $CFG->dirroot . '/course/modlib.php'; require_once $CFG->dirroot . '/lib/resourcelib.php'; $moduleid = $DB->get_field('modules', 'id', array('name' => 'url')); $data = new \stdClass(); $data->modulename = 'url'; $data->module = $moduleid; $data->name = $url; $data->visible = 1; $data->section = 1; $data->externalurl = $url; $data->display = RESOURCELIB_DISPLAY_POPUP; $data->popupwidth = 400; $data->popupheight = 400; // Create instance of url. $modinfo = add_moduleinfo($data, $COURSE); return $modinfo->coursemodule; }
/** * Creates an instance of the module for testing purposes. * * Module type will be taken from the class name. Each module type may overwrite * this function to add other default values used by it. * * @param array|stdClass $record data for module being generated. Requires 'course' key * (an id or the full object). Also can have any fields from add module form. * @param null|array $options general options for course module. Since 2.6 it is * possible to omit this argument by merging options into $record * @return stdClass record from module-defined table with additional field * cmid (corresponding id in course_modules table) */ public function create_instance($record = null, array $options = null) { global $CFG, $DB; require_once $CFG->dirroot . '/course/modlib.php'; $this->instancecount++; // Merge options into record and add default values. $record = $this->prepare_moduleinfo_record($record, $options); // Retrieve the course record. if (!empty($record->course->id)) { $course = $record->course; $record->course = $record->course->id; } else { $course = get_course($record->course); } // Fill the name and intro with default values (if missing). if (empty($record->name)) { $record->name = get_string('pluginname', $this->get_modulename()) . ' ' . $this->instancecount; } if (empty($record->introeditor) && empty($record->intro)) { $record->intro = 'Test ' . $this->get_modulename() . ' ' . $this->instancecount; } if (empty($record->introeditor) && empty($record->introformat)) { $record->introformat = FORMAT_MOODLE; } // Before Moodle 2.6 it was possible to create a module with completion tracking when // it is not setup for course and/or site-wide. Display debugging message so it is // easier to trace an error in unittests. if ($record->completion && empty($CFG->enablecompletion)) { debugging('Did you forget to set $CFG->enablecompletion before generating module with completion tracking?', DEBUG_DEVELOPER); } if ($record->completion && empty($course->enablecompletion)) { debugging('Did you forget to enable completion tracking for the course before generating module with completion tracking?', DEBUG_DEVELOPER); } // Add the module to the course. $moduleinfo = add_moduleinfo($record, $course, $mform = null); // Prepare object to return with additional field cmid. $instance = $DB->get_record($this->get_modulename(), array('id' => $moduleinfo->instance), '*', MUST_EXIST); $instance->cmid = $moduleinfo->coursemodule; return $instance; }