Example #1
0
 /**
  * Set up method.
  */
 protected function setUp()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $this->setTimezone('Australia/Perth');
     $user = $this->getDataGenerator()->create_user();
     $sub = new stdClass();
     $sub->url = '';
     $sub->courseid = 0;
     $sub->groupid = 0;
     $sub->userid = $user->id;
     $sub->pollinterval = 0;
     $subid = $DB->insert_record('event_subscriptions', $sub, true);
     $event = new stdClass();
     $event->name = 'Event name';
     $event->description = '';
     $event->timestart = 1385913700;
     // A 2013-12-2 Monday event.
     $event->timeduration = 3600;
     $event->uuid = 'uuid';
     $event->subscriptionid = $subid;
     $event->userid = $user->id;
     $event->groupid = 0;
     $event->courseid = 0;
     $event->eventtype = 'user';
     $eventobj = calendar_event::create($event, false);
     $DB->set_field('event', 'repeatid', $eventobj->id, array('id' => $eventobj->id));
     $eventobj->repeatid = $eventobj->id;
     $this->event = $eventobj;
 }
 /**
  *
  */
 public static function update_event_timedue($data)
 {
     global $DB;
     if (!empty($data->timedue)) {
         $event = new \stdClass();
         $event->name = $data->name;
         $event->description = format_module_intro('dataform', $data, $data->coursemodule);
         $event->timestart = $data->timedue;
         if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'dataform', 'instance' => $data->id))) {
             $calendarevent = \calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             $event->courseid = $data->course;
             $event->groupid = 0;
             $event->userid = 0;
             $event->modulename = 'dataform';
             $event->instance = $data->id;
             $event->eventtype = 'due';
             $event->timeduration = 0;
             $event->visible = $DB->get_field('course_modules', 'visible', array('module' => $data->module, 'instance' => $data->id));
             \calendar_event::create($event);
         }
     } else {
         $DB->delete_records('event', array('modulename' => 'dataform', 'instance' => $data->id, 'eventtype' => 'due'));
     }
 }
 /**
  * Do the job.
  */
 public function execute()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/calendar/lib.php';
     // Get calendars set to sync in.
     $starttime = time();
     \local_o365\feature\calsync\observers::set_event_import(true);
     // Using a direct query here so we don't run into static cache issues.
     $laststarttime = $DB->get_record('config_plugins', ['plugin' => 'local_o365', 'name' => 'calsyncinlastrun']);
     $laststarttime = !empty($laststarttime) && !empty($laststarttime->value) ? $laststarttime->value : 0;
     $httpclient = new \local_o365\httpclient();
     $clientdata = \local_o365\oauth2\clientdata::instance_from_oidc();
     $calsubs = $DB->get_recordset_select('local_o365_calsub', 'syncbehav = ? OR syncbehav = ?', ['in', 'both']);
     $calsync = new \local_o365\feature\calsync\main($clientdata, $httpclient);
     foreach ($calsubs as $i => $calsub) {
         try {
             $events = $calsync->get_events($calsub->user_id, $calsub->o365calid, $laststarttime);
             if (!empty($events) && is_array($events) && isset($events['value']) && is_array($events['value'])) {
                 if (!empty($events['value'])) {
                     foreach ($events['value'] as $i => $event) {
                         if (!isset($event['Id'])) {
                             mtrace('Skipped an event because of malformed data.');
                             continue;
                         }
                         $idmapexists = $DB->record_exists('local_o365_calidmap', ['outlookeventid' => $event['Id']]);
                         if ($idmapexists === false) {
                             // Create Moodle event.
                             $eventparams = ['name' => $event['Subject'], 'description' => $event['Body']['Content'], 'eventtype' => $calsub->caltype, 'repeatid' => 0, 'modulename' => 0, 'instance' => 0, 'timestart' => strtotime($event['Start']), 'visible' => 1, 'uuid' => '', 'sequence' => 1];
                             $end = strtotime($event['End']);
                             $eventparams['timeduration'] = $end - $eventparams['timestart'];
                             if ($calsub->caltype === 'user') {
                                 $eventparams['userid'] = $calsub->caltypeid;
                             }
                             if ($calsub->caltype === 'course') {
                                 $eventparams['courseid'] = $calsub->caltypeid;
                             }
                             $moodleevent = \calendar_event::create($eventparams, false);
                             if (!empty($moodleevent) && !empty($moodleevent->id)) {
                                 $idmaprec = ['eventid' => $moodleevent->id, 'outlookeventid' => $event['Id'], 'origin' => 'o365', 'userid' => $calsub->user_id];
                                 $DB->insert_record('local_o365_calidmap', (object) $idmaprec);
                                 mtrace('Successfully imported event #' . $moodleevent->id);
                             }
                         }
                     }
                 } else {
                     mtrace('No new events to sync in.');
                 }
             } else {
                 mtrace('Bad response received when fetching events.');
             }
         } catch (\Exception $e) {
             mtrace('Error: ' . $e->getMessage());
         }
     }
     $calsubs->close();
     \local_o365\feature\calsync\observers::set_event_import(false);
     set_config('calsyncinlastrun', $starttime, 'local_o365');
     return true;
 }
