Ejemplo 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;
}
Ejemplo n.º 2
0
 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $scuser = new mod_opencast_user();
     if ($data['channelnew'] == OPENCAST_CHANNEL_NEW) {
         if ($scuser->getExternalAccount() == '') {
             $errors['channelnew'] = get_string('user_notaai', 'opencast');
         }
         if (!$data['newchannelname']) {
             $errors['newchannelname'] = get_string('required');
         }
     }
     if ($data['channelnew'] == OPENCAST_CHANNEL_EXISTING) {
         // make sure we can be external_authority for this channel
         $scobj = new mod_opencast_series();
         $ext_id = isset($data['ext_id']) ? $data['ext_id'] : $this->current->ext_id;
         $scobj->setExtId($ext_id);
         $sysaccount_extid = mod_opencast_series::getSysAccountOfUser();
         // we must explicitly set $USER as a producer in $scobj or we won't be allowed to add his system_user
         $scobj->setOrganizationDomain(mod_opencast_series::getOrganizationByEmail($sysaccount_extid));
         $scobj->setProducer($scuser->getExternalAccount());
         // first, add SysAccount as producer (using $USER account), so we can use SysAccount later to make API calls
         //            $scobj->addProducer($sysaccount_extid, false);
         $channelid = empty($this->_instance) ? $ext_id : $this->current->id;
         // if there already is one instance we must refer to it by its Moodle ID otherwise there could
         // be several records!
         $thechannel = $scobj->fetch($channelid, !empty($this->_instance), true);
     } else {
         if ($data['groupmode'] != NOGROUPS && !$data['is_ivt']) {
             $errors['groupmode'] = get_string('nogroups_withoutivt', 'opencast');
         }
     }
     return $errors;
 }