/** * Edit the assignment in Moodle then on Turnitin * * @global type $USER * @global type $DB * @param boolean $createevent - setting to determine whether to create a calendar event. * @return boolean */ public function edit_moodle_assignment($createevent = true) { global $USER, $DB, $CFG; $config = turnitintooltwo_admin_config(); $this->turnitintooltwo->id = $this->id; $this->turnitintooltwo->timemodified = time(); // Get Moodle Course Object. $course = $this->get_course_data($this->turnitintooltwo->course); // Get the Turnitin owner of this this Course or make user the owner if none. $ownerid = $this->get_tii_owner($course->id); if (!empty($ownerid)) { $owner = new turnitintooltwo_user($ownerid, 'Instructor'); } else { $owner = new turnitintooltwo_user($USER->id, 'Instructor'); } // Edit course in Turnitin. $this->edit_tii_course($course); $course->turnitin_ctl = $course->fullname . " (Moodle TT)"; // Get Current Moodle Turnitin Tool data (Assignment). if (!($turnitintooltwonow = $DB->get_record("turnitintooltwo", array("id" => $this->id)))) { turnitintooltwo_print_error('turnitintooltwogeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } // Get Current Moodle Turnitin Tool Parts Object. if (!($parts = $DB->get_records_select("turnitintooltwo_parts", " turnitintooltwoid = ? ", array($this->id), 'id ASC'))) { turnitintooltwo_print_error('partgeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } $partids = array_keys($parts); // Update GradeMark setting depending on config setting. $this->turnitintooltwo->usegrademark = $config->usegrademark; // Set the checkbox settings for updates. $this->turnitintooltwo->erater_spelling = isset($this->turnitintooltwo->erater_spelling) ? $this->turnitintooltwo->erater_spelling : 0; $this->turnitintooltwo->erater_grammar = isset($this->turnitintooltwo->erater_grammar) ? $this->turnitintooltwo->erater_grammar : 0; $this->turnitintooltwo->erater_usage = isset($this->turnitintooltwo->erater_usage) ? $this->turnitintooltwo->erater_usage : 0; $this->turnitintooltwo->erater_mechanics = isset($this->turnitintooltwo->erater_mechanics) ? $this->turnitintooltwo->erater_mechanics : 0; $this->turnitintooltwo->erater_style = isset($this->turnitintooltwo->erater_style) ? $this->turnitintooltwo->erater_style : 0; $this->turnitintooltwo->transmatch = isset($this->turnitintooltwo->transmatch) ? $this->turnitintooltwo->transmatch : 0; $this->turnitintooltwo->institution_check = isset($this->turnitintooltwo->institution_check) ? $this->turnitintooltwo->institution_check : 0; // Update each individual part. for ($i = 1; $i <= $this->turnitintooltwo->numparts; $i++) { // Update Turnitin Assignment. $assignment = new TiiAssignment(); $assignment->setClassId($course->turnitin_cid); $assignment->setAuthorOriginalityAccess($this->turnitintooltwo->studentreports); $assignment->setRubricId(!empty($this->turnitintooltwo->rubric) ? $this->turnitintooltwo->rubric : ''); $assignment->setSubmitPapersTo($this->turnitintooltwo->submitpapersto); $assignment->setResubmissionRule($this->turnitintooltwo->reportgenspeed); $assignment->setBibliographyExcluded($this->turnitintooltwo->excludebiblio); $assignment->setQuotedExcluded($this->turnitintooltwo->excludequoted); $assignment->setSmallMatchExclusionType($this->turnitintooltwo->excludetype); $assignment->setSmallMatchExclusionThreshold((int) $this->turnitintooltwo->excludevalue); $assignment->setLateSubmissionsAllowed($this->turnitintooltwo->allowlate); if ($config->repositoryoption == 1) { $assignment->setInstitutionCheck(isset($this->turnitintooltwo->institution_check) ? $this->turnitintooltwo->institution_check : 0); } $attribute = "maxmarks" . $i; $assignment->setMaxGrade($this->turnitintooltwo->{$attribute}); $assignment->setSubmittedDocumentsCheck($this->turnitintooltwo->spapercheck); $assignment->setInternetCheck($this->turnitintooltwo->internetcheck); $assignment->setPublicationsCheck($this->turnitintooltwo->journalcheck); $assignment->setTranslatedMatching($this->turnitintooltwo->transmatch); $assignment->setAllowNonOrSubmissions($this->turnitintooltwo->allownonor); // Erater settings. $assignment->setErater(isset($this->turnitintooltwo->erater) ? $this->turnitintooltwo->erater : 0); $assignment->setEraterSpelling($this->turnitintooltwo->erater_spelling); $assignment->setEraterGrammar($this->turnitintooltwo->erater_grammar); $assignment->setEraterUsage($this->turnitintooltwo->erater_usage); $assignment->setEraterMechanics($this->turnitintooltwo->erater_mechanics); $assignment->setEraterStyle($this->turnitintooltwo->erater_style); $assignment->setEraterSpellingDictionary(isset($this->turnitintooltwo->erater_dictionary) ? $this->turnitintooltwo->erater_dictionary : 'en_US'); $assignment->setEraterHandbook(isset($this->turnitintooltwo->erater_handbook) ? $this->turnitintooltwo->erater_handbook : 0); $attribute = "dtstart" . $i; $assignment->setStartDate(gmdate("Y-m-d\\TH:i:s\\Z", $this->turnitintooltwo->{$attribute})); $attribute = "dtdue" . $i; $assignment->setDueDate(gmdate("Y-m-d\\TH:i:s\\Z", $this->turnitintooltwo->{$attribute})); $attribute = "dtpost" . $i; $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\\TH:i:s\\Z", $this->turnitintooltwo->{$attribute})); $attribute = "partname" . $i; $assignment->setTitle($this->turnitintooltwo->name . " " . $this->turnitintooltwo->{$attribute} . " (Moodle TT)"); // Initialise part. $part = new stdClass(); $part->turnitintooltwoid = $this->id; $part->partname = $this->turnitintooltwo->{$attribute}; $part->deleted = 0; $part->maxmarks = $assignment->getMaxGrade(); $part->dtstart = strtotime($assignment->getStartDate()); $part->dtdue = strtotime($assignment->getDueDate()); $part->dtpost = strtotime($assignment->getFeedbackReleaseDate()); $parttiiassignid = 0; if ($i <= count($partids) && !empty($partids[$i - 1])) { $partdetails = $this->get_part_details($partids[$i - 1]); $part->submitted = $partdetails->submitted; $part->unanon = $partdetails->unanon; // Set anonymous marking depending on whether part has been unanonymised. if ($config->useanon && $partdetails->unanon != 1) { $assignment->setAnonymousMarking($this->turnitintooltwo->anon); } $parttiiassignid = $partdetails->tiiassignid; } if ($parttiiassignid > 0) { $assignment->setAssignmentId($parttiiassignid); $this->edit_tii_assignment($assignment); } else { $parttiiassignid = $this->create_tii_assignment($assignment, $this->id, $i); $part->submitted = 0; } $part->tiiassignid = $parttiiassignid; // Unanonymise part if necessary. if ($part->dtpost < time() && $part->submitted == 1) { $part->unanon = 1; } $properties = new stdClass(); $properties->name = $this->turnitintooltwo->name . ' - ' . $part->partname; $properties->description = $this->turnitintooltwo->intro; $properties->courseid = $this->turnitintooltwo->course; $properties->groupid = 0; $properties->userid = 0; $properties->modulename = 'turnitintooltwo'; $properties->instance = $this->id; $properties->eventtype = 'due'; $properties->timestart = $part->dtdue; $properties->timeduration = 0; if ($i <= count($partids) && !empty($partdetails->id)) { $part->id = $partids[$i - 1]; // Get Current Moodle part data. if (!($partnow = $DB->get_record("turnitintooltwo_parts", array("id" => $part->id)))) { turnitintooltwo_print_error('partgeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } if (!($dbpart = $DB->update_record('turnitintooltwo_parts', $part))) { turnitintooltwo_print_error('partupdateerror', 'turnitintooltwo', null, $i, __FILE__, __LINE__); exit; } else { turnitintooltwo_activitylog("Moodle Assignment part updated (" . $part->id . ") - " . $part->partname, "REQUEST"); } // Delete existing events for this assignment part. $eventname = $turnitintooltwonow->name . " - " . $partnow->partname; $dbselect = " modulename = ? AND instance = ? AND name LIKE ? "; // Moodle pre 2.5 on SQL Server errors here as queries weren't allowed on ntext fields, the relevant fields // are nvarchar from 2.6 onwards so we have to cast the relevant fields in pre 2.5 SQL Server setups. if ($CFG->branch <= 25 && $CFG->dbtype == "sqlsrv") { $dbselect = " CAST(modulename AS nvarchar(max)) = ? AND instance = ? AND CAST(name AS nvarchar(max)) = ? "; } $DB->delete_records_select('event', $dbselect, array('turnitintooltwo', $this->id, $eventname)); } else { if (!($dbpart = $DB->insert_record('turnitintooltwo_parts', $part))) { turnitintooltwo_print_error('partdberror', 'turnitintooltwo', null, $i, __FILE__, __LINE__); exit; } } if ($createevent == true) { require_once $CFG->dirroot . '/calendar/lib.php'; $event = new calendar_event($properties); $event->update($properties, false); } } $this->turnitintooltwo->timemodified = time(); $update = $DB->update_record("turnitintooltwo", $this->turnitintooltwo); turnitintooltwo_activitylog("Turnitintool updated (" . $this->id . ") - " . $this->turnitintooltwo->name, "REQUEST"); // Define grade settings. if (!isset($_SESSION['tii_assignment_reset'])) { turnitintooltwo_grade_item_update($this->turnitintooltwo); } return $update; }
/** * Creates a new event and returns a calendar_event object * * @param object|array $properties An object containing event properties * @return calendar_event|false The event object or false if it failed */ public static function create($properties) { if (is_array($properties)) { $properties = (object) $properties; } if (!is_object($properties)) { throw new coding_exception('When creating an event properties should be either an object or an assoc array'); } $event = new calendar_event($properties); if ($event->update($properties)) { return $event; } else { return false; } }
/** * * Adds an event to the calendar of a user * @param object $event a object containing details of an event tot be saved into a users calendar */ function save_event($event) { //we can not user add_event in moodle 2.0 as it requires the user to have persmissions to add events to the //calendar however this capability check can be bypassed if we use the calendar event class so we will use add_event in //1.9 and calendar_event class in 2.0 global $CFG, $USER; if (stripos($CFG->release, "2.") !== false) { require_once $CFG->dirroot . '/calendar/lib.php'; $calevent = new calendar_event($event); $calevent->update($event, false); if ($calevent !== false) { return $calevent->id; } } else { return add_event($event); } }
/** * Updates the calendar events associated to the given workshop * * @param stdClass $workshop the workshop instance record * @param int $cmid course module id */ function workshop_calendar_update(stdClass $workshop, $cmid) { global $DB; // get the currently registered events so that we can re-use their ids $currentevents = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id)); // the common properties for all events $base = new stdClass(); $base->description = format_module_intro('workshop', $workshop, $cmid, false); $base->courseid = $workshop->course; $base->groupid = 0; $base->userid = 0; $base->modulename = 'workshop'; $base->eventtype = 'pluginname'; $base->instance = $workshop->id; $base->visible = instance_is_visible('workshop', $workshop); $base->timeduration = 0; if ($workshop->submissionstart) { $event = clone($base); $event->name = get_string('submissionstartevent', 'mod_workshop', $workshop->name); $event->timestart = $workshop->submissionstart; if ($reusedevent = array_shift($currentevents)) { $event->id = $reusedevent->id; } else { // should not be set but just in case unset($event->id); } // update() will reuse a db record if the id field is set $eventobj = new calendar_event($event); $eventobj->update($event, false); } if ($workshop->submissionend) { $event = clone($base); $event->name = get_string('submissionendevent', 'mod_workshop', $workshop->name); $event->timestart = $workshop->submissionend; if ($reusedevent = array_shift($currentevents)) { $event->id = $reusedevent->id; } else { // should not be set but just in case unset($event->id); } // update() will reuse a db record if the id field is set $eventobj = new calendar_event($event); $eventobj->update($event, false); } if ($workshop->assessmentstart) { $event = clone($base); $event->name = get_string('assessmentstartevent', 'mod_workshop', $workshop->name); $event->timestart = $workshop->assessmentstart; if ($reusedevent = array_shift($currentevents)) { $event->id = $reusedevent->id; } else { // should not be set but just in case unset($event->id); } // update() will reuse a db record if the id field is set $eventobj = new calendar_event($event); $eventobj->update($event, false); } if ($workshop->assessmentend) { $event = clone($base); $event->name = get_string('assessmentendevent', 'mod_workshop', $workshop->name); $event->timestart = $workshop->assessmentend; if ($reusedevent = array_shift($currentevents)) { $event->id = $reusedevent->id; } else { // should not be set but just in case unset($event->id); } // update() will reuse a db record if the id field is set $eventobj = new calendar_event($event); $eventobj->update($event, false); } // delete any leftover events foreach ($currentevents as $oldevent) { $oldevent = calendar_event::load($oldevent); $oldevent->delete(); } }
/** * Updates an instance of the grouptool in the database * * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @param stdClass $grouptool An object from the form in mod_form.php * @param mod_grouptool_mod_form $mform * @return boolean Success/Fail */ function grouptool_update_instance(stdClass $grouptool, mod_grouptool_mod_form $mform = null) { global $DB, $CFG; $grouptool->timemodified = time(); $grouptool->id = $grouptool->instance; $cmid = $grouptool->coursemodule; if (!isset($grouptool->use_size)) { $grouptool->use_size = 0; } if (!isset($grouptool->use_individual)) { $grouptool->use_individual = 0; } if (!isset($grouptool->use_queue)) { $queues = $DB->count_records_sql("SELECT COUNT(DISTINCT queues.id)\n FROM {grouptool_agrps} agrps\n LEFT JOIN {grouptool_queued} queues ON queues.agrpid = agrps.id\n WHERE agrps.grouptoolid = ?", array($grouptool->instance)); if (!empty($queues)) { $grouptool->use_queue = 1; } else { $grouptool->use_queue = 0; } } if (!isset($grouptool->allow_multiple)) { $grouptool->allow_multiple = 0; } $grouptool->grpsize = clean_param($grouptool->grpsize, PARAM_INT); $grouptool->choose_min = clean_param($grouptool->choose_min, PARAM_INT); $grouptool->choose_max = clean_param($grouptool->choose_max, PARAM_INT); // Register students if immediate registration has been turned on! if ($grouptool->immediate_reg) { require_once $CFG->dirroot . '/mod/grouptool/locallib.php'; $instance = new mod_grouptool($grouptool->coursemodule, $grouptool); $instance->push_registrations(); } require_once $CFG->dirroot . '/calendar/lib.php'; $event = new stdClass(); if ($grouptool->allow_reg) { $event->name = get_string('registration_period_start', 'grouptool') . ' ' . $grouptool->name; } else { $event->name = $grouptool->name . ' ' . get_string('availabledate', 'grouptool'); } $event->description = format_module_intro('grouptool', $grouptool, $grouptool->coursemodule); if (!empty($grouptool->timeavailable)) { $event->timestart = $grouptool->timeavailable; } else { $grouptool->timecreated = $DB->get_field('grouptool', 'timecreated', array('id' => $grouptool->id)); $event->timestart = $grouptool->timecreated; } $event->visible = instance_is_visible('grouptool', $grouptool); $event->timeduration = 0; if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'grouptool', 'instance' => $grouptool->id, 'eventtype' => 'availablefrom'))) { $calendarevent = calendar_event::load($event->id); $calendarevent->update($event, false); } else { $event->courseid = $grouptool->course; $event->groupid = 0; $event->userid = 0; $event->modulename = 'grouptool'; $event->instance = $grouptool->id; /* * For activity module's events, this can be used to set the alternative text of the * event icon. Set it to 'pluginname' unless you have a better string. */ $event->eventtype = 'availablefrom'; calendar_event::create($event); } if ($grouptool->timedue != 0) { unset($event->id); unset($calendarevent); if ($grouptool->allow_reg) { $event->name = get_string('registration_period_end', 'grouptool') . ' ' . $grouptool->name; } else { $event->name = $grouptool->name . ' ' . get_string('duedate', 'grouptool'); } $event->timestart = $grouptool->timedue; $event->eventtype = 'deadline'; /* * For activity module's events, this can be used to set the alternative text of the * event icon. Set it to 'pluginname' unless you have a better string. */ if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'grouptool', 'instance' => $grouptool->id, 'eventtype' => 'due'))) { $calendarevent = calendar_event::load($event->id); $calendarevent->update($event, false); } else { unset($event->id); $event->courseid = $grouptool->course; // We've got some permission issues with calendar_event::create() so we work around that! $calev = new calendar_event($event); $calev->update($event, false); } } else { if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'grouptool', 'instance' => $grouptool->id, 'eventtype' => 'due'))) { $calendarevent = calendar_event::load($event->id); $calendarevent->delete(true); } } $coursegroups = $DB->get_fieldset_select('groups', 'id', 'courseid = ?', array($grouptool->course)); foreach ($coursegroups as $groupid) { if (!$DB->record_exists('grouptool_agrps', array('grouptoolid' => $grouptool->instance, 'groupid' => $groupid))) { $record = new stdClass(); $record->grouptoolid = $grouptool->instance; $record->groupid = $groupid; $record->sort_order = 9999999; $record->grpsize = $grouptool->grpsize; $record->active = 0; $DB->insert_record('grouptool_agrps', $record); } } // We have to override the functions fetching of data, because it's not updated yet! grouptool_update_queues($grouptool); return $DB->update_record('grouptool', $grouptool); }