Example #4
0
/**
 * Performs upgrade of the database structure and data
 *
 * Workshop supports upgrades from version 1.9.0 and higher only. During 1.9 > 2.0 upgrade,
 * there are significant database changes.
 *
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_workshop_upgrade($oldversion)
{
    global $CFG, $DB, $OUTPUT;
    $dbman = $DB->get_manager();
    // Moodle v2.2.0 release upgrade line
    if ($oldversion < 2012033100) {
        // add the field 'phaseswitchassessment' to the 'workshop' table
        $table = new xmldb_table('workshop');
        $field = new xmldb_field('phaseswitchassessment', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'assessmentend');
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint(true, 2012033100, 'workshop');
    }
    /**
     * Remove all workshop calendar events
     */
    if ($oldversion < 2012041700) {
        require_once $CFG->dirroot . '/calendar/lib.php';
        $events = $DB->get_records('event', array('modulename' => 'workshop'));
        foreach ($events as $event) {
            $event = calendar_event::load($event);
            $event->delete();
        }
        upgrade_mod_savepoint(true, 2012041700, 'workshop');
    }
    /**
     * Recreate all workshop calendar events
     */
    if ($oldversion < 2012041701) {
        require_once dirname(dirname(__FILE__)) . '/lib.php';
        $sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,\n                       w.submissionend, w.assessmentstart, w.assessmentend,\n                       cm.id AS cmid\n                  FROM {workshop} w\n                  JOIN {modules} m ON m.name = 'workshop'\n                  JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";
        $rs = $DB->get_recordset_sql($sql);
        foreach ($rs as $workshop) {
            $cmid = $workshop->cmid;
            unset($workshop->cmid);
            workshop_calendar_update($workshop, $cmid);
        }
        $rs->close();
        upgrade_mod_savepoint(true, 2012041701, 'workshop');
    }
    // Moodle v2.3.0 release upgrade line
    // Put any upgrade step following this
    return true;
}
Example #5
0
function appear_add_instance($data)
{
    global $DB, $CFG, $USER;
    $appear = new stdClass();
    $appear->course = $data->course;
    $appear->name = $data->name;
    $appear->intro = $data->intro;
    $appear->revision = $data->revision;
    $appear->timemodified = time();
    $appear->timecreated = time();
    $appear->timestart = $data->starttime;
    $appear->id = $DB->insert_record('appear', $appear);
    //creating group
    $group = new stdClass();
    $group->name = $data->name . '_group_' . $appear->id;
    $group->courseid = $data->course;
    $group->hidepicture = 0;
    $group->id = groups_create_group($group);
    // creating event subscription
    $sub = new stdClass();
    $sub->url = $CFG->wwwroot . '/mod/appear/view.php?id=' . $data->coursemodule;
    $sub->courseid = $data->course;
    $sub->groupid = $group->id;
    $sub->userid = $USER->id;
    $sub->pollinterval = 0;
    $subid = $DB->insert_record('event_subscriptions', $sub, true);
    // creating calender event
    $event = new stdClass();
    $event->name = $data->name;
    $event->description = '';
    $event->timestart = $data->starttime;
    $event->modulename = 'appear';
    $event->timeduration = 3600;
    $event->uuid = 'uuid';
    $event->subscriptionid = $subid;
    $event->userid = $USER->id;
    $event->groupid = $group->id;
    $event->courseid = $data->course;
    $event->eventtype = 'feedbackcloses';
    $eventobj = calendar_event::create($event, false);
    return $appear->id;
}
function geogebra_after_add_or_update($geogebra, $mform)
{
    global $DB;
    if ($mform->get_data()->filetype === GEOGEBRA_FILE_TYPE_LOCAL) {
        $filename = geogebra_set_mainfile($geogebra);
        $geogebra->url = $filename;
        $result = $DB->update_record('geogebra', $geogebra);
    }
    if ($geogebra->timedue) {
        $event = new stdClass();
        if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'geogebra', 'instance' => $geogebra->id))) {
            $event->name = $geogebra->name;
            $event->description = format_module_intro('geogebra', $geogebra, $geogebra->coursemodule);
            $event->timestart = $geogebra->timedue;
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->update($event);
        } else {
            $event = new stdClass();
            $event->name = $geogebra->name;
            $event->description = format_module_intro('geogebra', $geogebra, $geogebra->coursemodule);
            $event->courseid = $geogebra->course;
            $event->groupid = 0;
            $event->userid = 0;
            $event->modulename = 'geogebra';
            $event->instance = $geogebra->id;
            $event->eventtype = 'due';
            $event->timestart = $geogebra->timedue;
            $event->timeduration = 0;
            calendar_event::create($event);
        }
    } else {
        $DB->delete_records('event', array('modulename' => 'geogebra', 'instance' => $geogebra->id));
    }
    // get existing grade item
    geogebra_grade_item_update($geogebra);
    return true;
}
Example #7
0
 /**
  * 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;
     }
 }
Example #8
0
/**
 * Processes the data passed by the part update form from the summary page
 *
 * @param object $cm The moodle course module object for this instance
 * @param object $turnitintool The turnitintool object is for this activity
 * @param array $post The post array from the part update form
 * @return array A notice array contains error details for display on page load in the case of an error nothing returned if no errors occur
 */
