本文整理汇总了PHP中Import::csv_reader方法的典型用法代码示例。如果您正苦于以下问题:PHP Import::csv_reader方法的具体用法?PHP Import::csv_reader怎么用?PHP Import::csv_reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Import
的用法示例。
在下文中一共展示了Import::csv_reader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* Read file and returns an array filled up with its' content.
*
* @return array of objects
*/
protected function read()
{
$result = array();
$path = $this->path;
if (!is_readable($path)) {
return array();
}
$items = \Import::csv_reader($path);
foreach ($items as $item) {
$item = (object) $item;
$title = isset($item->title) ? trim($item->title) : '';
$description = isset($item->description) ? trim($item->description) : '';
$name = \Security::remove_XSS($name);
$description = \Security::remove_XSS($description);
$is_blank_line = empty($name) && empty($description);
if ($is_blank_line) {
continue;
}
$item = new Notebook();
$item->title = $title;
$item->description = $description;
$result[] = $item;
}
return $result;
}
示例2: get_data
/**
* Read file and returns an array filled up with its' content.
*
* @return array of objects
*/
public function get_data()
{
$result = array();
$path = $this->path;
if (!is_readable($path)) {
return array();
}
$items = \Import::csv_reader($path);
foreach ($items as $item) {
$item = (object) $item;
$url = isset($item->url) ? trim($item->url) : '';
$title = isset($item->title) ? trim($item->title) : '';
$description = isset($item->description) ? trim($item->description) : '';
$target = isset($item->target) ? trim($item->target) : '';
$category_title = isset($item->category_title) ? trim($item->category_title) : '';
$category_description = isset($item->category_description) ? trim($item->category_description) : '';
if (empty($url)) {
continue;
}
if ($category_title) {
$category_title = \Security::remove_XSS($category_title);
$category_description = \Security::remove_XSS($category_description);
} else {
$category_description = '';
}
$url = \Security::remove_XSS($url);
$title = \Security::remove_XSS($title);
$description = \Security::remove_XSS($description);
$target = \Security::remove_XSS($target);
$item->url = $url;
$item->title = $title;
$item->description = $description;
$item->target = $target;
$item->category_title = $category_title;
$item->category_description = $category_description;
$result[] = $item;
}
return $result;
}
示例3: importUnsubscribeStatic
/**
* @param string $file
*/
private function importUnsubscribeStatic($file, $moveFile = false, &$teacherBackup = array(), &$groupBackup = array())
{
$data = Import::csv_reader($file);
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$chamiloUserName = $row['UserName'];
$chamiloCourseCode = $row['CourseCode'];
$chamiloSessionId = $row['SessionID'];
$sessionInfo = api_get_session_info($chamiloSessionId);
if (empty($sessionInfo)) {
$this->logger->addError('Session does not exists: ' . $chamiloSessionId);
continue;
}
$courseInfo = api_get_course_info($chamiloCourseCode);
if (empty($courseInfo)) {
$this->logger->addError('Course does not exists: ' . $courseInfo);
continue;
}
$userId = Usermanager::get_user_id_from_username($chamiloUserName);
if (empty($userId)) {
$this->logger->addError('User does not exists: ' . $chamiloUserName);
continue;
}
$sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "\n WHERE\n user_id = " . $userId . " AND\n course_code = '" . $courseInfo['code'] . "'\n ";
$result = Database::query($sql);
$userCourseData = Database::fetch_array($result, 'ASSOC');
$teacherBackup[$userId][$courseInfo['code']] = $userCourseData;
$sql = "SELECT * FROM " . Database::get_course_table(TABLE_GROUP_USER) . "\n WHERE\n user_id = " . $userId . " AND\n c_id = '" . $courseInfo['real_id'] . "'\n ";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['user'][$userId][$courseInfo['code']][$groupData['group_id']] = $groupData;
}
$sql = "SELECT * FROM " . Database::get_course_table(TABLE_GROUP_TUTOR) . "\n WHERE\n user_id = " . $userId . " AND\n c_id = '" . $courseInfo['real_id'] . "'\n ";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['tutor'][$userId][$courseInfo['code']][$groupData['group_id']] = $groupData;
}
CourseManager::unsubscribe_user($userId, $courseInfo['code'], $chamiloSessionId);
$this->logger->addError("User '{$chamiloUserName}' was removed from session: #{$chamiloSessionId}, Course: " . $courseInfo['code']);
}
}
}
示例4: get_lang
echo get_lang('CSVMustLookLike') . ' (' . get_lang('MandatoryFields') . ')';
echo '<pre>
<strong>term</strong>;<strong>definition</strong>;
"Hello";"Hola";
"Good";"Bueno";</pre>';
if ($form->validate()) {
//this is a bad idea //jm
if (isset($_POST['replace']) && $_POST['replace']) {
foreach (GlossaryManager::get_glossary_terms() as $term) {
if (!GlossaryManager::delete_glossary($term['id'], false)) {
Display::display_error_message(get_lang("CannotDeleteGlossary") . ':' . $term['id']);
}
}
}
//$data = Import::csv_to_array($_FILES['file']['tmp_name']);
$data = Import::csv_reader($_FILES['file']['tmp_name']);
$good = 0;
$bad = 0;
foreach ($data as $item) {
if (GlossaryManager::save_glossary(array('glossary_title' => $item['term'], 'glossary_comment' => $item['definition']), false)) {
$good++;
} else {
$bad++;
}
}
Display::display_confirmation_message(get_lang("TermsImported") . ':' . $good);
if ($bad) {
Display::display_error_message(get_lang("TermsNotImported") . ':' . $bad);
}
GlossaryManager::display_glossary();
}
示例5: importSessionDrhCSV
/**
* @param string $file
* @param bool $sendEmail
* @param bool $removeOldRelationShips
*/
public static function importSessionDrhCSV($file, $sendEmail, $removeOldRelationShips)
{
$list = Import::csv_reader($file);
if (!empty($list)) {
$userSessionList = array();
foreach ($list as $data) {
$userInfo = api_get_user_info_from_username($data['Username']);
$sessionInfo = self::get_session_by_name($data['SessionName']);
if (!empty($userInfo) && !empty($sessionInfo)) {
$userSessionList[$userInfo['user_id']]['session_list'][] = array('session_id' => $sessionInfo['id'], 'session_info' => $sessionInfo);
$userSessionList[$userInfo['user_id']]['user_info'] = $userInfo;
}
}
self::subscribeDrhToSessionList($userSessionList, $sendEmail, $removeOldRelationShips);
return self::checkSubscribeDrhToSessionList($userSessionList);
}
}
示例6: importUnsubscribeStatic
/**
* @param string $file
*/
private function importUnsubscribeStatic($file)
{
$data = Import::csv_reader($file);
if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found.");
foreach ($data as $row) {
$chamiloUserName = $row['UserName'];
$chamiloCourseCode = $row['CourseCode'];
$chamiloSessionId = $row['SessionID'];
$sessionInfo = api_get_session_info($chamiloSessionId);
if (empty($sessionInfo)) {
$this->logger->addError('Session does not exists: ' . $chamiloSessionId);
continue;
}
$courseInfo = api_get_course_info($chamiloCourseCode);
if (empty($courseInfo)) {
$this->logger->addError('Course does not exists: ' . $courseInfo);
continue;
}
$userId = Usermanager::get_user_id_from_username($chamiloUserName);
if (empty($userId)) {
$this->logger->addError('User does not exists: ' . $chamiloUserName);
continue;
}
CourseManager::unsubscribe_user($userId, $courseInfo['code'], $chamiloSessionId);
$this->logger->addError("User '{$chamiloUserName}' was removed from session: #{$chamiloSessionId}, Course: " . $courseInfo['code']);
}
}
}
示例7: api_get_course_id
$archiveFile = 'export_exercise_categoroes_' . api_get_course_id() . '_' . api_get_local_time();
$categories = $category->getCategories($courseId, $sessionId);
$export = [];
$export[] = ['title', 'description'];
if (!empty($categories)) {
foreach ($categories as $category) {
$export[] = [$category['title'], $category['description']];
}
}
Export::arrayToCsv($export, $archiveFile);
exit;
break;
case 'import_category':
$form = importCategoryForm();
if ($form->validate()) {
$categories = Import::csv_reader($_FILES['file']['tmp_name']);
if (!empty($categories)) {
foreach ($categories as $item) {
$cat = new TestCategory(0, $item['title'], $item['description']);
$cat->addCategoryInBDD();
}
Display::addFlash(Display::return_message(get_lang('Imported')));
}
}
$content = $form->returnForm();
break;
}
Display::display_header(get_lang('Category'));
displayActionBar();
echo $content;
echo $category->displayCategories($courseId, $sessionId);