示例#1
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data'));
     $choices = csv_import_reader::get_delimiter_list();
     $key = array_search(';', $choices);
     if (!$key === FALSE) {
         // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon):
         unset($choices[$key]);
     }
     $typesarray = array();
     $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . ' ', 'csv');
     $typesarray[] =& MoodleQuickForm::createElement('select', 'delimiter_name', null, $choices);
     $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls');
     $typesarray[] =& MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods');
     $mform->addGroup($typesarray, 'exportar', '', array(''), false);
     $mform->addRule('exportar', null, 'required');
     $mform->setDefault('exporttype', 'csv');
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data'));
     foreach ($this->_datafields as $field) {
         if ($field->text_export_supported()) {
             $mform->addElement('advcheckbox', 'field_' . $field->field->id, '<div title="' . s($field->field->description) . '">' . $field->field->name . '</div>', ' (' . $field->name() . ')', array('group' => 1));
             $mform->setDefault('field_' . $field->field->id, 1);
         } else {
             $a = new object();
             $a->fieldtype = $field->name();
             $mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, get_string('unsupportedexport', 'data', $a));
         }
     }
     $this->add_checkbox_controller(1, null, null, 1);
     require_once $CFG->libdir . '/portfoliolib.php';
     if (has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->_cm->id))) {
         if ($portfoliooptions = portfolio_instance_select(portfolio_instances(), call_user_func(array('data_portfolio_caller', 'supported_formats')), 'data_portfolio_caller', '', true, true)) {
             $mform->addElement('header', 'notice', get_string('portfolionotfile', 'data') . ':');
             $portfoliooptions[0] = get_string('none');
             ksort($portfoliooptions);
             $mform->addElement('select', 'portfolio', get_string('portfolio', 'portfolio'), $portfoliooptions);
         }
     }
     $this->add_action_buttons(true, get_string('exportdatabaserecords', 'data'));
 }
 public function to_html($format = null, $addstr = null)
 {
     global $CFG, $COURSE, $OUTPUT, $USER;
     if (!$this->is_renderable()) {
         return;
     }
     if (empty($this->callbackclass) || empty($this->callbackfile)) {
         throw new portfolio_button_exception('mustsetcallbackoptions', 'portfolio');
     }
     if (empty($this->formats)) {
         // use the caller defaults
         $this->set_formats();
     }
     $url = new moodle_url('/portfolio/add.php');
     foreach ($this->callbackargs as $key => $value) {
         if (!empty($value) && !is_string($value) && !is_numeric($value)) {
             $a = new stdClass();
             $a->key = $key;
             $a->value = print_r($value, true);
             debugging(get_string('nonprimative', 'portfolio', $a));
             return;
         }
         $url->param('ca_' . $key, $value);
     }
     $url->param('sesskey', sesskey());
     $url->param('callbackfile', $this->callbackfile);
     $url->param('callbackclass', $this->callbackclass);
     $url->param('course', !empty($COURSE) ? $COURSE->id : 0);
     $url->param('callerformats', implode(',', $this->formats));
     $mimetype = null;
     if ($this->file instanceof stored_file) {
         $mimetype = $this->file->get_mimetype();
     } else {
         if ($this->intendedmimetype) {
             $mimetype = $this->intendedmimetype;
         }
     }
     $selectoutput = '';
     if (count($this->instances) == 1) {
         $tmp = array_values($this->instances);
         $instance = $tmp[0];
         $formats = portfolio_supported_formats_intersect($this->formats, $instance->supported_formats());
         if (count($formats) == 0) {
             // bail. no common formats.
             //debugging(get_string('nocommonformats', 'portfolio', (object)array('location' => $this->callbackclass, 'formats' => implode(',', $this->formats))));
             return;
         }
         if ($error = portfolio_instance_sanity_check($instance)) {
             // bail, plugin is misconfigured
             //debugging(get_string('instancemisconfigured', 'portfolio', get_string($error[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
             return;
         }
         if (!$instance->allows_multiple_exports() && ($already = portfolio_existing_exports($USER->id, $instance->get('plugin')))) {
             //debugging(get_string('singleinstancenomultiallowed', 'portfolio'));
             return;
         }
         if ($mimetype && !$instance->file_mime_check($mimetype)) {
             // bail, we have a specific file or mimetype and this plugin doesn't support it
             //debugging(get_string('mimecheckfail', 'portfolio', (object)array('plugin' => $instance->get('plugin'), 'mimetype' => $mimetype)));
             return;
         }
         $url->param('instance', $instance->get('id'));
     } else {
         if (!($selectoutput = portfolio_instance_select($this->instances, $this->formats, $this->callbackclass, $mimetype, 'instance', true))) {
             return;
         }
     }
     // if we just want a url to redirect to, do it now
     if ($format == PORTFOLIO_ADD_FAKE_URL) {
         return $url->out(false);
     }
     if (empty($addstr)) {
         $addstr = get_string('addtoportfolio', 'portfolio');
     }
     if (empty($format)) {
         $format = PORTFOLIO_ADD_FULL_FORM;
     }
     $formoutput = '<form method="post" action="' . $CFG->wwwroot . '/portfolio/add.php" id="portfolio-add-button">' . "\n";
     $formoutput .= html_writer::input_hidden_params($url);
     $linkoutput = '<a class="portfolio-add-link" title="' . $addstr . '" href="' . $url->out();
     switch ($format) {
         case PORTFOLIO_ADD_FULL_FORM:
             $formoutput .= $selectoutput;
             $formoutput .= "\n" . '<input type="submit" value="' . $addstr . '" />';
             $formoutput .= "\n" . '</form>';
             break;
         case PORTFOLIO_ADD_ICON_FORM:
             $formoutput .= $selectoutput;
             $formoutput .= "\n" . '<input class="portfolio-add-icon" type="image" src="' . $OUTPUT->pix_url('t/portfolioadd') . '" alt=' . $addstr . '" />';
             $formoutput .= "\n" . '</form>';
             break;
         case PORTFOLIO_ADD_ICON_LINK:
             $linkoutput .= '"><img class="portfolio-add-icon" src="' . $OUTPUT->pix_url('t/portfolioadd') . '" alt="' . $addstr . '" /></a>';
             break;
         case PORTFOLIO_ADD_TEXT_LINK:
             $linkoutput .= '">' . $addstr . '</a>';
             break;
         default:
             debugging(get_string('invalidaddformat', 'portfolio', $format));
     }
     $output = in_array($format, array(PORTFOLIO_ADD_FULL_FORM, PORTFOLIO_ADD_ICON_FORM)) ? $formoutput : $linkoutput;
     return $output;
 }