function turnitintool_update_partnames($cm, $turnitintool, $post)
{
    global $CFG, $USER;
    if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) {
        $notice['message'] = '';
        $error = false;
        $dtstart = make_timestamp($post["dtstart"]["year"], $post["dtstart"]["month"], $post["dtstart"]["day"], $post["dtstart"]["hour"], $post["dtstart"]["minute"], 0, get_user_timezone());
        $dtdue = make_timestamp($post["dtdue"]["year"], $post["dtdue"]["month"], $post["dtdue"]["day"], $post["dtdue"]["hour"], $post["dtdue"]["minute"], 0, get_user_timezone());
        $dtpost = make_timestamp($post["dtpost"]["year"], $post["dtpost"]["month"], $post["dtpost"]["day"], $post["dtpost"]["hour"], $post["dtpost"]["minute"], 0, get_user_timezone());
        if ($dtstart >= $dtdue) {
            $notice['message'] .= get_string('partstarterror', 'turnitintool');
            $error = true;
        }
        if ($dtpost < $dtstart) {
            $notice['message'] .= get_string('partdueerror', 'turnitintool');
            $error = true;
        }
        if (empty($post['partname'])) {
            $notice['message'] .= get_string('partnameerror', 'turnitintool');
            $error = true;
        }
        if (strlen($post['partname']) > 35) {
            $input = new stdClass();
            $input->length = 35;
            $input->field = get_string('partname', 'turnitintool');
            $notice['message'] .= get_string('maxlength', 'turnitintool', $input);
            $error = true;
        }
        if (!preg_match("/^[-]?[0-9]+([\\.][0-9]+)?\$/", $post['maxmarks'])) {
            // ENTRY IS NOT A NUMBER
            $notice['message'] .= get_string('partmarkserror', 'turnitintool');
            $error = true;
        }
        if ($error) {
            $notice['error'] = $post['submitted'];
            $notice['post'] = $post;
        }
        if (!$error) {
            // Update Turnitin Assignment via the API [[[[
            $tiipost = new stdClass();
            $tiipost->ctl = turnitintool_getCTL($turnitintool->course);
            $tiipost->dtstart = $dtstart;
            $tiipost->dtdue = $dtdue;
            $tiipost->dtpost = $dtpost;
            if (turnitintool_is_owner($turnitintool->course)) {
                $owner = $USER;
            } else {
                $owner = turnitintool_get_owner($turnitintool->course);
            }
            if (!($course = turnitintool_get_record('course', 'id', $turnitintool->course))) {
                turnitintool_print_error('coursegeterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                exit;
            }
            $loaderbar = new turnitintool_loaderbarclass(3);
            $tii = new turnitintool_commclass(turnitintool_getUID($owner), $owner->firstname, $owner->lastname, $owner->email, 2, $loaderbar);
            $tii->startSession();
            turnitintool_usersetup($owner, get_string('userprocess', 'turnitintool'), $tii, $loaderbar);
            turnitintool_classsetup($course, $owner, get_string('classprocess', 'turnitintool'), $tii, $loaderbar);
            if ($tii->getRerror()) {
                if ($tii->getAPIunavailable()) {
                    turnitintool_print_error('apiunavailable', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
                } else {
                    turnitintool_print_error($tii->getRmessage(), NULL, NULL, NULL, __FILE__, __LINE__);
                }
                exit;
            }
            $tiipost->cid = turnitintool_getCID($turnitintool->course);
            $tiipost->assignid = turnitintool_getAID($post['submitted']);
            $tiipost->s_view_report = $turnitintool->studentreports;
            $tiipost->max_points = $post['maxmarks'];
            $tiipost->anon = $turnitintool->anon;
            $tiipost->report_gen_speed = $turnitintool->reportgenspeed;
            $tiipost->late_accept_flag = $turnitintool->allowlate;
            $tiipost->submit_papers_to = $turnitintool->submitpapersto;
            $tiipost->s_paper_check = $turnitintool->spapercheck;
            $tiipost->internet_check = $turnitintool->internetcheck;
            $tiipost->journal_check = $turnitintool->journalcheck;
            // Add in Exclude small matches, biblio, quoted etc 20102009
            $tiipost->exclude_biblio = $turnitintool->excludebiblio;
            $tiipost->exclude_quoted = $turnitintool->excludequoted;
            $tiipost->exclude_value = $turnitintool->excludevalue;
            $tiipost->exclude_type = $turnitintool->excludetype;
            // Add in the erater settings
            $tiipost->erater = $turnitintool->erater;
            $tiipost->erater_handbook = $turnitintool->erater_handbook;
            $tiipost->erater_dictionary = $turnitintool->erater_dictionary;
            $tiipost->erater_spelling = $turnitintool->erater_spelling;
            $tiipost->erater_grammar = $turnitintool->erater_grammar;
            $tiipost->erater_usage = $turnitintool->erater_usage;
            $tiipost->erater_mechanics = $turnitintool->erater_mechanics;
            $tiipost->erater_style = $turnitintool->erater_style;
            $tiipost->transmatch = $turnitintool->transmatch;
            $tiipost->name = $turnitintool->name . ' - ' . $post['partname'] . ' (Moodle ' . $tiipost->assignid . ')';
            $tiipost->currentassign = $turnitintool->name . ' - ' . turnitintool_partnamefromnum($post['submitted']) . ' (Moodle ' . $tiipost->assignid . ')';
            $tii->createAssignment($tiipost, 'UPDATE', get_string('assignmentupdate', 'turnitintool', ''));
            if ($tii->getRerror()) {
                if ($tii->getRcode() == TURNITINTOOL_DB_UNIQUEID_ERROR) {
                    $reason = get_string('assignmentdoesnotexist', 'turnitintool');
                } else {
                    $reason = $tii->getAPIunavailable() ? get_string('apiunavailable', 'turnitintool') : $tii->getRmessage();
                }
                turnitintool_print_error('<strong>' . get_string('updateerror', 'turnitintool') . '</strong><br />' . $reason);
                exit;
            }
            $part = new stdClass();
            $part->id = $post['submitted'];
            $part->dtstart = $dtstart;
            $part->dtdue = $dtdue;
            $part->dtpost = $dtpost;
            $part->partname = $post['partname'];
            $part->maxmarks = $post['maxmarks'];
            $part->deleted = 0;
            $event = new stdClass();
            $event->timestart = $part->dtdue;
            $event->name = $turnitintool->name . ' - ' . $part->partname;
            $currentevent = $turnitintool->name . ' - ' . turnitintool_partnamefromnum($post['submitted']);
            if (!($dbpart = turnitintool_update_record('turnitintool_parts', $part, false))) {
                turnitintool_print_error('partdberror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
            }
            if ($events = turnitintool_get_record_select('event', "modulename='turnitintool' AND instance = ? AND name = ?", array($turnitintool->id, $currentevent))) {
                $event->id = $events->id;
                if (method_exists('calendar_event', 'update')) {
                    $calendarevent = calendar_event::load($event->id);
                    $calendarevent->update($event);
                } else {
                    update_event($event);
                }
            }
            @(include_once $CFG->dirroot . "/lib/gradelib.php");
            // Set the view time for Grade Book viewing
            if (function_exists('grade_update')) {
                $lastpart = turnitintool_get_record('turnitintool_parts', 'turnitintoolid', $turnitintool->id, '', '', '', '', 'max(dtpost)');
                $lastpart = current($lastpart);
                $params['hidden'] = $lastpart;
                grade_update('mod/turnitintool', $turnitintool->course, 'mod', 'turnitintool', $turnitintool->id, 0, NULL, $params);
            }
            $tii->endSession();
            turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php' . '?id=' . $cm->id . '&do=intro');
            exit;
        } else {
            return $notice;
        }
    } else {
        turnitintool_print_error('permissiondeniederror', 'turnitintool', NULL, NULL, __FILE__, __LINE__);
    }
}
/**
 * Deletes a booking option and the associated user answers
 * @param $bookingid the booking instance
 * @param $optionid the booking option
 * @return false if not successful, true on success
 */
function booking_delete_booking_option($booking, $optionid)
{
    global $DB;
    $event = new stdClass();
    if (!($option = $DB->get_record("booking_options", array("id" => $optionid)))) {
        return false;
    }
    $result = true;
    $params = array('bookingid' => $booking->id, 'optionid' => $optionid);
    $userids = $DB->get_fieldset_select('booking_answers', 'userid', 'bookingid = :bookingid AND optionid = :optionid', $params);
    foreach ($userids as $userid) {
        booking_check_unenrol_user($option, $booking, $userid);
        // Unenrol any users enroled via this option.
    }
    if (!$DB->delete_records("booking_answers", array("bookingid" => $booking->id, "optionid" => $optionid))) {
        $result = false;
    }
    // Delete calendar entry, if any
    $event->id = $DB->get_field('booking_options', 'calendarid', array('id' => $optionid));
    if ($event->id > 0) {
        // Delete event if exist
        $event = calendar_event::load($event->id);
        $event->delete(true);
    }
    if (!$DB->delete_records("booking_options", array("id" => $optionid))) {
        $result = false;
    }
    return $result;
}
Example #10
0
/**
 * This creates new events given as timeopen and closeopen by $feedback.
 *
 * @global object
 * @param object $feedback
 * @return void
 */
function feedback_set_events($feedback) {
    global $DB;

    // adding the feedback to the eventtable (I have seen this at quiz-module)
    $DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$feedback->id));

    if (!isset($feedback->coursemodule)) {
        $cm = get_coursemodule_from_id('feedback', $feedback->id);
        $feedback->coursemodule = $cm->id;
    }

    // the open-event
    if ($feedback->timeopen > 0) {
        $event = new stdClass();
        $event->name         = get_string('start', 'feedback').' '.$feedback->name;
        $event->description  = format_module_intro('feedback', $feedback, $feedback->coursemodule);
        $event->courseid     = $feedback->course;
        $event->groupid      = 0;
        $event->userid       = 0;
        $event->modulename   = 'feedback';
        $event->instance     = $feedback->id;
        $event->eventtype    = 'open';
        $event->timestart    = $feedback->timeopen;
        $event->visible      = instance_is_visible('feedback', $feedback);
        if ($feedback->timeclose > 0) {
            $event->timeduration = ($feedback->timeclose - $feedback->timeopen);
        } else {
            $event->timeduration = 0;
        }

        calendar_event::create($event);
    }

    // the close-event
    if ($feedback->timeclose > 0) {
        $event = new stdClass();
        $event->name         = get_string('stop', 'feedback').' '.$feedback->name;
        $event->description  = format_module_intro('feedback', $feedback, $feedback->coursemodule);
        $event->courseid     = $feedback->course;
        $event->groupid      = 0;
        $event->userid       = 0;
        $event->modulename   = 'feedback';
        $event->instance     = $feedback->id;
        $event->eventtype    = 'close';
        $event->timestart    = $feedback->timeclose;
        $event->visible      = instance_is_visible('feedback', $feedback);
        $event->timeduration = 0;

        calendar_event::create($event);
    }
}
Example #11
0
    /**
     * Updates a new assignment activity
     *
     * Given an object containing all the necessary data,
     * (defined by the form in mod_form.php) this function
     * will update the assignment instance and return the id number
     * The due date is updated in the calendar
     * This is common to all assignment types.
     *
     * @global object
     * @global object
     * @param object $assignment The data from the form on mod_form.php
     * @return bool success
     */
    function update_instance($assignment) {
        global $COURSE, $DB;

        $assignment->timemodified = time();

        $assignment->id = $assignment->instance;
        $assignment->courseid = $assignment->course;

        $DB->update_record('assignment', $assignment);

        if ($assignment->timedue) {
            $event = new stdClass();

            if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) {

                $event->name        = $assignment->name;
                $event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
                $event->timestart   = $assignment->timedue;

                $calendarevent = calendar_event::load($event->id);
                $calendarevent->update($event);
            } else {
                $event = new stdClass();
                $event->name        = $assignment->name;
                $event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
                $event->courseid    = $assignment->course;
                $event->groupid     = 0;
                $event->userid      = 0;
                $event->modulename  = 'assignment';
                $event->instance    = $assignment->id;
                $event->eventtype   = 'due';
                $event->timestart   = $assignment->timedue;
                $event->timeduration = 0;

                calendar_event::create($event);
            }
        } else {
            $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id));
        }

        // get existing grade item
        assignment_grade_item_update($assignment);

        return true;
    }
