コード例 #1
0
 /**
  * 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
0
 /**
  * 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) : '';
         $content = isset($item->content) ? trim($item->content) : '';
         $type = isset($item->type) ? trim($item->type) : '';
         $title = \Security::remove_XSS($title);
         $content = \Security::remove_XSS($content);
         $type = \Security::remove_XSS($type);
         $is_blank_line = empty($title) && empty($content) && empty($type);
         if ($is_blank_line) {
             continue;
         }
         $type = CourseDescriptionType::repository()->find_one_by_name($type);
         $type_id = $type ? $type->id : 0;
         $description = CourseDescription::create();
         $description->title = $title;
         $description->content = $content;
         $description->description_type = $type_id;
         $result[] = $description;
     }
     return $result;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * @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']);
         }
     }
 }
コード例 #5
0
ファイル: index.php プロジェクト: annickvdp/Chamilo1.9.10
 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();
 }
コード例 #6
0
 /**
  * @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);
     }
 }
コード例 #7
0
ファイル: import_csv.php プロジェクト: ragebat/chamilo-lms
 /**
  * @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']);
         }
     }
 }
コード例 #8
0
        $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);