Esempio n. 1
0
 function edit()
 {
     $registry = Registry::getInstance();
     $application = Application::getInstance();
     $locale = $registry->get('locale');
     $locales = LocaleManager::getLocales();
     $exercise = new Exercise(intval($_GET['id']));
     if ($_POST['action'] == 'save') {
         //d($_POST, 1);
         $exercise->name = trim($_POST['name']);
         $exercise->description = trim($_POST['description']);
         $exercise->controller = trim($_POST['controller']);
         $exercise->configTemplate = trim($_POST['config_template']);
         $exercise->save();
         header('Location: /cms/exercise/list');
         exit;
     } else {
         $i18n = new I18n($registry->get('i18n_path') . 'exercise.xml');
         $data = ['exercise' => $exercise];
         $renderer = new Renderer(Page::MODE_NORMAL);
         $pTitle = $i18n->get($exercise->id ? 'update_mode' : 'append_mode');
         $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', ExerciseEditView::get($data));
         $renderer->loadPage();
         $renderer->output();
     }
 }
Esempio n. 2
0
 static function createExercise()
 {
     $exercise = new Exercise();
     $exercise->name = "unitTest " . microtime();
     $exercise->description = "unitTest description";
     $exercise->controller = "unit_test_controller.php";
     $exercise->configTemplate = "unit_test_config_template";
     $exercise->save();
     return $exercise;
 }
Esempio n. 3
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();
     }
 }
Esempio n. 4
0
 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();
     }
 }