Example #12
0
 /**
  * Deletes this lesson from the database
  */
 public function delete()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->dirroot . '/calendar/lib.php';
     $cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
     $context = context_module::instance($cm->id);
     $DB->delete_records("lesson", array("id" => $this->properties->id));
     $DB->delete_records("lesson_pages", array("lessonid" => $this->properties->id));
     $DB->delete_records("lesson_answers", array("lessonid" => $this->properties->id));
     $DB->delete_records("lesson_attempts", array("lessonid" => $this->properties->id));
     $DB->delete_records("lesson_grades", array("lessonid" => $this->properties->id));
     $DB->delete_records("lesson_timer", array("lessonid" => $this->properties->id));
     $DB->delete_records("lesson_branch", array("lessonid" => $this->properties->id));
     $DB->delete_records("lesson_high_scores", array("lessonid" => $this->properties->id));
     if ($events = $DB->get_records('event', array("modulename" => 'lesson', "instance" => $this->properties->id))) {
         foreach ($events as $event) {
             $event = calendar_event::load($event);
             $event->delete();
         }
     }
     // Delete files associated with this module.
     $fs = get_file_storage();
     $fs->delete_area_files($context->id);
     grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted' => 1));
     return true;
 }
Example #13
0
 /**
  * Get Calendar events
  *
  * @param array $events A list of events
  * @param array $options various options
  * @return array Array of event details
  * @since Moodle 2.5
  */
 public static function get_calendar_events($events = array(), $options = array())
 {
     global $SITE, $DB, $USER, $CFG;
     require_once $CFG->dirroot . "/calendar/lib.php";
     // Parameter validation.
     $params = self::validate_parameters(self::get_calendar_events_parameters(), array('events' => $events, 'options' => $options));
     $funcparam = array('courses' => array(), 'groups' => array());
     $hassystemcap = has_capability('moodle/calendar:manageentries', context_system::instance());
     $warnings = array();
     // Let us findout courses that we can return events from.
     if (!$hassystemcap) {
         $courses = enrol_get_my_courses();
         $courses = array_keys($courses);
         foreach ($params['events']['courseids'] as $id) {
             if (in_array($id, $courses)) {
                 $funcparam['courses'][] = $id;
             } else {
                 $warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this course');
             }
         }
     } else {
         $courses = $params['events']['courseids'];
         $funcparam['courses'] = $courses;
     }
     // Let us findout groups that we can return events from.
     if (!$hassystemcap) {
         $groups = groups_get_my_groups();
         $groups = array_keys($groups);
         foreach ($params['events']['groupids'] as $id) {
             if (in_array($id, $groups)) {
                 $funcparam['groups'][] = $id;
             } else {
                 $warnings[] = array('item' => $id, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to access this group');
             }
         }
     } else {
         $groups = $params['events']['groupids'];
         $funcparam['groups'] = $groups;
     }
     // Do we need user events?
     if (!empty($params['options']['userevents'])) {
         $funcparam['users'] = array($USER->id);
     } else {
         $funcparam['users'] = false;
     }
     // Do we need site events?
     if (!empty($params['options']['siteevents'])) {
         $funcparam['courses'][] = $SITE->id;
     }
     // We treat 0 and null as no end.
     if (empty($params['options']['timeend'])) {
         $params['options']['timeend'] = PHP_INT_MAX;
     }
     $eventlist = calendar_get_events($params['options']['timestart'], $params['options']['timeend'], $funcparam['users'], $funcparam['groups'], $funcparam['courses'], true, $params['options']['ignorehidden']);
     // WS expects arrays.
     $events = array();
     foreach ($eventlist as $id => $event) {
         $events[$id] = (array) $event;
     }
     // We need to get events asked for eventids.
     $eventsbyid = calendar_get_events_by_id($params['events']['eventids']);
     foreach ($eventsbyid as $eventid => $eventobj) {
         $event = (array) $eventobj;
         if (isset($events[$eventid])) {
             continue;
         }
         if ($hassystemcap) {
             // User can see everything, no further check is needed.
             $events[$eventid] = $event;
         } else {
             if (!empty($eventobj->modulename)) {
                 $cm = get_coursemodule_from_instance($eventobj->modulename, $eventobj->instance);
                 if (\core_availability\info_module::is_user_visible($cm, 0, false)) {
                     $events[$eventid] = $event;
                 }
             } else {
                 // Can the user actually see this event?
                 $eventobj = calendar_event::load($eventobj);
                 if ($eventobj->courseid == $SITE->id || !empty($eventobj->groupid) && in_array($eventobj->groupid, $groups) || !empty($eventobj->courseid) && in_array($eventobj->courseid, $courses) || $USER->id == $eventobj->userid || calendar_edit_event_allowed($eventid)) {
                     $events[$eventid] = $event;
                 } else {
                     $warnings[] = array('item' => $eventid, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to view this event');
                 }
             }
         }
     }
     return array('events' => $events, 'warnings' => $warnings);
 }
Example #14
0
/**
 * 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();
    }
}
Example #15
0
/**
 * Call this function to update an event in the calendar table
 * the event will be identified by the id field of the $event object.
 *
 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
 * @return bool Success
 * @deprecated please calendar_event->update() instead.
 */
function update_event($event)
{
    global $CFG;
    require_once $CFG->dirroot . '/calendar/lib.php';
    debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
    $event = (object) $event;
    $calendarevent = calendar_event::load($event->id);
    return $calendarevent->update($event);
}
 /** Create calendar events or update them
  * Set $prop->id, if you want to do an update instead of creating an new event
  *
  * @param string $name        Event title
  * @param int    $userid      User id
  * @param string $type        Event type
  * @param int    $repeats     Number of repeated events to create
  * @param int    $timestart   Time stamp of the event start
  * @param mixed  $prop        List of event properties as array or object
  * @return mixed              Event object or false;
  * @since Moodle 2.5
  */
 public static function create_calendar_event($name, $userid = 0, $type = 'user', $repeats = 0, $timestart = null, $prop = null)
 {
     global $CFG, $DB, $USER, $SITE;
     require_once "{$CFG->dirroot}/calendar/lib.php";
     if (!empty($prop)) {
         if (is_array($prop)) {
             $prop = (object) $prop;
         }
     } else {
         $prop = new stdClass();
     }
     $prop->name = $name;
     if (empty($prop->eventtype)) {
         $prop->eventtype = $type;
     }
     if (empty($prop->repeats)) {
         $prop->repeats = $repeats;
     }
     if (empty($prop->timestart)) {
         $prop->timestart = time();
     }
     if (empty($prop->timeduration)) {
         $prop->timeduration = 0;
     }
     if (empty($prop->repeats)) {
         $prop->repeat = 0;
     } else {
         $prop->repeat = 1;
     }
     if (empty($prop->userid)) {
         if (!empty($userid)) {
             $prop->userid = $userid;
         } else {
             return false;
         }
     }
     if (!isset($prop->courseid)) {
         $prop->courseid = $SITE->id;
     }
     $event = new calendar_event($prop);
     return $event->create($prop);
 }
Example #17
0
/**
 * This function updates the events associated to the quiz.
 * If $override is non-zero, then it updates only the events
 * associated with the specified override.
 *
 * @uses QUIZ_MAX_EVENT_LENGTH
 * @param object $quiz the quiz object.
 * @param object optional $override limit to a specific override
 */
function quiz_update_events($quiz, $override = null) {
    global $DB;

    // Load the old events relating to this quiz.
    $conds = array('modulename'=>'quiz',
                   'instance'=>$quiz->id);
    if (!empty($override)) {
        // Only load events for this override.
        $conds['groupid'] = isset($override->groupid)?  $override->groupid : 0;
        $conds['userid'] = isset($override->userid)?  $override->userid : 0;
    }
    $oldevents = $DB->get_records('event', $conds);

    // Now make a todo list of all that needs to be updated.
    if (empty($override)) {
        // We are updating the primary settings for the quiz, so we
        // need to add all the overrides.
        $overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id));
        // As well as the original quiz (empty override).
        $overrides[] = new stdClass();
    } else {
        // Just do the one override.
        $overrides = array($override);
    }

    foreach ($overrides as $current) {
        $groupid   = isset($current->groupid)?  $current->groupid : 0;
        $userid    = isset($current->userid)? $current->userid : 0;
        $timeopen  = isset($current->timeopen)?  $current->timeopen : $quiz->timeopen;
        $timeclose = isset($current->timeclose)? $current->timeclose : $quiz->timeclose;

        // Only add open/close events for an override if they differ from the quiz default.
        $addopen  = empty($current->id) || !empty($current->timeopen);
        $addclose = empty($current->id) || !empty($current->timeclose);

        if (!empty($quiz->coursemodule)) {
            $cmid = $quiz->coursemodule;
        } else {
            $cmid = get_coursemodule_from_instance('quiz', $quiz->id, $quiz->course)->id;
        }

        $event = new stdClass();
        $event->description = format_module_intro('quiz', $quiz, $cmid);
        // Events module won't show user events when the courseid is nonzero.
        $event->courseid    = ($userid) ? 0 : $quiz->course;
        $event->groupid     = $groupid;
        $event->userid      = $userid;
        $event->modulename  = 'quiz';
        $event->instance    = $quiz->id;
        $event->timestart   = $timeopen;
        $event->timeduration = max($timeclose - $timeopen, 0);
        $event->visible     = instance_is_visible('quiz', $quiz);
        $event->eventtype   = 'open';

        // Determine the event name.
        if ($groupid) {
            $params = new stdClass();
            $params->quiz = $quiz->name;
            $params->group = groups_get_group_name($groupid);
            if ($params->group === false) {
                // Group doesn't exist, just skip it.
                continue;
            }
            $eventname = get_string('overridegroupeventname', 'quiz', $params);
        } else if ($userid) {
            $params = new stdClass();
            $params->quiz = $quiz->name;
            $eventname = get_string('overrideusereventname', 'quiz', $params);
        } else {
            $eventname = $quiz->name;
        }
        if ($addopen or $addclose) {
            if ($timeclose and $timeopen and $event->timeduration <= QUIZ_MAX_EVENT_LENGTH) {
                // Single event for the whole quiz.
                if ($oldevent = array_shift($oldevents)) {
                    $event->id = $oldevent->id;
                } else {
                    unset($event->id);
                }
                $event->name = $eventname;
                // The method calendar_event::create will reuse a db record if the id field is set.
                calendar_event::create($event);
            } else {
                // Separate start and end events.
                $event->timeduration  = 0;
                if ($timeopen && $addopen) {
                    if ($oldevent = array_shift($oldevents)) {
                        $event->id = $oldevent->id;
                    } else {
                        unset($event->id);
                    }
                    $event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
                    // The method calendar_event::create will reuse a db record if the id field is set.
                    calendar_event::create($event);
                }
                if ($timeclose && $addclose) {
                    if ($oldevent = array_shift($oldevents)) {
                        $event->id = $oldevent->id;
                    } else {
                        unset($event->id);
                    }
                    $event->name      = $eventname.' ('.get_string('quizcloses', 'quiz').')';
                    $event->timestart = $timeclose;
                    $event->eventtype = 'close';
                    calendar_event::create($event);
                }
            }
        }
    }

    // Delete any leftover events.
    foreach ($oldevents as $badevent) {
        $badevent = calendar_event::load($badevent);
        $badevent->delete();
    }
}
Example #18
0
 /**
  *
  * Updates a calendar event with new details
  * @param object $event a object containing details of an event tot be saved into a users calendar
  */
 function update_event($event)
 {
     global $CFG, $USER;
     if (stripos($CFG->release, "2.") !== false) {
         require_once $CFG->dirroot . '/calendar/lib.php';
         $calevent = calendar_event::load($event->id);
         return $calevent->update($event, false);
     } else {
         return update_event($event);
     }
 }
