本文整理汇总了PHP中file_get_unused_draft_itemid函数的典型用法代码示例。如果您正苦于以下问题:PHP file_get_unused_draft_itemid函数的具体用法?PHP file_get_unused_draft_itemid怎么用?PHP file_get_unused_draft_itemid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_get_unused_draft_itemid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: toHtml
function toHtml() {
global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
$id = $this->_attributes['id'];
$elname = $this->_attributes['name'];
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
}
if (!$draftitemid = (int)$this->getValue()) {
// no existing area info provided - let's use fresh new draft area
$draftitemid = file_get_unused_draft_itemid();
$this->setValue($draftitemid);
}
if ($COURSE->id == SITEID) {
$context = get_context_instance(CONTEXT_SYSTEM);
} else {
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
}
$client_id = uniqid();
$args = new stdClass();
// need these three to filter repositories list
$args->accepted_types = $this->_options['accepted_types']?$this->_options['accepted_types']:'*';
$args->return_types = FILE_INTERNAL;
$args->itemid = $draftitemid;
$args->maxbytes = $this->_options['maxbytes'];
$args->context = $PAGE->context;
$args->buttonname = $elname.'choose';
$html = $this->_getTabs();
$fp = new file_picker($args);
$options = $fp->options;
$options->context = $PAGE->context;
$html .= $OUTPUT->render($fp);
$html .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" value="'.$draftitemid.'" class="filepickerhidden"/>';
$module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker'));
$PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
$nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array(
'env'=>'filepicker',
'action'=>'browse',
'itemid'=>$draftitemid,
'subdirs'=>0,
'maxbytes'=>$options->maxbytes,
'maxfiles'=>1,
'ctx_id'=>$PAGE->context->id,
'course'=>$PAGE->course->id,
'sesskey'=>sesskey(),
));
// non js file picker
$html .= '<noscript>';
$html .= "<div><object type='text/html' data='$nonjsfilepicker' height='160' width='600' style='border:1px solid #000'></object></div>";
$html .= '</noscript>';
return $html;
}
开发者ID:nottmoo,项目名称:moodle,代码行数:60,代码来源:filepicker.php
示例2: test_create_instance
public function test_create_instance()
{
global $DB, $CFG, $USER;
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$this->assertFalse($DB->record_exists('imscp', array('course' => $course->id)));
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course));
$records = $DB->get_records('imscp', array('course' => $course->id), 'id');
$this->assertEquals(1, count($records));
$this->assertTrue(array_key_exists($imscp->id, $records));
$params = array('course' => $course->id, 'name' => 'Another imscp');
$imscp = $this->getDataGenerator()->create_module('imscp', $params);
$records = $DB->get_records('imscp', array('course' => $course->id), 'id');
$this->assertEquals(2, count($records));
$this->assertEquals('Another imscp', $records[$imscp->id]->name);
// Examples of specifying the package file (do not validate anything, just check for exceptions).
// 1. As path to the file in filesystem:
$params = array('course' => $course->id, 'packagepath' => $CFG->dirroot . '/mod/imscp/tests/packages/singlescobasic.zip');
$imscp = $this->getDataGenerator()->create_module('imscp', $params);
// 2. As file draft area id:
$fs = get_file_storage();
$params = array('course' => $course->id, 'package' => file_get_unused_draft_itemid());
$usercontext = context_user::instance($USER->id);
$filerecord = array('component' => 'user', 'filearea' => 'draft', 'contextid' => $usercontext->id, 'itemid' => $params['package'], 'filename' => 'singlescobasic.zip', 'filepath' => '/');
$fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/mod/imscp/tests/packages/singlescobasic.zip');
$imscp = $this->getDataGenerator()->create_module('imscp', $params);
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:28,代码来源:generator_test.php
示例3: create_instance
public function create_instance($record = null, array $options = null)
{
global $CFG, $USER;
require_once $CFG->dirroot . '/mod/scorm/lib.php';
require_once $CFG->dirroot . '/mod/scorm/locallib.php';
$cfgscorm = get_config('scorm');
// Add default values for scorm.
$record = (array) $record + array('scormtype' => SCORM_TYPE_LOCAL, 'packagefile' => '', 'packagefilepath' => $CFG->dirroot . '/mod/scorm/tests/packages/singlescobasic.zip', 'packageurl' => '', 'updatefreq' => SCORM_UPDATE_NEVER, 'popup' => 0, 'width' => $cfgscorm->framewidth, 'height' => $cfgscorm->frameheight, 'skipview' => $cfgscorm->skipview, 'hidebrowse' => $cfgscorm->hidebrowse, 'displaycoursestructure' => $cfgscorm->displaycoursestructure, 'hidetoc' => $cfgscorm->hidetoc, 'nav' => $cfgscorm->nav, 'navpositionleft' => $cfgscorm->navpositionleft, 'navpositiontop' => $cfgscorm->navpositiontop, 'displayattemptstatus' => $cfgscorm->displayattemptstatus, 'timeopen' => 0, 'timeclose' => 0, 'grademethod' => GRADESCOES, 'maxgrade' => $cfgscorm->maxgrade, 'maxattempt' => $cfgscorm->maxattempt, 'whatgrade' => $cfgscorm->whatgrade, 'forcenewattempt' => $cfgscorm->forcenewattempt, 'lastattemptlock' => $cfgscorm->lastattemptlock, 'forcecompleted' => $cfgscorm->forcecompleted, 'auto' => $cfgscorm->auto);
// The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) {
if (!isloggedin() || isguestuser()) {
throw new coding_exception('Scorm generator requires a current user');
}
if (!file_exists($record['packagefilepath'])) {
throw new coding_exception("File {$record['packagefilepath']} does not exist");
}
$usercontext = context_user::instance($USER->id);
// Pick a random context id for specified user.
$record['packagefile'] = file_get_unused_draft_itemid();
// Add actual file there.
$filerecord = array('component' => 'user', 'filearea' => 'draft', 'contextid' => $usercontext->id, 'itemid' => $record['packagefile'], 'filename' => basename($record['packagefilepath']), 'filepath' => '/');
$fs = get_file_storage();
$fs->create_file_from_pathname($filerecord, $record['packagefilepath']);
}
return parent::create_instance($record, (array) $options);
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:26,代码来源:lib.php
示例4: test_assessable_uploaded
public function test_assessable_uploaded()
{
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$params['course'] = $course->id;
$instance = $generator->create_instance($params);
$cm = get_coursemodule_from_instance('assign', $instance->id);
$context = context_module::instance($cm->id);
$assign = new testable_assign($context, $cm, $course);
$this->setUser($user->id);
$submission = $assign->get_user_submission($user->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_PLAIN);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$sink = $this->redirectEvents();
$plugin->save($submission, $data);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\\assignsubmission_onlinetext\\event\\assessable_uploaded', $event);
$this->assertEquals($context->id, $event->contextid);
$this->assertEquals($submission->id, $event->objectid);
$this->assertEquals(array(), $event->other['pathnamehashes']);
$this->assertEquals('Submission text', $event->other['content']);
$expected = new stdClass();
$expected->modulename = 'assign';
$expected->cmid = $cm->id;
$expected->itemid = $submission->id;
$expected->courseid = $course->id;
$expected->userid = $user->id;
$expected->content = 'Submission text';
$this->assertEventLegacyData($expected, $event);
}
开发者ID:covex-nn,项目名称:moodle,代码行数:35,代码来源:events_test.php
示例5: create_instance
public function create_instance($record = null, array $options = null)
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$workshopconfig = get_config('workshop');
// Add default values for workshop.
$record = (array) $record + array('strategy' => $workshopconfig->strategy, 'grade' => $workshopconfig->grade, 'gradinggrade' => $workshopconfig->gradinggrade, 'gradedecimals' => $workshopconfig->gradedecimals, 'nattachments' => 1, 'maxbytes' => $workshopconfig->maxbytes, 'latesubmissions' => 0, 'useselfassessment' => 0, 'overallfeedbackmode' => 1, 'overallfeedbackfiles' => 0, 'overallfeedbackmaxbytes' => $workshopconfig->maxbytes, 'useexamples' => 0, 'examplesmode' => $workshopconfig->examplesmode, 'submissionstart' => 0, 'submissionend' => 0, 'phaseswitchassessment' => 0, 'assessmentstart' => 0, 'assessmentend' => 0);
if (!isset($record['gradecategory']) || !isset($record['gradinggradecategory'])) {
require_once $CFG->libdir . '/gradelib.php';
$courseid = is_object($record['course']) ? $record['course']->id : $record['course'];
$gradecategories = grade_get_categories_menu($courseid);
reset($gradecategories);
$defaultcategory = key($gradecategories);
$record += array('gradecategory' => $defaultcategory, 'gradinggradecategory' => $defaultcategory);
}
if (!isset($record['instructauthorseditor'])) {
$record['instructauthorseditor'] = array('text' => 'Instructions for submission ' . ($this->instancecount + 1), 'format' => FORMAT_MOODLE, 'itemid' => file_get_unused_draft_itemid());
}
if (!isset($record['instructreviewerseditor'])) {
$record['instructreviewerseditor'] = array('text' => 'Instructions for assessment ' . ($this->instancecount + 1), 'format' => FORMAT_MOODLE, 'itemid' => file_get_unused_draft_itemid());
}
if (!isset($record['conclusioneditor'])) {
$record['conclusioneditor'] = array('text' => 'Conclusion ' . ($this->instancecount + 1), 'format' => FORMAT_MOODLE, 'itemid' => file_get_unused_draft_itemid());
}
return parent::create_instance($record, (array) $options);
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:26,代码来源:lib.php
示例6: display_add_field
function display_add_field($recordid = 0)
{
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
$file = false;
$content = false;
$displayname = '';
$fs = get_file_storage();
$context = $PAGE->context;
$itemid = null;
// editing an existing database entry
if ($recordid) {
if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
if (!empty($content->content)) {
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
$usercontext = context_user::instance($USER->id);
if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) {
return false;
}
if (empty($content->content1)) {
// Print icon if file already exists
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>';
} else {
$displayname = 'no file added';
}
}
}
}
} else {
$itemid = file_get_unused_draft_itemid();
}
$html = '';
// database entry label
$html .= '<div title="' . s($this->field->description) . '">';
$html .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>';
// itemid element
$html .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />';
$options = new stdClass();
$options->maxbytes = $this->field->param3;
$options->maxfiles = 1;
// Limit to one file for the moment, this may be changed if requested as a feature in the future.
$options->itemid = $itemid;
$options->accepted_types = '*';
$options->return_types = FILE_INTERNAL;
$options->context = $PAGE->context;
$fm = new form_filemanager($options);
// Print out file manager.
$output = $PAGE->get_renderer('core', 'files');
$html .= $output->render($fm);
$html .= '</fieldset>';
$html .= '</div>';
$module = array('name' => 'form_filemanager', 'fullpath' => '/lib/form/filemanager.js', 'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), 'strings' => array(array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), array('confirmrenamefile', 'repository'), array('edit', 'moodle')));
$PAGE->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module);
return $html;
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:56,代码来源:field.class.php
示例7: toHtml
public function toHtml()
{
global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
$id = $this->_attributes['id'];
$elname = $this->_attributes['name'];
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
}
if (!($draftitemid = (int) $this->getValue())) {
// no existing area info provided - let's use fresh new draft area
$draftitemid = file_get_unused_draft_itemid();
$this->setValue($draftitemid);
}
if ($COURSE->id == SITEID) {
$context = context_system::instance();
} else {
$context = context_course::instance($COURSE->id);
}
$client_id = uniqid();
$args = new stdClass();
// Need these three to filter repositories list.
$args->accepted_types = $this->_options['accepted_types'] ? $this->_options['accepted_types'] : '*';
$args->return_types = $this->_options['return_types'];
$args->itemid = $draftitemid;
$args->maxbytes = 0;
$args->context = $PAGE->context;
$args->buttonname = $elname . 'choose';
$args->elementname = $elname;
// We can only tell the filepicker that we want FILE_REFERENCE repos
// and which specific repo types we don't want. So here we build a list
// of all FILE_REFERENCE supplying repos that aren't thebox to force
// it to only display that one.
$refrepos = repository::get_instances(array('currentcontext' => $PAGE->context, 'return_types' => FILE_REFERENCE));
$disabled = array();
foreach ($refrepos as $repo) {
if (($name = $repo->get_typename()) != $this->repo) {
$disabled[] = $name;
}
}
$args->disable_types = $disabled;
$html = $this->_getTabs();
$fp = new file_picker($args);
$options = $fp->options;
$options->context = $PAGE->context;
$html .= $OUTPUT->render($fp);
$html .= '<input type="hidden" name="' . $elname . '" id="' . $id . '" value="' . $draftitemid . '" class="filepickerhidden"/>';
$module = array('name' => 'form_filepicker', 'fullpath' => '/lib/form/filepicker.js', 'requires' => array('core_filepicker', 'node', 'node-event-simulate', 'core_dndupload'));
$PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
$nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array('env' => 'filepicker', 'action' => 'browse', 'itemid' => $draftitemid, 'subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'ctx_id' => $PAGE->context->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey()));
// non js file picker
$html .= '<noscript>';
$html .= "<div><object type='text/html' data='{$nonjsfilepicker}' height='160' width='600' style='border:1px solid #000'></object></div>";
$html .= '</noscript>';
return $html;
}
开发者ID:eSrem,项目名称:moodle-mod_mediagallery,代码行数:55,代码来源:uploader.php
示例8: output_html
/**
* Returns an XHTML string for the editor
*
* @param string $data
* @param string $query
* @return string XHTML string for the editor
*/
public function output_html($data, $query = '')
{
global $USER;
$default = $this->get_defaultsetting();
$defaultinfo = $default;
if (!is_null($default) and $default !== '') {
$defaultinfo = "\n" . $default;
}
$ctx = context_user::instance($USER->id);
$editor = editors_get_preferred_editor(FORMAT_HTML);
$options = $this->get_options();
$draftitemid = file_get_unused_draft_itemid();
$component = is_null($this->plugin) ? 'core' : $this->plugin;
$data = file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->get_full_name() . '_draftitemid', $draftitemid, $options, $data);
$fpoptions = array();
$args = new stdClass();
// need these three to filter repositories list
$args->accepted_types = array('web_image');
$args->return_types = $options['return_types'];
$args->context = $ctx;
$args->env = 'filepicker';
// advimage plugin
$image_options = initialise_filepicker($args);
$image_options->context = $ctx;
$image_options->client_id = uniqid();
$image_options->maxbytes = $options['maxbytes'];
$image_options->areamaxbytes = $options['areamaxbytes'];
$image_options->env = 'editor';
$image_options->itemid = $draftitemid;
// moodlemedia plugin
$args->accepted_types = array('video', 'audio');
$media_options = initialise_filepicker($args);
$media_options->context = $ctx;
$media_options->client_id = uniqid();
$media_options->maxbytes = $options['maxbytes'];
$media_options->areamaxbytes = $options['areamaxbytes'];
$media_options->env = 'editor';
$media_options->itemid = $draftitemid;
// advlink plugin
$args->accepted_types = '*';
$link_options = initialise_filepicker($args);
$link_options->context = $ctx;
$link_options->client_id = uniqid();
$link_options->maxbytes = $options['maxbytes'];
$link_options->areamaxbytes = $options['areamaxbytes'];
$link_options->env = 'editor';
$link_options->itemid = $draftitemid;
$fpoptions['image'] = $image_options;
$fpoptions['media'] = $media_options;
$fpoptions['link'] = $link_options;
$editor->use_editor($this->get_id(), $options, $fpoptions);
return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"><textarea rows="' . $this->rows . '" cols="' . $this->cols . '" id="' . $this->get_id() . '" name="' . $this->get_full_name() . '" spellcheck="true">' . s($data) . '</textarea></div>
<input value="' . $draftitemid . '" name="' . $this->get_full_name() . '_draftitemid" type="hidden" />', $this->description, true, '', $defaultinfo, $query);
}
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:61,代码来源:admin_confightmleditor.php
示例9: create_instance
public function create_instance($record = null, array $options = null)
{
global $CFG;
// Add default values for lesson.
$record = (array) $record + array('progressbar' => 0, 'ongoing' => 0, 'displayleft' => 0, 'displayleftif' => 0, 'slideshow' => 0, 'maxanswers' => $CFG->lesson_maxanswers, 'feedback' => 0, 'activitylink' => 0, 'available' => 0, 'deadline' => 0, 'usepassword' => 0, 'password' => '', 'dependency' => 0, 'timespent' => 0, 'completed' => 0, 'gradebetterthan' => 0, 'modattempts' => 0, 'review' => 0, 'maxattempts' => 1, 'nextpagedefault' => $CFG->lesson_defaultnextpage, 'maxpages' => 0, 'practice' => 0, 'custom' => 1, 'retake' => 0, 'usemaxgrade' => 0, 'minquestions' => 0, 'grade' => 100);
if (!isset($record['mediafile'])) {
require_once $CFG->libdir . '/filelib.php';
$record['mediafile'] = file_get_unused_draft_itemid();
}
return parent::create_instance($record, (array) $options);
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:11,代码来源:lib.php
示例10: display_add_field
function display_add_field($recordid = 0)
{
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
$file = false;
$content = false;
$displayname = '';
$fs = get_file_storage();
$context = $PAGE->context;
$itemid = null;
// editing an existing database entry
if ($recordid) {
if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
if (!empty($content->content)) {
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
$usercontext = context_user::instance($USER->id);
if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) {
return false;
}
if (empty($content->content1)) {
// Print icon if file already exists
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>';
} else {
$displayname = 'no file added';
}
}
}
}
} else {
$itemid = file_get_unused_draft_itemid();
}
$html = '';
// database entry label
$html .= '<div title="' . s($this->field->description) . '">';
$html .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>';
// itemid element
$html .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />';
$options = new stdClass();
$options->maxbytes = $this->field->param3;
$options->maxfiles = 1;
// Limit to one file for the moment, this may be changed if requested as a feature in the future.
$options->itemid = $itemid;
$options->accepted_types = '*';
$options->return_types = FILE_INTERNAL;
$options->context = $PAGE->context;
$fm = new form_filemanager($options);
// Print out file manager.
$output = $PAGE->get_renderer('core', 'files');
$html .= $output->render($fm);
$html .= '</fieldset>';
$html .= '</div>';
return $html;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:54,代码来源:field.class.php
示例11: create_instance
public function create_instance($record = null, array $options = null)
{
// Add default values for folder.
$record = (array) $record + array('display' => 0);
if (!isset($record['showexpanded'])) {
$record['showexpanded'] = get_config('folder', 'showexpanded');
}
if (!isset($record['files'])) {
$record['files'] = file_get_unused_draft_itemid();
}
return parent::create_instance($record, (array) $options);
}
开发者ID:evltuma,项目名称:moodle,代码行数:12,代码来源:lib.php
示例12: display_add_field
function display_add_field($recordid = 0)
{
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
$file = false;
$content = false;
$displayname = '';
$fs = get_file_storage();
$context = $PAGE->context;
$itemid = null;
// editing an existing database entry
if ($recordid) {
if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id);
if (!empty($content->content)) {
if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) {
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) {
return false;
}
if (empty($content->content1)) {
// Print icon if file already exists
$src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename());
$displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>';
} else {
$displayname = 'no file added';
}
}
}
}
} else {
$itemid = file_get_unused_draft_itemid();
}
$html = '';
// database entry label
$html .= '<div title="' . s($this->field->description) . '">';
$html .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>';
// itemid element
$html .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />';
$options = new stdClass();
$options->maxbytes = $this->field->param3;
$options->itemid = $itemid;
$options->accepted_types = '*';
$options->return_types = FILE_INTERNAL;
$options->context = $PAGE->context;
$fp = new file_picker($options);
// print out file picker
$html .= $OUTPUT->render($fp);
$html .= '</fieldset>';
$html .= '</div>';
$module = array('name' => 'data_filepicker', 'fullpath' => '/mod/data/data.js', 'requires' => array('core_filepicker'));
$PAGE->requires->js_init_call('M.data_filepicker.init', array($fp->options), true, $module);
return $html;
}
开发者ID:nmicha,项目名称:moodle,代码行数:53,代码来源:field.class.php
示例13: create_instance
public function create_instance($record = null, array $options = null)
{
global $CFG;
// Add default values for lesson.
$lessonconfig = get_config('mod_lesson');
$record = (array) $record + array('progressbar' => $lessonconfig->progressbar, 'ongoing' => $lessonconfig->ongoing, 'displayleft' => $lessonconfig->displayleftmenu, 'displayleftif' => $lessonconfig->displayleftif, 'slideshow' => $lessonconfig->slideshow, 'maxanswers' => $lessonconfig->maxanswers, 'feedback' => $lessonconfig->defaultfeedback, 'activitylink' => 0, 'available' => 0, 'deadline' => 0, 'usepassword' => 0, 'password' => '', 'dependency' => 0, 'timespent' => 0, 'completed' => 0, 'gradebetterthan' => 0, 'modattempts' => $lessonconfig->modattempts, 'review' => $lessonconfig->displayreview, 'maxattempts' => $lessonconfig->maximumnumberofattempts, 'nextpagedefault' => $lessonconfig->defaultnextpage, 'maxpages' => $lessonconfig->numberofpagestoshow, 'practice' => $lessonconfig->practice, 'custom' => $lessonconfig->customscoring, 'retake' => $lessonconfig->retakesallowed, 'usemaxgrade' => $lessonconfig->handlingofretakes, 'minquestions' => $lessonconfig->minimumnumberofquestions, 'grade' => 100);
if (!isset($record['mediafile'])) {
require_once $CFG->libdir . '/filelib.php';
$record['mediafile'] = file_get_unused_draft_itemid();
}
return parent::create_instance($record, (array) $options);
}
开发者ID:evltuma,项目名称:moodle,代码行数:12,代码来源:lib.php
示例14: create_assign_and_submit_text
/**
* Create an assign object and submit an online text submission.
*/
protected function create_assign_and_submit_text()
{
$assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1, 'assignfeedback_comments_enabled' => 1));
$user = $this->students[0];
$this->setUser($user);
// Create an online text submission.
$submission = $assign->get_user_submission($user->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('text' => '<p>This is some text.</p>', 'format' => 1, 'itemid' => file_get_unused_draft_itemid());
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$plugin->save($submission, $data);
return $assign;
}
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:comments_test.php
示例15: test_attach_files
/**
* Test for folder file attachments.
*
* @return void
*/
public function test_attach_files()
{
global $USER;
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$fs = get_file_storage();
$usercontext = context_user::instance($USER->id);
$record = new stdClass();
$record->course = $course->id;
$record->files = file_get_unused_draft_itemid();
// Attach the main file. We put them in the draft area, create_module will move them.
$filerecord = array('contextid' => $usercontext->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $record->files, 'filepath' => '/');
// Attach 4 files.
for ($i = 1; $i <= 4; $i++) {
$filerecord['filename'] = 'myfile' . $i;
$fs->create_file_from_string($filerecord, 'Test folder file ' . $i);
}
// And a fifth in a sub-folder.
$filerecord['filename'] = 'myfile5';
$filerecord['filepath'] = '/subfolder/';
$fs->create_file_from_string($filerecord, 'Test folder file 5');
$this->getDataGenerator()->create_module('folder', $record);
// Returns the instance as long as the area is supported.
$searcharea = \core_search\manager::get_search_area($this->folderareaid);
$this->assertInstanceOf('\\mod_folder\\search\\activity', $searcharea);
$recordset = $searcharea->get_recordset_by_timestamp(0);
$nrecords = 0;
foreach ($recordset as $record) {
$doc = $searcharea->get_document($record);
$searcharea->attach_files($doc);
$files = $doc->get_files();
// Folder should return all files attached.
$this->assertCount(5, $files);
// We don't know the order, so get all the names, then sort, then check.
$filenames = array();
foreach ($files as $file) {
$filenames[] = $file->get_filename();
}
sort($filenames);
for ($i = 1; $i <= 5; $i++) {
$this->assertEquals('myfile' . $i, $filenames[$i - 1]);
}
$nrecords++;
}
// If there would be an error/failure in the foreach above the recordset would be closed on shutdown.
$recordset->close();
$this->assertEquals(1, $nrecords);
}
开发者ID:evltuma,项目名称:moodle,代码行数:54,代码来源:search_test.php
示例16: setUp
/**
* Setup all the various parts of an assignment activity including creating an onlinetext submission.
*/
protected function setUp()
{
$this->user = $this->getDataGenerator()->create_user();
$this->course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$params['course'] = $this->course->id;
$instance = $generator->create_instance($params);
$this->cm = get_coursemodule_from_instance('assign', $instance->id);
$this->context = context_module::instance($this->cm->id);
$this->assign = new testable_assign($this->context, $this->cm, $this->course);
$this->setUser($this->user->id);
$this->submission = $this->assign->get_user_submission($this->user->id, true);
$this->data = new stdClass();
$this->data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_PLAIN);
}
开发者ID:evltuma,项目名称:moodle,代码行数:18,代码来源:events_test.php
示例17: setUp
protected function setUp()
{
parent::setUp();
// Add additional default data (some real attempts and stuff).
$this->setUser($this->editingteachers[0]);
$this->create_instance();
$setask = $this->create_instance(array('duedate' => time(), 'attemptreopenmethod' => ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL, 'maxattempts' => 3, 'submissiondrafts' => 1, 'setasksubmission_onlinetext_enabled' => 1));
// Add a submission.
$this->setUser($this->students[0]);
$submission = $setask->get_user_submission($this->students[0]->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_HTML);
$plugin = $setask->get_submission_plugin_by_type('onlinetext');
$plugin->save($submission, $data);
// And now submit it for marking.
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$setask->testable_update_submission($submission, $this->students[0]->id, true, false);
// Mark the submission.
$this->setUser($this->teachers[0]);
$data = new stdClass();
$data->grade = '50.0';
$setask->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
// This is required so that the submissions timemodified > the grade timemodified.
sleep(2);
// Edit the submission again.
$this->setUser($this->students[0]);
$submission = $setask->get_user_submission($this->students[0]->id, true);
$setask->testable_update_submission($submission, $this->students[0]->id, true, false);
// This is required so that the submissions timemodified > the grade timemodified.
sleep(2);
// Allow the student another attempt.
$this->teachers[0]->ignoresesskey = true;
$this->setUser($this->teachers[0]);
$result = $setask->testable_process_add_attempt($this->students[0]->id);
// Add another submission.
$this->setUser($this->students[0]);
$submission = $setask->get_user_submission($this->students[0]->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text 2', 'format' => FORMAT_HTML);
$plugin = $setask->get_submission_plugin_by_type('onlinetext');
$plugin->save($submission, $data);
// And now submit it for marking (again).
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$setask->testable_update_submission($submission, $this->students[0]->id, true, false);
}
开发者ID:krzpassrl,项目名称:SRL_Moodle_db,代码行数:45,代码来源:lib_test.php
示例18: display_add_field
function display_add_field($recordid = 0)
{
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
$text = '';
$format = 0;
$str = '<div title="' . $this->field->description . '">';
editors_head_setup();
$options = $this->get_options();
$itemid = $this->field->id;
$field = 'field_' . $itemid;
if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
$format = $content->content1;
$text = clean_text($content->content, $format);
$text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text);
} else {
$draftitemid = file_get_unused_draft_itemid();
}
$updatecontrol = $field;
$idcontrol = $field . '_itemid';
$str .= '<input type="hidden" id="' . $updatecontrol . '" name="' . $updatecontrol . '" value="empty" />';
$str .= '<input type="hidden" name="' . $idcontrol . '" value="' . $draftitemid . '" />';
// $type = DBP_AUDIOMP3;
$usercontextid = context_user::instance($USER->id)->id;
switch ($this->field->param4) {
case DBP_AUDIO:
$str .= fetchAudioRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid);
break;
case DBP_VIDEO:
$str .= fetchVideoRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid);
break;
case DBP_AUDIOMP3:
$str .= fetchMP3RecorderForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid);
break;
case DBP_WHITEBOARDSIMPLE:
case DBP_WHITEBOARDFULL:
$str .= fetchWhiteboardForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid);
break;
case DBP_SNAPSHOT:
$str .= fetchSnapshotCameraForSubmission($updatecontrol, 'apic.jpg', 350, 400, $usercontextid, "user", "draft", $draftitemid);
break;
}
return $str;
}
|
请发表评论