当前位置: 首页>>代码示例>>PHP>>正文


PHP csv_import_reader::get_columns方法代码示例

本文整理汇总了PHP中csv_import_reader::get_columns方法的典型用法代码示例。如果您正苦于以下问题:PHP csv_import_reader::get_columns方法的具体用法?PHP csv_import_reader::get_columns怎么用?PHP csv_import_reader::get_columns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在csv_import_reader的用法示例。


在下文中一共展示了csv_import_reader::get_columns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 /**
  * Initialise the import reader and locate the column indexes.
  *
  * @return bool false is a failed import
  */
 public function init()
 {
     if ($this->csvreader == null) {
         $this->csvreader = new csv_import_reader($this->importid, 'assignfeedback_offline');
     }
     $this->csvreader->init();
     $columns = $this->csvreader->get_columns();
     $strgrade = get_string('grade');
     $strid = get_string('recordid', 'assign');
     $strmodified = get_string('lastmodifiedgrade', 'assign');
     foreach ($this->assignment->get_feedback_plugins() as $plugin) {
         if ($plugin->is_enabled() && $plugin->is_visible()) {
             foreach ($plugin->get_editor_fields() as $field => $description) {
                 $this->feedbackcolumnindexes[$description] = array('plugin' => $plugin, 'field' => $field, 'description' => $description);
             }
         }
     }
     if ($columns) {
         foreach ($columns as $index => $column) {
             if (isset($this->feedbackcolumnindexes[$column])) {
                 $this->feedbackcolumnindexes[$column]['index'] = $index;
             }
             if ($column == $strgrade) {
                 $this->gradeindex = $index;
             }
             if ($column == $strid) {
                 $this->idindex = $index;
             }
             if ($column == $strmodified) {
                 $this->modifiedindex = $index;
             }
         }
     }
     if ($this->idindex < 0 || $this->gradeindex < 0 || $this->modifiedindex < 0) {
         return false;
     }
     $groupmode = groups_get_activity_groupmode($this->assignment->get_course_module());
     // All users.
     $groupid = 0;
     $groupname = '';
     if ($groupmode) {
         $groupid = groups_get_activity_group($this->assignment->get_course_module(), true);
         $groupname = groups_get_group_name($groupid) . '-';
     }
     $this->validusers = $this->assignment->list_participants($groupid, false);
     return true;
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:52,代码来源:importgradeslib.php

示例2: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/csvlib.class.php';
     require_once $CFG->libdir . '/moodlelib.php';
     $csvfilepath = $this->arguments[0];
     if ($csvfilepath[0] != '/') {
         $csvfilepath = $this->cwd . DIRECTORY_SEPARATOR . $csvfilepath;
     }
     $iid = \csv_import_reader::get_new_iid('userprofile');
     $type = 'userprofile';
     $csvreader = new \csv_import_reader($iid, $type);
     if (false === ($csvfile = file_get_contents($csvfilepath))) {
         cli_error('Unable to load csv file. ' . error_get_last()['message']);
     }
     if (!$csvreader->load_csv_content($csvfile, 'utf-8', 'comma')) {
         cli_error('Unalbe to parse csv file. ' . $csvreader->get_error());
     }
     if (!$csvreader->init()) {
         cli_error('Unable to initialise csv reading');
     }
     $columns = $csvreader->get_columns();
     $columnsids = array_flip($columns);
     while (false !== ($row = $csvreader->next())) {
         $category = $this->get_or_create_category($row[$columnsids['categoryname']], $row[$columnsids['categorysortorder']]);
         $userfield = new \stdClass();
         $userfield->shortname = $row[$columnsids['shortname']];
         $userfield->name = $row[$columnsids['name']];
         $userfield->datatype = $row[$columnsids['datatype']];
         $userfield->description = $row[$columnsids['description']];
         $userfield->descriptionformat = $row[$columnsids['descriptionformat']];
         $userfield->categoryid = $category->id;
         $userfield->sortorder = $row[$columnsids['sortorder']];
         $userfield->required = $row[$columnsids['required']];
         $userfield->locked = $row[$columnsids['locked']];
         $userfield->visible = $row[$columnsids['visible']];
         $userfield->forceunique = $row[$columnsids['forceunique']];
         $userfield->signup = $row[$columnsids['signup']];
         $userfield->defaultdata = $row[$columnsids['defaultdata']];
         $userfield->defaultdataformat = $row[$columnsids['defaultdataformat']];
         $userfield->param1 = $row[$columnsids['param1']];
         $userfield->param2 = $row[$columnsids['param2']];
         $userfield->param3 = $row[$columnsids['param3']];
         $userfield->param4 = $row[$columnsids['param4']];
         $userfield->param5 = $row[$columnsids['param5']];
         $this->get_or_create_userfield($userfield);
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:48,代码来源:UserProfileFieldsImport.php

示例3: load_csv_content

 /**
  * Load CSV content for previewing.
  *
  * @param string $text The grade data being imported.
  * @param string $encoding The type of encoding the file uses.
  * @param string $separator The separator being used to define each field.
  * @param int $previewrows How many rows are being previewed.
  */
 public function load_csv_content($text, $encoding, $separator, $previewrows)
 {
     $this->raise_limits();
     $this->iid = csv_import_reader::get_new_iid('grade');
     $csvimport = new csv_import_reader($this->iid, 'grade');
     $csvimport->load_csv_content($text, $encoding, $separator);
     $this->error = $csvimport->get_error();
     // Get header (field names).
     $this->headers = $csvimport->get_columns();
     $this->trim_headers();
     $csvimport->init();
     $this->previewdata = array();
     for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
         $lines = $csvimport->next();
         if ($lines) {
             $this->previewdata[] = $lines;
         }
     }
 }
开发者ID:jtibbetts,项目名称:moodle,代码行数:27,代码来源:load_data.php

示例4: validation

 function validation($data, $files)
 {
     global $CFG;
     $errors = array();
     // Use csv importer from Moodle
     $iid = csv_import_reader::get_new_iid('emarking-predefined-comments');
     $reader = new csv_import_reader($iid, 'emarking-predefined-comments');
     $content = $data['comments'];
     $reader->load_csv_content($content, 'utf8', "tab");
     // Validate columns, minimum number and first two to be userid and attemptid
     if (count($reader->get_columns()) < 0) {
         $errors['comments'] = get_string('onecolumnrequired', 'mod_emarking');
     }
     $reader->init();
     $current = 0;
     while ($line = $reader->next()) {
         $current++;
     }
     if ($current < 1) {
         $errors['comments'] = get_string('twolinesrequired', 'mod_emarking');
     }
     return $errors;
 }
开发者ID:eduagdo,项目名称:emarking,代码行数:23,代码来源:predefined_comments_form.php

示例5: test_csv_functions

 public function test_csv_functions()
 {
     global $CFG;
     $csvexport = new csv_export_writer();
     $csvexport->set_filename('unittest');
     foreach ($this->testdata as $data) {
         $csvexport->add_data($data);
     }
     $csvoutput = $csvexport->print_csv_data(true);
     $this->assertEquals($csvoutput, $this->teststring);
     $test_data = csv_export_writer::print_array($this->testdata, 'comma', '"', true);
     $this->assertEquals($test_data, $this->teststring);
     // Testing that the content is imported correctly.
     $iid = csv_import_reader::get_new_iid('lib');
     $csvimport = new csv_import_reader($iid, 'lib');
     $contentcount = $csvimport->load_csv_content($this->teststring, 'utf-8', 'comma');
     $csvimport->init();
     $dataset = array();
     $dataset[] = $csvimport->get_columns();
     while ($record = $csvimport->next()) {
         $dataset[] = $record;
     }
     $csvimport->cleanup();
     $csvimport->close();
     $this->assertEquals($dataset, $this->testdata);
     // Testing for the wrong count of columns.
     $errortext = get_string('csvweirdcolumns', 'error');
     $iid = csv_import_reader::get_new_iid('lib');
     $csvimport = new csv_import_reader($iid, 'lib');
     $contentcount = $csvimport->load_csv_content($this->teststring2, 'utf-8', 'comma');
     $importerror = $csvimport->get_error();
     $csvimport->cleanup();
     $csvimport->close();
     $this->assertEquals($importerror, $errortext);
     // Testing for empty content
     $errortext = get_string('csvemptyfile', 'error');
     $iid = csv_import_reader::get_new_iid('lib');
     $csvimport = new csv_import_reader($iid, 'lib');
     $contentcount = $csvimport->load_csv_content($this->teststring3, 'utf-8', 'comma');
     $importerror = $csvimport->get_error();
     $csvimport->cleanup();
     $csvimport->close();
     $this->assertEquals($importerror, $errortext);
     // Testing for a tab separated file.
     // The tab separated file has a trailing tab and extra blank lines at the end of the file.
     $filename = $CFG->dirroot . '/lib/tests/fixtures/tabfile.csv';
     $fp = fopen($filename, 'r');
     $tabdata = fread($fp, filesize($filename));
     fclose($fp);
     $iid = csv_import_reader::get_new_iid('tab');
     $csvimport = new csv_import_reader($iid, 'tab');
     $contentcount = $csvimport->load_csv_content($tabdata, 'utf-8', 'tab');
     // This should import four rows including the headings.
     $this->assertEquals($contentcount, 4);
     // Testing for empty lines.
     $iid = csv_import_reader::get_new_iid('blanklines');
     $csvimport = new csv_import_reader($iid, 'blanklines');
     $contentcount = $csvimport->load_csv_content($this->teststring4, 'utf-8', 'comma');
     // Five lines including the headings should be imported.
     $this->assertEquals($contentcount, 5);
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:61,代码来源:csvclass_test.php

示例6: array

        echo $OUTPUT->footer();
        die;
    }
} else {
    $cir = new csv_import_reader($importid, 'uploadcourse');
}
// Data to set in the form.
$data = array('importid' => $importid, 'previewrows' => $previewrows);
if (!empty($form1data)) {
    // Get options from the first form to pass it onto the second.
    foreach ($form1data->options as $key => $value) {
        $data["options[{$key}]"] = $value;
    }
}
$context = context_system::instance();
$mform2 = new tool_uploadcourse_step2_form(null, array('contextid' => $context->id, 'columns' => $cir->get_columns(), 'data' => $data));
// If a file has been uploaded, then process it.
if ($form2data = $mform2->is_cancelled()) {
    $cir->cleanup(true);
    redirect($returnurl);
} else {
    if ($form2data = $mform2->get_data()) {
        $options = (array) $form2data->options;
        $defaults = (array) $form2data->defaults;
        // Restorefile deserves its own logic because formslib does not really appreciate
        // when the name of a filepicker is an array...
        $options['restorefile'] = '';
        if (!empty($form2data->restorefile)) {
            $options['restorefile'] = $mform2->save_temp_file('restorefile');
        }
        $processor = new tool_uploadcourse_processor($cir, $options, $defaults);
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:index.php

示例7: process_csv

 /**
  * @param array  $options associative delimiter,enclosure,encoding,updateexisting,settings
  */
 public function process_csv($data, $csvcontent, $options = null)
 {
     global $CFG, $DB;
     require_once "{$CFG->libdir}/csvlib.class.php";
     @set_time_limit(0);
     raise_memory_limit(MEMORY_EXTRA);
     $iid = \csv_import_reader::get_new_iid('moddataform');
     $cir = new \csv_import_reader($iid, 'moddataform');
     $delimiter = !empty($options['delimiter']) ? $options['delimiter'] : $this->_delimiter;
     $enclosure = !empty($options['enclosure']) ? $options['enclosure'] : $this->_enclosure;
     $encoding = !empty($options['encoding']) ? $options['encoding'] : $this->_encoding;
     $fieldsettings = !empty($options['settings']) ? $options['settings'] : array();
     $readcount = $cir->load_csv_content($csvcontent, $encoding, $delimiter);
     if (empty($readcount)) {
         $data->errors[] = $cir->get_error();
         return $data;
     }
     // Csv column headers.
     if (!($fieldnames = $cir->get_columns())) {
         $data->errors[] = $cir->get_error();
         return $data;
     }
     // Are we updating existing entries?
     $existingkeys = array();
     $keyname = null;
     if ($updateexisting = !empty($options['updateexisting'])) {
         if (isset($fieldnames['entryid'])) {
             $keyname = 'entryid';
         } else {
             $keyname = reset($fieldnames);
             if ($field = $this->df->field_manager->get_field_by_name($keyname)) {
                 $params = array('fieldid' => $field->id);
                 $existingkeys = $DB->get_records_menu('dataform_contents', $params, '', 'entryid,content');
             }
         }
     }
     // Are we adding the imported entries to every participant?
     $addperparticipant = (!empty($options['addperparticipant']) and $users = $this->df->grade_manager->get_gradebook_users());
     $i = 0;
     $cir->init();
     while ($csvrecord = $cir->next()) {
         $csvrecord = array_combine($fieldnames, $csvrecord);
         // Add the entry for every participant.
         if ($addperparticipant) {
             foreach ($users as $userid => $unused) {
                 // Set the entry id.
                 $i++;
                 $entryid = -$i;
                 $data->eids[$entryid] = $entryid;
                 $data->{"entry_{$entryid}_userid"} = $userid;
                 // Iterate the fields and collate their entry content.
                 foreach ($fieldsettings as $fieldid => $importsettings) {
                     $field = $this->df->field_manager->get_field_by_id($fieldid);
                     $data = $field->prepare_import_content($data, $importsettings, $csvrecord, $entryid);
                 }
             }
             continue;
         }
         // Get the entry id.
         $entryid = 0;
         if ($updateexisting and $keyname) {
             if ($keyname == 'entryid') {
                 if (!empty($csvrecord['entryid'])) {
                     $entryid = $csvrecord['entryid'];
                 }
             } else {
                 if ($existingkeys and !empty($csvrecord[$keyname])) {
                     $entryid = array_search($csvrecord[$keyname], $existingkeys);
                 }
             }
         }
         if (!$entryid) {
             $i++;
             $entryid = -$i;
         }
         $data->eids[$entryid] = $entryid;
         // Iterate the fields and collate their entry content.
         foreach ($fieldsettings as $fieldid => $importsettings) {
             $field = $this->df->field_manager->get_field_by_id($fieldid);
             $data = $field->prepare_import_content($data, $importsettings, $csvrecord, $entryid);
         }
     }
     $cir->cleanup(true);
     $cir->close();
     return $data;
 }
开发者ID:vaenda,项目名称:moodle-mod_dataform,代码行数:89,代码来源:csv.php

示例8: cc_validate_coursecategory_upload_columns

/**
 * Validation callback function - verified the column line of csv file.
 * Converts standard column names to lowercase.
 * @param csv_import_reader $cir
 * @param array $stdfields standard coursecategory fields
 * @param moodle_url $returnurl return url in case of any error
 * @return array list of fields
 */
function cc_validate_coursecategory_upload_columns(csv_import_reader $cir, $stdfields, moodle_url $returnurl)
{
    $columns = $cir->get_columns();
    if (empty($columns)) {
        $cir->close();
        $cir->cleanup();
        print_error('cannotreadtmpfile', 'error', $returnurl);
    }
    if (count($columns) < 2) {
        $cir->close();
        $cir->cleanup();
        print_error('csvfewcolumns', 'error', $returnurl);
    }
    // test columns
    $processed = array();
    foreach ($columns as $key => $unused) {
        $field = $columns[$key];
        $lcfield = core_text::strtolower($field);
        if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) {
            // standard fields are only lowercase
            $newfield = $lcfield;
        } else {
            $cir->close();
            $cir->cleanup();
            print_error('invalidfieldname', 'error', $returnurl, $field);
        }
        if (in_array($newfield, $processed)) {
            $cir->close();
            $cir->cleanup();
            print_error('duplicatefieldname', 'error', $returnurl, $newfield);
        }
        $processed[$key] = $newfield;
    }
    return $processed;
}
开发者ID:alexandru-elisei,项目名称:moodle-tool_uploadcoursecategory,代码行数:43,代码来源:locallib.php

示例9: uu_validate_user_upload_columns

/**
 * Validation callback function - verified the column line of csv file.
 * Converts standard column names to lowercase.
 * @param csv_import_reader $cir
 * @param array $stdfields standard user fields
 * @param array $profilefields custom profile fields
 * @param moodle_url $returnurl return url in case of any error
 * @return array list of fields
 */
function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $profilefields, moodle_url $returnurl)
{
    $columns = $cir->get_columns();
    if (empty($columns)) {
        $cir->close();
        $cir->cleanup();
        print_error('cannotreadtmpfile', 'error', $returnurl);
    }
    if (count($columns) < 2) {
        $cir->close();
        $cir->cleanup();
        print_error('csvfewcolumns', 'error', $returnurl);
    }
    // test columns
    $processed = array();
    foreach ($columns as $key => $unused) {
        $field = $columns[$key];
        $lcfield = textlib::strtolower($field);
        if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) {
            // standard fields are only lowercase
            $newfield = $lcfield;
        } else {
            if (in_array($field, $profilefields)) {
                // exact profile field name match - these are case sensitive
                $newfield = $field;
            } else {
                if (in_array($lcfield, $profilefields)) {
                    // hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field
                    $newfield = $lcfield;
                } else {
                    if (preg_match('/^(cohort|course|group|type|role|enrolperiod)\\d+$/', $lcfield)) {
                        // special fields for enrolments
                        $newfield = $lcfield;
                    } else {
                        $cir->close();
                        $cir->cleanup();
                        print_error('invalidfieldname', 'error', $returnurl, $field);
                    }
                }
            }
        }
        if (in_array($newfield, $processed)) {
            $cir->close();
            $cir->cleanup();
            print_error('duplicatefieldname', 'error', $returnurl, $newfield);
        }
        $processed[$key] = $newfield;
    }
    return $processed;
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:59,代码来源:locallib.php