Example #19
0
/**
 * Update a vpl instance
 *
 * @param object from the form in mod.html
 * @return boolean OK
 *
 **/
function vpl_update_instance($instance)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/calendar/lib.php';
    vpl_truncate_VPL($instance);
    $instance->id = $instance->instance;
    //Update event
    $event = vpl_create_event($instance, $instance->id);
    if ($eventid = $DB->get_field('event', 'id', array('modulename' => VPL, 'instance' => $instance->id))) {
        $event->id = $eventid;
        $calendarevent = calendar_event::load($eventid);
        if ($instance->duedate) {
            $calendarevent->update($event);
        } else {
            $calendarevent->delete();
        }
    } else {
        if ($instance->duedate) {
            calendar_event::create($event);
        }
    }
    $cm = get_coursemodule_from_instance(VPL, $instance->id, $instance->course);
    vpl_update_grade_item($instance, $cm);
    return $DB->update_record(VPL, $instance);
}
Example #20
0
/**
 * Call this function to unhide an event in the calendar table
 * the event will be identified by the id field of the $event object.
 *
 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
 * @return true
 */
function show_event($event) {
    global $CFG;
    require_once($CFG->dirroot.'/calendar/lib.php');
    $event = new calendar_event($event);
    return $event->toggle_visibility(true);
}
Example #21
0
 /**
  * Update the calendar entries for this assignment.
  *
  * @param int $coursemoduleid - Required to pass this in because it might
  *                              not exist in the database yet.
  * @return bool
  */
 public function update_calendar($coursemoduleid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/calendar/lib.php';
     // Special case for add_instance as the coursemodule has not been set yet.
     $instance = $this->get_instance();
     if ($instance->duedate) {
         $event = new stdClass();
         $params = array('modulename' => 'assign', 'instance' => $instance->id);
         $event->id = $DB->get_field('event', 'id', $params);
         $event->name = $instance->name;
         $event->timestart = $instance->duedate;
         // Convert the links to pluginfile. It is a bit hacky but at this stage the files
         // might not have been saved in the module area yet.
         $intro = $instance->intro;
         if ($draftid = file_get_submitted_draft_itemid('introeditor')) {
             $intro = file_rewrite_urls_to_pluginfile($intro, $draftid);
         }
         // We need to remove the links to files as the calendar is not ready
         // to support module events with file areas.
         $intro = strip_pluginfile_content($intro);
         if ($this->show_intro()) {
             $event->description = array('text' => $intro, 'format' => $instance->introformat);
         } else {
             $event->description = array('text' => '', 'format' => $instance->introformat);
         }
         if ($event->id) {
             $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             unset($event->id);
             $event->courseid = $instance->course;
             $event->groupid = 0;
             $event->userid = 0;
             $event->modulename = 'assign';
             $event->instance = $instance->id;
             $event->eventtype = 'due';
             $event->timeduration = 0;
             calendar_event::create($event);
         }
     } else {
         $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id));
     }
 }
