Ejemplo n.º 1
0
/**
 * Updates an instance of the collaborate 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 $collaborate An object from the form in mod_form.php
 * @param mod_collaborate_mod_form $mform The form instance itself (if needed)
 * @return boolean Success/Fail
 */
function collaborate_update_instance(stdClass $collaborate, mod_collaborate_mod_form $mform = null)
{
    global $DB, $COURSE;
    $htmlsession = local::el_update_html_session($collaborate, $collaborate->course);
    $api = api::get_api();
    if ($htmlsession instanceof SetHtmlSession) {
        $collaborate->timeend = local::timeend_from_duration($collaborate->timestart, $collaborate->duration);
        $collaborate->sessionid = local::api_create_session($collaborate, $COURSE);
        $result = $api->SetHtmlSession($htmlsession);
    } else {
        if ($htmlsession instanceof UpdateHtmlSessionDetails) {
            $result = $api->UpdateHtmlSession($htmlsession);
        } else {
            $msg = 'el_update_html_session returned an unexpected object. ';
            $msg .= 'Should have been either mod_collaborate\\soap\\generated\\SetHtmlSession OR ';
            $msg .= 'mod_collaborate\\soap\\generated\\UpdateHtmlSessionDetails. ';
            $msg .= 'Returned: ' . var_export($htmlsession, true);
            throw new coding_exception($msg);
        }
    }
    // Re-get html session from result. This means that we are guaranteeing our
    // module data is exactly the same as what is on the collaborate end!
    $htmlsessioncollection = $result->getHtmlSession();
    $htmlsession = $htmlsessioncollection[0];
    if (empty($collaborate->id)) {
        $collaborate->id = $collaborate->instance;
    }
    $collaborate->timemodified = time();
    $collaborate->timestart = $htmlsession->getStartTime()->getTimestamp();
    $collaborate->timeend = $htmlsession->getEndTime()->getTimestamp();
    $result = $DB->update_record('collaborate', $collaborate);
    collaborate_grade_item_update($collaborate);
    local::update_calendar($collaborate);
    return $result;
}