示例10: process_uploaded_groups

 /**
  * enrol and add user to groups in course
  * @param object $course
  * @param csv_import_reader $reader
  * @param int $roleid
  */
 public function process_uploaded_groups($course, $reader, $roleid)
 {
     global $DB, $PAGE;
     $usercol = null;
     // Index of username column.
     $groupcol = null;
     // Index of group column.
     // Find the index of the needed columns.
     $i = 0;
     foreach ($reader->get_columns() as $col) {
         $col = strtoupper(trim($col));
         switch ($col) {
             case 'USERNAME':
                 $usercol = $i;
                 break;
             case 'GROUP':
                 $groupcol = $i;
                 break;
         }
         $i++;
     }
     // Get the manual enrolment plugin.
     $enrolinstances = enrol_get_instances($course->id, true);
     $manualinstance = null;
     foreach ($enrolinstances as $instance) {
         if ($instance->enrol == 'manual') {
             $manualinstance = $instance;
             break;
         }
     }
     $manualenroler = enrol_get_plugin('manual');
     // Get the list of enrolled users for the course.
     $manager = new course_enrolment_manager($PAGE, $course);
     $totalusers = $manager->get_total_users();
     /*
      * Since the number of fields being retrieved are limited (email, id, lastaccess, and lastseen),
      * I feel comfortable retrieving the entire enrolled userbase for this course.
      */
     $users = $manager->get_users('firstname', 'ASC', 0, $totalusers);
     $groups = $manager->get_all_groups();
     $groupids = array();
     foreach ($groups as $group) {
         $groupids[$group->name] = $group->id;
     }
     // Prep the returned array.
     $output = array('group_created' => array(), 'user_enrolled' => array(), 'member_added' => array(), 'error' => array('user_not_found' => array(), 'group_failed' => array(), 'enrol_failed' => array(), 'member_failed' => array(), 'user_not_added' => array()));
     // Loop through the records.
     $reader->init();
     while ($line = $reader->next()) {
         $username = trim($line[$usercol]);
         $groupname = trim($line[$groupcol]);
         // Check if the user exists.
         $user = $DB->get_record('user', array('username' => $username));
         if ($user === false) {
             $output['error']['user_not_found'][] = $username;
             continue;
         }
         // Enroll the user as needed.
         if (!isset($users[$user->id])) {
             try {
                 $manualenroler->enrol_user($manualinstance, $user->id, $roleid);
                 $output['user_enrolled'][] = $username;
             } catch (Exception $e) {
                 $output['error']['enroll_failed'][] = $username;
             }
         }
         // Create the group as needed.
         if (!isset($groupids[$groupname])) {
             if ($groupname != '') {
                 $data = new stdClass();
                 $data->courseid = $course->id;
                 $data->name = $groupname;
                 $newgroupid = groups_create_group($data);
             } else {
                 $newgroupid = false;
             }
             if ($newgroupid === false) {
                 if ($groupname != '') {
                     $output['error']['group_failed'][] = $groupname;
                 }
             } else {
                 $groupids[$groupname] = $newgroupid;
                 $output['group_created'][] = $groupname;
             }
         }
         // Add the user to the group.
         if ($groupname != '') {
             if (groups_add_member($groupids[$groupname], $user->id)) {
                 if (!isset($output['member_added'][$groupname])) {
                     $output['member_added'][$groupname] = array();
                 }
                 $output['member_added'][$groupname][] = $username;
             } else {
                 if (!isset($output['error']['member_failed'][$groupname])) {
//.........这里部分代码省略.........
开发者ID:at-tools,项目名称:moodle-block_uploadgroups,代码行数:101,代码来源:lib.php

示例11: array

 /**
  * Validation callback function - verified the column line of csv file.
  * Converts standard column names to lowercase.
  * @param csv_import_reader $cir
  * @param array $fields standard user fields
  * @param moodle_url $returnurl return url in case of any error
  * @return array list of fields
  */
 static function validate_columns(csv_import_reader $cir, $fields, moodle_url $returnurl)
 {
     $columns = $cir->get_columns();
     $ignoredfields = $fields['ignored'];
     $stdfields = array_merge($fields['required'], $fields['optional']);
     if (empty($columns)) {
         $cir->close();
         $cir->cleanup();
         print_error('cannotreadtmpfile', 'error', $returnurl);
     }
     if (count($columns) < 2) {
         $cir->close();
         $cir->cleanup();
         print_error('csvfewcolumns', 'error', $returnurl);
     }
     // test columns
     $processed = array();
     foreach ($columns as $key => $unused) {
         $field = $columns[$key];
         $lcfield = core_text::strtolower($field);
         if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) {
             // standard fields are only lowercase
             $newfield = $lcfield;
         } else {
             if (in_array($field, $ignoredfields) or in_array($lcfield, $ignoredfields)) {
                 continue;
             } else {
                 $cir->close();
                 $cir->cleanup();
                 print_error('invalidfieldname', 'error', $returnurl, $field);
             }
         }
         if (in_array($newfield, $processed)) {
             $cir->close();
             $cir->cleanup();
         }
         $processed[$key] = $newfield;
     }
     foreach ($fields['required'] as $field) {
         $lcfield = core_text::strtolower($field);
         if (!in_array($lcfield, $processed)) {
             $cir->close();
             $cir->cleanup(true);
             print_error('fieldrequired', 'error', $returnurl, $lcfield);
         }
     }
     return $processed;
 }
开发者ID:kevin-bruton,项目名称:marsupial,代码行数:56,代码来源:locallib.php

示例12: array

    echo $OUTPUT->box_end();
    echo $OUTPUT->footer();
    die;
} else {
    // Large files are likely to take their time and memory. Let PHP know
    // that we'll take longer, and that the process should be recycled soon
    // to free up memory.
    @set_time_limit(0);
    raise_memory_limit(MEMORY_EXTRA);
    $iid = csv_import_reader::get_new_iid('moddata');
    $cir = new csv_import_reader($iid, 'moddata');
    $readcount = $cir->load_csv_content($form->get_file_content('recordsfile'), $formdata->encoding, $formdata->fielddelimiter);
    if (empty($readcount)) {
        print_error('csvfailed', 'data', "{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}");
    } else {
        if (!($fieldnames = $cir->get_columns())) {
            print_error('cannotreadtmpfile', 'error');
        }
        // check the fieldnames are valid
        $fields = $DB->get_records('data_fields', array('dataid' => $data->id), '', 'name, id, type');
        $errorfield = '';
        foreach ($fieldnames as $name) {
            if (!isset($fields[$name])) {
                $errorfield .= "'{$name}' ";
            }
        }
        if (!empty($errorfield)) {
            print_error('fieldnotmatched', 'data', "{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}", $errorfield);
        }
        $cir->init();
        $recordsadded = 0;
开发者ID:vuchannguyen,项目名称:web,代码行数:31,代码来源:import.php

示例13: array

echo $OUTPUT->tabtree(emarking_tabs($context, $cm, $emarking), 'importrubric');
list($gradingmanager, $gradingmethod, $definition, $rubriccontroller) = emarking_validate_rubric($context, false, false);
// Form Display.
$predefinedform = new emarking_import_excel_form(null, array('cmid' => $cm->id));
if ($predefinedform->get_data()) {
    // Use csv importer from Moodle.
    $iid = csv_import_reader::get_new_iid('emarking-predefined-comments');
    $reader = new csv_import_reader($iid, 'emarking-predefined-comments');
    $content = $predefinedform->get_data()->comments;
    $reader->load_csv_content($content, 'utf8', 'tab');
    $columns = array();
    $columns[] = html_writer::div(get_string('criterion', 'mod_emarking'));
    $columns[] = html_writer::div(get_string('rubriclevel', 'mod_emarking'));
    $data = array();
    $definitiondata = array();
    $ignoredcolumns = $reader->get_columns();
    if (!isset($predefinedform->get_data()->headers)) {
        $data[] = emarking_table_from_line($ignoredcolumns);
        $definitiondata[] = $ignoredcolumns;
    }
    $reader->init();
    $current = 1;
    while ($line = $reader->next()) {
        $definitiondata[] = $line;
        if (count($line) > 0 && $current % 2 == 0) {
            $data[] = emarking_table_from_line($line);
        } else {
            for ($i = 1; $i < count($line); $i++) {
                $points = floatval(emarking_extract_rubric_points($line[$i]));
                if ($points >= 0) {
                    $data[count($data) - 1][1]->data[0][$i - 1] .= html_writer::div($points . ' ' . get_string('points', 'grades'), 'score');
开发者ID:hansnok,项目名称:emarking,代码行数:31,代码来源:importrubric.php

示例14: import_logs

 /**
  * Imports the log views defined in the csv file, iterating each row. This is made under the transaction initiated in
  * import_data function.
  *
  * @param object $logsfile Course csv file.
  * @param object $formdata Submitted form data, needed to load the csv.
  * @param int $courseid Generated course id in this transaction.
  * @param \block_mycourse_recommendations\database_helper $db Database handler object, passed as argument to instance it
  * again.
  */
 public static function import_logs($logsfile, $formdata, $courseid, $db)
 {
     $iid = \csv_import_reader::get_new_iid('logsfile');
     $csvreader = new \csv_import_reader($iid, 'logsfile');
     $csvreader->load_csv_content($logsfile, $formdata->encoding, $formdata->delimiter_name);
     $csvreader->init();
     $fields = $csvreader->get_columns();
     while ($fields) {
         $userid = $fields[0];
         $resourcename = $fields[1];
         $resourcetype = $fields[2];
         $resourceid = $fields[3];
         $views = $fields[4];
         $timecreated = $fields[5];
         $db->insert_historic_logs($userid, $courseid, $resourcename, $resourcetype, $resourceid, $views, $timecreated);
         self::$lastinsertedlogs++;
         $fields = $csvreader->next();
     }
     $csvreader->close();
 }
开发者ID:julenpardo,项目名称:moodle-block_mycourse_recommendations,代码行数:30,代码来源:csv_importer.php

示例15: uu_validate_user_upload_columns

/**
 * Validation callback function - verified the column line of csv file.
 * Converts column names to lowercase too.
 * @param csv_import_reader $cir
 * @param array standard user fields
 * @param array custom profile fields
 * @param moodle_url $returnurl return url in case of any error
 * @return array list of fields
 */
function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $frofilefields, moodle_url $returnurl)
{
    $columns = $cir->get_columns();
    if (empty($columns)) {
        $cir->close();
        $cir->cleanup();
        print_error('cannotreadtmpfile', 'error', $returnurl);
    }
    if (count($columns) < 2) {
        $cir->close();
        $cir->cleanup();
        print_error('csvfewcolumns', 'error', $returnurl);
    }
    // test columns
    $processed = array();
    foreach ($columns as $key => $unused) {
        $field = strtolower($columns[$key]);
        // no unicode expected here, ignore case
        if (!in_array($field, $stdfields) && !in_array($field, $frofilefields) && !preg_match('/^course\\d+$/', $field) && !preg_match('/^group\\d+$/', $field) && !preg_match('/^type\\d+$/', $field) && !preg_match('/^role\\d+$/', $field) && !preg_match('/^enrolperiod\\d+$/', $field)) {
            print_error('invalidfieldname', 'error', $returnurl, $field);
        }
        if (in_array($field, $processed)) {
            $cir->close();
            $cir->cleanup();
            print_error('duplicatefieldname', 'error', $returnurl, $field);
        }
        $processed[$key] = $field;
    }
    return $processed;
}
开发者ID:hitphp,项目名称:moodle,代码行数:39,代码来源:uploaduserlib.php


注:本文中的csv_import_reader::get_columns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。