Example #22
0
    /**
     * Deletes this lesson from the database
     */
    public function delete() {
        global $CFG, $DB;
        require_once($CFG->libdir.'/gradelib.php');
        require_once($CFG->dirroot.'/calendar/lib.php');

        $DB->delete_records("lesson", array("id"=>$this->properties->id));;
        $DB->delete_records("lesson_pages", array("lessonid"=>$this->properties->id));
        $DB->delete_records("lesson_answers", array("lessonid"=>$this->properties->id));
        $DB->delete_records("lesson_attempts", array("lessonid"=>$this->properties->id));
        $DB->delete_records("lesson_grades", array("lessonid"=>$this->properties->id));
        $DB->delete_records("lesson_timer", array("lessonid"=>$this->properties->id));
        $DB->delete_records("lesson_branch", array("lessonid"=>$this->properties->id));
        $DB->delete_records("lesson_high_scores", array("lessonid"=>$this->properties->id));
        if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$this->properties->id))) {
            foreach($events as $event) {
                $event = calendar_event::load($event);
                $event->delete();
            }
        }

        grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, NULL, array('deleted'=>1));
        return true;
    }
Example #23
0
/**
 * Updates chat records so that the next chat time is correct
 *
 * @global object
 * @param int $chatid
 * @return void
 */