示例#3
0
 public function to_html($format = null, $addstr = null)
 {
     if ($this->alreadyexporting) {
         return $this->already_exporting($format, $addstr);
     }
     global $CFG, $COURSE, $OUTPUT;
     if (!$this->is_renderable()) {
         return;
     }
     if (empty($this->callbackclass) || empty($this->callbackfile)) {
         throw new portfolio_button_exception('mustsetcallbackoptions', 'portfolio');
     }
     if (empty($this->formats)) {
         // use the caller defaults
         $this->set_formats();
     }
     $formoutput = '<form method="post" action="' . $CFG->wwwroot . '/portfolio/add.php" id="portfolio-add-button">' . "\n";
     $linkoutput = '<a href="' . $CFG->wwwroot . '/portfolio/add.php?';
     foreach ($this->callbackargs as $key => $value) {
         if (!empty($value) && !is_string($value) && !is_numeric($value)) {
             $a->key = $key;
             $a->value = print_r($value, true);
             debugging(get_string('nonprimative', 'portfolio', $a));
             return;
         }
         $linkoutput .= 'ca_' . $key . '=' . $value . '&amp;';
         $formoutput .= "\n" . '<input type="hidden" name="ca_' . $key . '" value="' . $value . '" />';
     }
     $formoutput .= "\n" . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
     $linkoutput .= 'sesskey=' . sesskey() . '&amp;';
     $formoutput .= "\n" . '<input type="hidden" name="callbackfile" value="' . $this->callbackfile . '" />';
     $formoutput .= "\n" . '<input type="hidden" name="callbackclass" value="' . $this->callbackclass . '" />';
     $formoutput .= "\n" . '<input type="hidden" name="course" value="' . (!empty($COURSE) ? $COURSE->id : 0) . '" />';
     $linkoutput .= 'callbackfile=' . $this->callbackfile . '&amp;callbackclass=' . $this->callbackclass . '&amp;course=' . (!empty($COURSE) ? $COURSE->id : 0);
     $selectoutput = '';
     if (count($this->instances) == 1) {
         $tmp = array_values($this->instances);
         $instance = $tmp[0];
         //$instance = array_shift($this->instances);
         $formats = portfolio_supported_formats_intersect($this->formats, $instance->supported_formats());
         if (count($formats) == 0) {
             // bail. no common formats.
             debugging(get_string('nocommonformats', 'portfolio', $this->callbackclass));
             return;
         }
         if ($error = portfolio_instance_sanity_check($instance)) {
             // bail, plugin is misconfigured
             debugging(get_string('instancemisconfigured', 'portfolio', get_string($error[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
             return;
         }
         $formoutput .= "\n" . '<input type="hidden" name="instance" value="' . $instance->get('id') . '" />';
         $linkoutput .= '&amp;instance=' . $instance->get('id');
     } else {
         $selectoutput = portfolio_instance_select($this->instances, $this->formats, $this->callbackclass, 'instance', true);
     }
     if (empty($addstr)) {
         $addstr = get_string('addtoportfolio', 'portfolio');
     }
     if (empty($format)) {
         $format = PORTFOLIO_ADD_FULL_FORM;
     }
     switch ($format) {
         case PORTFOLIO_ADD_FULL_FORM:
             $formoutput .= $selectoutput;
             $formoutput .= "\n" . '<input type="submit" value="' . $addstr . '" />';
             $formoutput .= "\n" . '</form>';
             break;
         case PORTFOLIO_ADD_ICON_FORM:
             $formoutput .= $selectoutput;
             $formoutput .= "\n" . '<input type="image" src="' . $OUTPUT->old_icon_url('t/portfolio') . '" alt=' . $addstr . '" />';
             $formoutput .= "\n" . '</form>';
             break;
         case PORTFOLIO_ADD_ICON_LINK:
             $linkoutput .= '"><img src="' . $OUTPUT->old_icon_url('t/portfolio') . '" alt=' . $addstr . '" /></a>';
             break;
         case PORTFOLIO_ADD_TEXT_LINK:
             $linkoutput .= '">' . $addstr . '</a>';
             break;
         default:
             debugging(get_string('invalidaddformat', 'portfolio', $format));
     }
     $output = in_array($format, array(PORTFOLIO_ADD_FULL_FORM, PORTFOLIO_ADD_ICON_FORM)) ? $formoutput : $linkoutput;
     return $output;
 }
示例#4
0
文件: add.php 项目: evltuma/moodle
    portfolio_export_pagesetup($PAGE, $caller);
    // this calls require_login($course) if it can..
    // finally! set up the exporter object with the portfolio instance, and caller information elements
    $exporter = new portfolio_exporter($instance, $caller, $callbackcomponent);
    // set the export-specific variables, and save.
    $exporter->set('user', $USER);
    $exporter->save();
}
if (!$exporter->get('instance')) {
    // we've just arrived but have no instance
    // in this case the exporter object and the caller object have been set up above
    // so just make a little form to select the portfolio plugin instance,
    // which is the last thing to do before starting the export.
    //
    // first check to make sure there is actually a point
    $options = portfolio_instance_select(portfolio_instances(), $exporter->get('caller')->supported_formats(), get_class($exporter->get('caller')), $exporter->get('caller')->get_mimetype(), 'instance', true, true);
    if (empty($options)) {
        throw new portfolio_export_exception($exporter, 'noavailableplugins', 'portfolio');
    } else {
        if (count($options) == 1) {
            // no point displaying a form, just redirect.
            $optionskeys = array_keys($options);
            $instance = array_shift($optionskeys);
            redirect($CFG->wwwroot . '/portfolio/add.php?id= ' . $exporter->get('id') . '&instance=' . $instance . '&sesskey=' . sesskey());
        }
    }
    // be very selective about not including this unless we really need to
    require_once $CFG->libdir . '/portfolio/forms.php';
    $mform = new portfolio_instance_select('', array('id' => $exporter->get('id'), 'caller' => $exporter->get('caller'), 'options' => $options));
    if ($mform->is_cancelled()) {
        $exporter->cancel_request();
示例#5
0
 function definition()
 {
     $this->caller = $this->_customdata['caller'];
     $options = portfolio_instance_select(portfolio_instances(), $this->caller->supported_formats($this->caller), get_class($this->caller), 'instance', true, true);
     if (empty($options)) {
         debugging('noavailableplugins', 'portfolio');
         return false;
     }
     $mform =& $this->_form;
     $mform->addElement('select', 'instance', get_string('selectplugin', 'portfolio'), $options);
     $this->add_action_buttons(true, get_string('next'));
 }