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


PHP Import::csv_to_array方法代码示例

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


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

示例1: parse_csv_data

/**
 * Read the CSV-file
 * @param string $file Path to the CSV-file
 * @return array All userinformation read from the file
 */
function parse_csv_data($file)
{
    $skills = Import::csv_to_array($file);
    foreach ($skills as $index => $skill) {
        $skills[$index] = $skill;
    }
    return $skills;
}
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:13,代码来源:skills_import.php

示例2: get_lang

$form->addElement('header', $tool_name);
$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
$form->addElement('checkbox', 'unsubscribe_users', null, get_lang('UnsubscribeUsersAlreadyAddedInCourse'));
$form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"');
$course_code = api_get_course_id();
if (empty($course_code)) {
    api_not_allowed(true);
}
$session_id = api_get_session_id();
$message = '';
$user_to_show = array();
$type = '';
if ($form->validate()) {
    if (isset($_FILES['import_file']['size']) && $_FILES['import_file']['size'] !== 0) {
        $unsubscribe_users = isset($_POST['unsubscribe_users']) ? true : false;
        $users = Import::csv_to_array($_FILES['import_file']['tmp_name']);
        $invalid_users = array();
        $clean_users = array();
        if (!empty($users)) {
            $empty_line = 0;
            foreach ($users as $user_data) {
                $user_id = null;
                $user_data = array_change_key_case($user_data, CASE_LOWER);
                // Checking "username" field
                if (isset($user_data['username']) && !empty($user_data['username'])) {
                    $user_id = UserManager::get_user_id_from_username($user_data['username']);
                }
                // Checking "id" field
                if (isset($user_data['id']) && !empty($user_data['id'])) {
                    $user_id = $user_data['id'];
                }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:31,代码来源:user_import.php

示例3: importCourses

 /**
  * @param string $file
  * @param bool $moveFile
  * @param array $teacherBackup
  * @param array $groupBackup
  */
 private function importCourses($file, $moveFile = true, &$teacherBackup = array(), &$groupBackup = array())
 {
     $data = Import::csv_to_array($file);
     if (!empty($data)) {
         $this->logger->addInfo(count($data) . " records found.");
         foreach ($data as $row) {
             $row = $this->cleanCourseRow($row);
             $courseCode = CourseManager::get_course_id_from_original_id($row['extra_' . $this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
             $courseInfo = api_get_course_info($courseCode);
             if (empty($courseInfo)) {
                 // Create
                 $params = array();
                 $params['title'] = $row['title'];
                 $params['exemplary_content'] = false;
                 $params['wanted_code'] = $row['course_code'];
                 $params['course_category'] = $row['course_category'];
                 $params['course_language'] = $row['language'];
                 $params['teachers'] = $row['teachers'];
                 $courseInfo = CourseManager::create_course($params);
                 if (!empty($courseInfo)) {
                     CourseManager::update_course_extra_field_value($courseInfo['code'], 'external_course_id', $row['extra_' . $this->extraFieldIdNameList['course']]);
                     $this->logger->addInfo("Courses - Course created " . $courseInfo['code']);
                 } else {
                     $this->logger->addError("Courses - Can't create course:" . $row['title']);
                 }
             } else {
                 // Update
                 $params = array('title' => $row['title'], 'category_code' => $row['course_category']);
                 $result = CourseManager::update_attributes($courseInfo['real_id'], $params);
                 $addTeacherToSession = isset($courseInfo['add_teachers_to_sessions_courses']) && !empty($courseInfo['add_teachers_to_sessions_courses']) ? true : false;
                 $teachers = $row['teachers'];
                 if (!is_array($teachers)) {
                     $teachers = array($teachers);
                 }
                 if ($addTeacherToSession) {
                     CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, true, false, $teacherBackup);
                 } else {
                     CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, false, false, $teacherBackup);
                 }
                 foreach ($teachers as $teacherId) {
                     if (isset($groupBackup['tutor'][$teacherId]) && isset($groupBackup['tutor'][$teacherId][$courseInfo['code']])) {
                         foreach ($groupBackup['tutor'][$teacherId][$courseInfo['code']] as $data) {
                             GroupManager::subscribe_tutors(array($teacherId), $data['group_id'], $data['c_id']);
                         }
                     }
                     if (isset($groupBackup['user'][$teacherId]) && isset($groupBackup['user'][$teacherId][$courseInfo['code']]) && !empty($groupBackup['user'][$teacherId][$courseInfo['code']])) {
                         foreach ($groupBackup['user'][$teacherId][$courseInfo['code']] as $data) {
                             GroupManager::subscribe_users(array($teacherId), $data['group_id'], $data['c_id']);
                         }
                     }
                 }
                 if ($result) {
                     $this->logger->addInfo("Courses - Course updated " . $courseInfo['code']);
                 } else {
                     $this->logger->addError("Courses - Course NOT updated " . $courseInfo['code']);
                 }
             }
         }
     }
     if ($moveFile) {
         $this->moveFile($file);
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:69,代码来源:import_csv.php

示例4: parse_csv_data

/**
 * Reads a CSV-file.
 * @param string $file Path to the CSV-file
 * @return array All course-information read from the file
 */
function parse_csv_data($file)
{
    $courses = Import::csv_to_array($file);
    return $courses;
}
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:10,代码来源:usergroup_user_import.php

示例5: array

    }
}
if (isset($_GET['import'])) {
    $interbreadcrumb[] = array('url' => 'gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']), 'name' => get_lang('ViewResult'));
    $import_result_form = new DataForm(DataForm::TYPE_IMPORT, 'import_result_form', null, api_get_self() . '?import=&selecteval=' . Security::remove_XSS($_GET['selecteval']), '_blank', '');
    if (!$import_result_form->validate()) {
        Display::display_header(get_lang('Import'));
    }
    $eval[0]->check_lock_permissions();
    if ($_POST['formSent']) {
        if (!empty($_FILES['import_file']['name'])) {
            $values = $import_result_form->exportValues();
            $file_type = $_POST['file_type'];
            $file_name = $_FILES['import_file']['tmp_name'];
            if ($file_type == 'csv') {
                $results = Import::csv_to_array($file_name);
            } else {
                $results = parse_xml_data($file_name);
            }
            $nr_results_added = 0;
            foreach ($results as $index => $importedresult) {
                //check username & score
                $importedresult['user_id'] = UserManager::get_user_id_from_username($importedresult['username']);
                $added = '0';
                foreach ($allresults as $allresult) {
                    if ($importedresult['user_id'] == $allresult->get_user_id()) {
                        if ($importedresult['score'] != $allresult->get_score()) {
                            if (!isset($values['overwrite'])) {
                                header('Location: gradebook_view_result.php?selecteval=' . Security::remove_XSS($_GET['selecteval']) . '&import_score_error=' . $importedresult['user_id']);
                                exit;
                                break;
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:31,代码来源:gradebook_view_result.php

示例6: parse_csv_data

/**
 * Read the CSV-file
 * @param string $file Path to the CSV-file
 * @return array All userinformation read from the file
 */
function parse_csv_data($file)
{
    $users = Import::csv_to_array($file);
    foreach ($users as $index => $user) {
        if (isset($user['Courses'])) {
            $user['Courses'] = explode('|', trim($user['Courses']));
        }
        $users[$index] = $user;
    }
    return $users;
}
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:16,代码来源:user_update_import.php

示例7: thematic

 /**
  * This method is used for thematic control (update, insert or listing)
  * @param 	string	Action
  * render to thematic.php
  */
 public function thematic($action)
 {
     $courseInfo = api_get_course_info();
     $thematic = new Thematic($courseInfo);
     $data = array();
     $error = false;
     $check = Security::check_token('request');
     $thematic_id = isset($_REQUEST['thematic_id']) ? intval($_REQUEST['thematic_id']) : null;
     if ($check) {
         switch ($action) {
             case 'thematic_add':
             case 'thematic_edit':
                 // insert or update a thematic
                 if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
                     if (trim($_POST['title']) !== '') {
                         if (api_is_allowed_to_edit(null, true)) {
                             $id = $_POST['thematic_id'];
                             $title = $_POST['title'];
                             $content = $_POST['content'];
                             $session_id = api_get_session_id();
                             $thematic->set_thematic_attributes($id, $title, $content, $session_id);
                             $last_id = $thematic->thematic_save();
                             if ($_POST['action'] == 'thematic_add') {
                                 $action = 'thematic_details';
                                 $thematic_id = null;
                                 if ($last_id) {
                                     $data['last_id'] = $last_id;
                                 }
                             } else {
                                 $action = 'thematic_details';
                                 $thematic_id = null;
                             }
                         }
                     } else {
                         $error = true;
                         $data['error'] = $error;
                         $data['action'] = $_POST['action'];
                         $data['thematic_id'] = $_POST['thematic_id'];
                         // render to the view
                         $this->view->set_data($data);
                         $this->view->set_layout('layout');
                         $this->view->set_template('thematic');
                         $this->view->render();
                     }
                 }
                 break;
             case 'thematic_copy':
                 //Copy a thematic to a session
                 $thematic->copy($thematic_id);
                 $thematic_id = null;
                 $action = 'thematic_details';
                 break;
             case 'thematic_delete_select':
                 //Delete many thematics
                 if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
                     if (api_is_allowed_to_edit(null, true)) {
                         $thematic_ids = $_POST['id'];
                         $affected_rows = $thematic->thematic_destroy($thematic_ids);
                     }
                     $action = 'thematic_details';
                 }
                 break;
             case 'thematic_delete':
                 // Delete a thematic
                 if (isset($thematic_id)) {
                     if (api_is_allowed_to_edit(null, true)) {
                         $affected_rows = $thematic->thematic_destroy($thematic_id);
                     }
                     $thematic_id = null;
                     $action = 'thematic_details';
                 }
                 break;
             case 'thematic_import_select':
                 break;
             case 'thematic_import':
                 $csv_import_array = Import::csv_to_array($_FILES['file']['tmp_name'], 'horizontal');
                 if (isset($_POST['replace']) && $_POST['replace']) {
                     // Remove current thematic.
                     $list = $thematic->get_thematic_list();
                     foreach ($list as $i) {
                         $thematic->thematic_destroy($i);
                     }
                 }
                 // Import the progress.
                 $current_thematic = null;
                 foreach ($csv_import_array as $data) {
                     foreach ($data as $key => $item) {
                         if ($key == 'title') {
                             $thematic->set_thematic_attributes(null, $item[0], $item[1], api_get_session_id());
                             $current_thematic = $thematic->thematic_save();
                             $description_type = 0;
                         }
                         if ($key == 'plan') {
                             $thematic->set_thematic_plan_attributes($current_thematic, $item[0], $item[1], $description_type);
                             $thematic->thematic_plan_save();
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:thematic_controller.php

示例8: importCourses

 /**
  * @param string $file
  */
 private function importCourses($file)
 {
     $data = Import::csv_to_array($file);
     //$language = $this->defaultLanguage;
     if (!empty($data)) {
         $this->logger->addInfo(count($data) . " records found.");
         foreach ($data as $row) {
             $row = $this->cleanCourseRow($row);
             $courseCode = CourseManager::get_course_id_from_original_id($row['extra_' . $this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
             //$courseInfo = api_get_course_info($row['course_code']);
             $courseInfo = api_get_course_info($courseCode);
             if (empty($courseInfo)) {
                 // Create
                 $params = array();
                 $params['title'] = $row['title'];
                 $params['exemplary_content'] = false;
                 $params['wanted_code'] = $row['course_code'];
                 $params['course_category'] = $row['course_category'];
                 $params['course_language'] = $row['language'];
                 $params['teachers'] = $row['teachers'];
                 $courseInfo = CourseManager::create_course($params);
                 if (!empty($courseInfo)) {
                     CourseManager::update_course_extra_field_value($courseInfo['code'], 'external_course_id', $row['extra_' . $this->extraFieldIdNameList['course']]);
                     $this->logger->addInfo("Courses - Course created " . $courseInfo['code']);
                 } else {
                     $this->logger->addError("Courses - Can't create course:" . $row['title']);
                 }
             } else {
                 // Update
                 $params = array('title' => $row['title']);
                 $result = CourseManager::update_attributes($courseInfo['real_id'], $params);
                 //CourseManager::updateTeachers($courseInfo['id'], $row['teachers']);
                 if ($result) {
                     $this->logger->addInfo("Courses - Course updated " . $courseInfo['code']);
                 } else {
                     $this->logger->addError("Courses - Course NOT updated " . $courseInfo['code']);
                 }
             }
         }
     }
     $this->moveFile($file);
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:45,代码来源:import_csv.php


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