function chat_update_chat_times($chatid = 0)
{
    // Updates chat records so that the next chat time is correct.
    global $DB;
    $timenow = time();
    $params = array('timenow' => $timenow, 'chatid' => $chatid);
    if ($chatid) {
        if (!($chats[] = $DB->get_record_select("chat", "id = :chatid AND chattime <= :timenow AND schedule > 0", $params))) {
            return;
        }
    } else {
        if (!($chats = $DB->get_records_select("chat", "chattime <= :timenow AND schedule > 0", $params))) {
            return;
        }
    }
    foreach ($chats as $chat) {
        switch ($chat->schedule) {
            case 1:
                // Single event - turn off schedule and disable.
                $chat->chattime = 0;
                $chat->schedule = 0;
                break;
            case 2:
                // Repeat daily.
                while ($chat->chattime <= $timenow) {
                    $chat->chattime += 24 * 3600;
                }
                break;
            case 3:
                // Repeat weekly.
                while ($chat->chattime <= $timenow) {
                    $chat->chattime += 7 * 24 * 3600;
                }
                break;
        }
        $DB->update_record("chat", $chat);
        $event = new stdClass();
        // Update calendar too.
        $cond = "modulename='chat' AND instance = :chatid AND timestart <> :chattime";
        $params = array('chattime' => $chat->chattime, 'chatid' => $chatid);
        if ($event->id = $DB->get_field_select('event', 'id', $cond, $params)) {
            $event->timestart = $chat->chattime;
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->update($event, false);
        }
    }
}
Example #24
0
/**
 * deletes an instance of a data
 *
 * @global object
 * @param int $id
 * @return bool
 */
function data_delete_instance($id)
{
    // takes the dataid
    global $DB, $CFG;
    if (!($data = $DB->get_record('data', array('id' => $id)))) {
        return false;
    }
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = context_module::instance($cm->id);
    /// Delete all the associated information
    // files
    $fs = get_file_storage();
    $fs->delete_area_files($context->id, 'mod_data');
    // get all the records in this data
    $sql = "SELECT r.id\n              FROM {data_records} r\n             WHERE r.dataid = ?";
    $DB->delete_records_select('data_content', "recordid IN ({$sql})", array($id));
    // delete all the records and fields
    $DB->delete_records('data_records', array('dataid' => $id));
    $DB->delete_records('data_fields', array('dataid' => $id));
    // Remove old calendar events.
    $events = $DB->get_records('event', array('modulename' => 'data', 'instance' => $id));
    foreach ($events as $event) {
        $event = calendar_event::load($event);
        $event->delete();
    }
    // Delete the instance itself
    $result = $DB->delete_records('data', array('id' => $id));
    // cleanup gradebook
    data_grade_item_delete($data);
    return $result;
}
 /**
  * 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;
 }
Example #26
0
/**
 * Runs any processes that must be run
 * after a lesson insert/update
 *
 * @global object
 * @param object $lesson Lesson form data
 * @return void
 **/
function lesson_process_post_save(&$lesson)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/calendar/lib.php';
    require_once $CFG->dirroot . '/mod/lesson/locallib.php';
    if ($events = $DB->get_records('event', array('modulename' => 'lesson', 'instance' => $lesson->id))) {
        foreach ($events as $event) {
            $event = calendar_event::load($event->id);
            $event->delete();
        }
    }
    $event = new stdClass();
    $event->description = $lesson->name;
    $event->courseid = $lesson->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'lesson';
    $event->instance = $lesson->id;
    $event->eventtype = 'open';
    $event->timestart = $lesson->available;
    $event->visible = instance_is_visible('lesson', $lesson);
    $event->timeduration = $lesson->deadline - $lesson->available;
    if ($lesson->deadline and $lesson->available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) {
        // Single event for the whole lesson.
        $event->name = $lesson->name;
        calendar_event::create(clone $event);
    } else {
        // Separate start and end events.
        $event->timeduration = 0;
        if ($lesson->available) {
            $event->name = $lesson->name . ' (' . get_string('lessonopens', 'lesson') . ')';
            calendar_event::create(clone $event);
        }
        if ($lesson->deadline) {
            $event->name = $lesson->name . ' (' . get_string('lessoncloses', 'lesson') . ')';
            $event->timestart = $lesson->deadline;
            $event->eventtype = 'close';
            calendar_event::create(clone $event);
        }
    }
}
Example #27
0
 /**
  * Update the calendar entries for this assignment.
  *
  * @param int $coursemoduleid - Required to pass this in because it might
  *                              not exist in the database yet.
  * @return bool
  */
 public function update_calendar($coursemoduleid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/calendar/lib.php';
     // Special case for add_instance as the coursemodule has not been set yet.
     $instance = $this->get_instance();
     if ($instance->duedate) {
         $event = new stdClass();
         $params = array('modulename' => 'assign', 'instance' => $instance->id);
         $event->id = $DB->get_field('event', 'id', $params);
         if ($event->id) {
             $event->name = $instance->name;
             $event->description = format_module_intro('assign', $instance, $coursemoduleid);
             $event->timestart = $instance->duedate;
             $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             $event = new stdClass();
             $event->name = $instance->name;
             $event->description = format_module_intro('assign', $instance, $coursemoduleid);
             $event->courseid = $instance->course;
             $event->groupid = 0;
             $event->userid = 0;
             $event->modulename = 'assign';
             $event->instance = $instance->id;
             $event->eventtype = 'due';
             $event->timestart = $instance->duedate;
             $event->timeduration = 0;
             calendar_event::create($event);
         }
     } else {
         $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id));
     }
 }
