Esempio n. 1
0
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will create a new instance and return the id number
 * of the new instance.
 *
 * @param object $opencast Moodle {opencast} table DB record
 *
 * @return int newly created instance ID
 */
function opencast_add_instance($opencast)
{
    global $DB, $USER;
    $opencast->timemodified = time();
    $scast = new mod_opencast_series();
    if (isset($opencast->newchannelname)) {
        $scast->setChannelName($opencast->newchannelname);
    }
    //$scast->setCourseId();
    //    $scast->setLicense($opencast->license);
    //    $scast->setDepartment($opencast->department);
    $scast->setAllowAnnotations($opencast->allow_annotations == OPENCAST_ANNOTATIONS);
    //    if (isset($opencast->template_id)) { // not set if creating new instance with existing channel
    //        $scast->setTemplateId($opencast->template_id);
    //    }
    $scast->setIvt($opencast->is_ivt);
    if (isset($opencast->inviting)) {
        $scast->setInvitingPossible($opencast->inviting);
    }
    $scast->setOrganizationDomain(mod_opencast_series::getOrganizationByEmail($USER->email));
    $opencast->organization_domain = $scast->getOrganization();
    if ($opencast->channelnew == OPENCAST_CHANNEL_NEW) {
        // New channel
        $scast->setProducer(mod_opencast_user::getExtIdFromMoodleUserId($USER->id));
        $scast->doCreate();
        $opencast->ext_id = $scast->getExtId();
    } else {
        // Existing channel
        $scast->setExtId($opencast->ext_id);
        $scast->update();
    }
    if (empty($opencast->timerestrict)) {
        $opencast->timeopen = 0;
        $opencast->timeclose = 0;
    }
    $opencast->id = $DB->insert_record('opencast', $opencast);
    return $opencast->id;
}