예제 #1
0
파일: StageTest.php 프로젝트: jne21/WBT
 function test_StageGetList()
 {
     $registry = Registry::getInstance();
     $setup = $registry->get(self::REG_KEY);
     $locales = LocaleManager::getLocales();
     $list = Stage::getList($setup['lessonId']);
     $this->assertNotCount(0, $list, "getList returns empty array from not empty database ({$setup['id']})");
     $this->assertArrayHasKey($setup['id'], $list, "getList: Existing Stage not found ({$setup['id']})");
     $stage = $list[$setup['id']];
     $this->assertInstanceOf('WBT\\Stage', $stage, "getList item is not an instance of Stage");
     $this->assertEquals($setup['lessonId'], $stage->lessonId, "getList: Invalid lesson id ({$setup['id']}).");
     foreach ($locales as $localeId => $localeData) {
         foreach ($this->l10nFields as $field) {
             $this->assertEquals($setup['l10n']->get($field, $localeId), $stage->l10n->get($field, $localeId), "getList: Invalid ({$setup['id']})->l10n({$localeId}, {$field}).");
         }
     }
     unset($stage);
 }
예제 #2
0
 function edit()
 {
     $registry = Registry::getInstance();
     $application = Application::getInstance();
     $locale = $registry->get('locale');
     $locales = LocaleManager::getLocales();
     $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
     $lesson = new Lesson($id);
     if (!$lesson->id) {
         $course = new Course(filter_input(INPUT_GET, 'course_id', FILTER_VALIDATE_INT));
     } else {
         $course = new Course($lesson->courseId);
     }
     if (!$course->id) {
         header('Location: /cms/course/list');
         exit;
     }
     if ('save' == filter_input(INPUT_POST, 'action')) {
         if (!$lesson->id) {
             $lesson->courseId = $course->id;
         }
         foreach (array_keys($locales) as $localeId) {
             $lesson->l10n->loadDataFromArray($localeId, ['name' => trim($_POST['name_' . $localeId]), 'meta' => trim($_POST['meta_' . $localeId]), 'description' => trim($_POST['description_' . $localeId]), 'brief' => trim($_POST['brief_' . $localeId]), 'url' => trim($_POST['url_' . $localeId]), 'title' => trim($_POST['title_' . $localeId])]);
         }
         $lesson->save();
         header('Location: /cms/course/edit?id=' . $lesson->courseId);
         exit;
     } else {
         $i18n = new I18n($registry->get('i18n_path') . 'lesson.xml');
         $data['lesson'] = $lesson;
         $data['exercises'] = Exercise::getList();
         $data['stages'] = Stage::getList($lesson->id);
         $renderer = new Renderer(Page::MODE_NORMAL);
         $pTitle = $i18n->get($lesson->id ? 'update_mode' : 'append_mode');
         $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', LessonEditView::get($data));
         $renderer->loadPage();
         $renderer->output();
     }
 }