Example #28
0
/**
 * This function will handles the whole deletion process of a module. This includes calling
 * the modules delete_instance function, deleting files, events, grades, conditional data,
 * the data in the course_module and course_sections table and adding a module deletion
 * event to the DB.
 *
 * @param int $cmid the course module id
 * @since 2.5
 */
function course_delete_module($cmid)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/gradelib.php';
    require_once $CFG->dirroot . '/blog/lib.php';
    require_once $CFG->dirroot . '/calendar/lib.php';
    // Get the course module.
    if (!($cm = $DB->get_record('course_modules', array('id' => $cmid)))) {
        return true;
    }
    // Get the module context.
    $modcontext = context_module::instance($cm->id);
    // Get the course module name.
    $modulename = $DB->get_field('modules', 'name', array('id' => $cm->module), MUST_EXIST);
    // Get the file location of the delete_instance function for this module.
    $modlib = "{$CFG->dirroot}/mod/{$modulename}/lib.php";
    // Include the file required to call the delete_instance function for this module.
    if (file_exists($modlib)) {
        require_once $modlib;
    } else {
        throw new moodle_exception('cannotdeletemodulemissinglib', '', '', null, "Cannot delete this module as the file mod/{$modulename}/lib.php is missing.");
    }
    $deleteinstancefunction = $modulename . '_delete_instance';
    // Ensure the delete_instance function exists for this module.
    if (!function_exists($deleteinstancefunction)) {
        throw new moodle_exception('cannotdeletemodulemissingfunc', '', '', null, "Cannot delete this module as the function {$modulename}_delete_instance is missing in mod/{$modulename}/lib.php.");
    }
    // Call the delete_instance function, if it returns false throw an exception.
    if (!$deleteinstancefunction($cm->instance)) {
        throw new moodle_exception('cannotdeletemoduleinstance', '', '', null, "Cannot delete the module {$modulename} (instance).");
    }
    // Remove all module files in case modules forget to do that.
    $fs = get_file_storage();
    $fs->delete_area_files($modcontext->id);
    // Delete events from calendar.
    if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) {
        foreach ($events as $event) {
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->delete();
        }
    }
    // Delete grade items, outcome items and grades attached to modules.
    if ($grade_items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $cm->instance, 'courseid' => $cm->course))) {
        foreach ($grade_items as $grade_item) {
            $grade_item->delete('moddelete');
        }
    }
    // Delete completion and availability data; it is better to do this even if the
    // features are not turned on, in case they were turned on previously (these will be
    // very quick on an empty table).
    $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
    $DB->delete_records('course_modules_availability', array('coursemoduleid' => $cm->id));
    $DB->delete_records('course_modules_avail_fields', array('coursemoduleid' => $cm->id));
    $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
    // Delete the context.
    context_helper::delete_instance(CONTEXT_MODULE, $cm->id);
    // Delete the module from the course_modules table.
    $DB->delete_records('course_modules', array('id' => $cm->id));
    // Delete module from that section.
    if (!delete_mod_from_section($cm->id, $cm->section)) {
        throw new moodle_exception('cannotdeletemodulefromsection', '', '', null, "Cannot delete the module {$modulename} (instance) from section.");
    }
    // Trigger event for course module delete action.
    $event = \core\event\course_module_deleted::create(array('courseid' => $cm->course, 'context' => $modcontext, 'objectid' => $cm->id, 'other' => array('modulename' => $modulename, 'instanceid' => $cm->instance)));
    $event->add_record_snapshot('course_modules', $cm);
    $event->trigger();
    rebuild_course_cache($cm->course, true);
}
Example #29
0
<?php

$id = get_request_variable('id', '');
$save = get_request_variable('save', '');
$start_date = get_request_variable('start_date', date('Y-m-d'));
$stop_date = get_request_variable('stop_date', date('Y-m-d'));
$calendar = new calendar();
$calendar->loadDefault($STORAGE['current_employee']->login);
$ids = calendar::getIdsForAuthor($STORAGE['current_employee']->login);
$event = new calendar_event();
$event->id_event = $id;
if ($id) {
    if (!$event->Load()) {
        $event->id_event = 0;
    } elseif (!in_array($event->calendar_id, $ids)) {
        $event->init();
    }
} else {
    $event->id_event = 0;
}
if ($save) {
    if ($event->calendar_id == 0) {
        $event->calendar_id = $calendar->id_calendar;
    }
    $event->what = get_request_variable('what', '');
    $event->where = get_request_variable('where', '');
    $event->description = get_request_variable('description', '');
    $event->completed = get_request_variable('completed', 'no');
    $event->notice = get_request_variable('notice', 'no');
    $event->mark = get_request_variable('mark', 'no');
    $event->start_date = parse_date('{Y}-{m}-{d}', $start_date, false);
Example #30
0
 function create_events($events)
 {
     global $CFG, $DB, $USER;
     foreach ($events as $event) {
         $user = get_complete_user_data('username', $event['username']);
         $event['userid'] = $user->id;
         // Let us set some defaults.
         $event['modulename'] = '';
         $event['instance'] = 0;
         $event['subscriptionid'] = null;
         $event['uuid'] = '';
         $event['format'] = 1;
         $event['repeat'] = 0;
         $event['timeduration'] = $event['timeend'] - $event['timestart'];
         $eventobj = new calendar_event($event);
         // Let's create the event.
         $var = $eventobj->create($event);
     }
     return count($events);
 }