Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Lesson();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Lesson'])) {
         $model->attributes = $_POST['Lesson'];
         if ($model->save()) {
             Yii::app()->user->setFlash('info', '<span class="single-name">' . $model->singleName() . '</span> <b>' . $model->name . '</b> ' . Yii::app()->params['postActions'][Yii::app()->controller->action->id] . '!');
             $this->redirect(array('/lesson'));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Lesson();
     if (isset($_POST['Lesson'])) {
         $acl = $this->_gets->getPost('acl');
         $model->attributes = $_POST['Lesson'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('lesson_create', array('model' => $model));
 }
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Lesson();
     if (isset($_POST['Lesson'])) {
         $acl = $this->_gets->getPost('acl');
         $model->attributes = $_POST['Lesson'];
         $model->teacher_id = 88888888;
         $model->check_status = 1;
         $model->actual_students = 0;
         $model->arrivals = 0;
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('lessonRecommend_create', array('model' => $model));
 }
Пример #4
0
 function testFind()
 {
     $name = "John Doe";
     $password = "******";
     $email = "*****@*****.**";
     $signed_in = 0;
     $test_user = new User($name, $password, $email, $signed_in);
     $test_user->save();
     $course_title = "Literature";
     $subject = "English";
     $course_description = "Deconstructing English literature.";
     $user_id = $test_user->getId();
     $test_course = new Course($course_title, $subject, $course_description, $user_id);
     $test_course->save();
     $unit_title = "Into the Wild";
     $unit_description = "The life and death of Chris McCandless.";
     $course_id = $test_course->getId();
     $test_unit = new Unit($unit_title, $unit_description, $course_id);
     $test_unit->save();
     $lesson_title = "Into the Wild: Chapter 1";
     $objective = "Students will read and discuss Chapter 1";
     $materials = "Books, discussion packets, pencils";
     $body = "Lorem ipsum etc etc blah blah blah blah...";
     $unit_id = $test_unit->getId();
     $test_lesson = new Lesson($lesson_title, $objective, $materials, $body, $unit_id);
     $test_lesson->save();
     $lesson_title2 = "The Catcher in the Rye: Chapter 3";
     $objective2 = "Students will read and discuss Chapter 3";
     $materials2 = "Books, essay prompts, pens";
     $body2 = "Blah blah blah etc etc lorem ipsum...";
     $test_lesson2 = new Lesson($lesson_title2, $objective2, $materials2, $body, $unit_id);
     $test_lesson2->save();
     $result = Lesson::find($test_lesson->getId());
     $this->assertEquals($test_lesson, $result);
 }
Пример #5
0
 /**
  * 一次性导入优酷视频
  * Enter description here ...
  * @param unknown_type $courseId
  */
 public function actionYoukuPlayList($courseId = 0)
 {
     if (isset($_POST['url'])) {
         $url = $_POST['url'];
         //			$output = Yii::app()->curl->get($_POST['url']);
         //			$partern = "";
         Yii::import('ext.SimpleHTMLDOM.SimpleHTMLDOM');
         // Create DOM from URL or file
         $simpleHTML = new SimpleHTMLDOM();
         $html = $simpleHTML->file_get_html($url);
         $urlDict = array('playlist' => array('pattern' => "/\\/playlist_show\\/id_/i", 'selector' => '#list1_1 .items  li.v_title a'), 'episode' => array('pattern' => "/\\/show_page\\/id_/i", 'selector' => '#episode li.ititle_w a'));
         foreach ($urlDict as $key => $item) {
             if (preg_match($item['pattern'], $url)) {
                 $type = $key;
                 $selector = $item['selector'];
                 break;
             }
         }
         // Find all images
         foreach ($html->find($selector) as $elem) {
             $lesson = new Lesson();
             $lesson->courseId = $courseId;
             $lesson->title = $elem->getAttribute("title") ? $elem->getAttribute("title") : $elem->innertext;
             $pattern = "/id_(.*)\\/?\\.html/i";
             preg_match($pattern, $elem->href, $matches);
             if ($matches[1]) {
                 //		http://player.youku.com/player.php/sid/XNTk5MTQ3OTQ0/v.swf
                 $lesson->url = "http://player.youku.com/player.php/sid/{$matches['1']}/v.swf";
             } else {
                 continue;
             }
             $lesson->addTime = time();
             $lesson->save();
         }
         $this->redirect(array('lesson/editByCourse', 'courseId' => $courseId));
         Yii::app()->end();
     }
     $course = Course::model()->findByPk($courseId);
     $this->renderPartial("youkuPlayList", array('course' => $course), false, true);
 }
Пример #6
0
    $unit = Unit::find($unit_id);
    $course = Course::find($course_id);
    //Deleting a unit should also delete orphaned lessons
    $lessons = $unit->getLessons();
    foreach ($lessons as $lesson) {
        $lesson->delete();
    }
    $unit->delete();
    $course_units = $course->getUnits();
    $user_id = $course->getUserId();
    return $app['twig']->render("course.html.twig", array('course' => Course::find($course_id), 'units' => $course_units, 'user' => User::find($user_id)));
});
//Add a lesson
$app->post("/add_lesson/{course_id}/{unit_id}", function ($course_id, $unit_id) use($app) {
    $new_lesson = new Lesson($_POST['lesson_title'], $_POST['lesson_objective'], $_POST['lesson_materials'], $_POST['lesson_body'], $unit_id);
    $new_lesson->save();
    $unit = Unit::find($unit_id);
    $course = Course::find($course_id);
    $user_id = $course->getUserId();
    return $app['twig']->render("unit.html.twig", array('unit' => $unit, 'lessons' => $unit->getLessons(), 'course' => $course, 'user' => User::find($user_id)));
});
//================= Lesson Routes ===============
//Show lesson
$app->get("/show_lesson/{id}", function ($id) use($app) {
    $lesson = Lesson::find($id);
    $unit_id = $lesson->getUnitId();
    $unit = Unit::find($unit_id);
    $course_id = $unit->getCourseId();
    $course = Course::find($course_id);
    $user_id = $course->getUserId();
    return $app['twig']->render("lesson.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'course' => $course, 'user' => User::find($user_id)));
Пример #7
0
 public function actionAddLesson()
 {
     $this->_seoTitle = '名师 - 增加课程';
     $model = new Lesson();
     if (isset($_POST['Lesson'])) {
         $model->attributes = $_POST['Lesson'];
         $model->teacher_id = $this->_user['masterId'];
         if ($model->validate()) {
             $file = XUpload::upload($_FILES['attach']);
             if (is_array($file)) {
                 $model->pic = $file['pathname'];
                 @unlink($_POST['oAttach']);
                 @unlink($_POST['oThumb']);
             }
         }
         if ($model->save()) {
             $this->redirect(array('mylesson'));
         }
     }
     $this->render('addlesson', array('model' => $model));
 }
Пример #8
0
 public function actionCreateMany($courseId)
 {
     $course = $this->loadCourse($courseId);
     if (isset($_POST['playList'])) {
         Yii::import('ext.videolink.VideoList');
         $videolist = new VideoList();
         $videos = $videolist->parse($_POST['playList']);
         $result = false;
         foreach ($videos as $item) {
             $mediaLink = new MediaLink();
             $mediaLink->title = $item['title'];
             $mediaLink->url = $item['url'];
             if ($mediaLink->save()) {
                 $lesson = new Lesson();
                 $lesson->title = $mediaLink->title ? $mediaLink->title : Yii::t('app', "未设置");
                 $lesson->mediaType = "link";
                 $lesson->mediaId = $mediaLink->id;
                 $lesson->courseId = $courseId;
                 $result = $lesson->save();
             }
         }
         if ($result) {
             Yii::app()->user->setFlash('success', Yii::t('app', '操作成功!'));
         } else {
             Yii::app()->user->setFlash('error', Yii::t('app', '操作失败!'));
         }
     }
     $this->layout = "/layouts/nonav_column1";
     $this->render('create_many_fancy', array('course' => $course));
 }