function getList() { $registry = Registry::getInstance(); $i18n = new I18n($registry->get('i18n_path') . 'exercise.xml'); $data = ['list' => Exercise::getList()]; $renderer = new Renderer(Page::MODE_NORMAL); $pTitle = $i18n->get('title'); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', ExerciseListView::get($data)); $renderer->loadPage(); $renderer->output(); }
function testExerciseGetList() { $registry = Registry::getInstance(); $id = $registry->get('exerciseId'); $list = Exercise::getList(); $this->assertNotCount(0, $list, "getList returns empty array from not empty database ({$id})"); $this->assertArrayHasKey($id, $list, "getList did not found existing Exercise ({$id})"); $exercise = $list[$id]; $this->assertInstanceOf('WBT\\Exercise', $exercise, "getList item is not an instance of Exercise"); $this->assertEquals($this->data[1]['name'], $exercise->name, "getList: Invalid name ({$id}) after update."); $this->assertEquals($this->data[1]['description'], $exercise->description, "getList: Invalid description ({$id}) after update."); $this->assertEquals($this->data[1]['controller'], $exercise->controller, "getList: Invalid controller ({$id}) after update."); $this->assertEquals($this->data[1]['config_template'], $exercise->configTemplate, "getList: Invalid config_template ({$id}) after update."); unset($exercise); }
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(); } }
function edit() { $registry = Registry::getInstance(); $locales = LocaleManager::getLocales(); $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); if (!$id) { $lesson = new Lesson(filter_input(INPUT_GET, 'lesson_id', FILTER_VALIDATE_INT)); $lessonId = $lesson->id; if (!$lessonId) { header('Location: /cms/course/list'); exit; } } $stage = new Stage($id); if ($_POST['action'] == 'save') { //d($_POST, 1); if (!$stage->id) { $exercise = new Exercise(filter_input(INPUT_POST, 'exercise_id', FILTER_VALIDATE_INT)); $exerciseId = $exercise->id; //die(print_r($_POST)); if (!$exerciseId) { header('Location: /cms/course/list'); exit; } $stage->lessonId = $lessonId; $stage->exerciseId = $exerciseId; $stage->settings = $exercise->configTemplate; } foreach (array_keys($locales) as $localeId) { $stage->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])]); } $stage->name = filter_input(INPUT_POST, 'name'); $stage->save(); header('Location: /cms/lesson/edit?id=' . $stage->lessonId); exit; } else { $i18n = new I18n($registry->get('i18n_path') . 'stage.xml'); $data['stage'] = $stage; $data['materials'] = Material::getList($this->id); if ($stage->id) { $exercise = new Exercise($stage->exerciseId); $data['exerciseName'] = $exercise->name; } else { $data['exercises'] = Exercise::getList(); } $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', StageEditView::get($data)); $renderer->loadPage(); $renderer->output(); } }