Esempio n. 1
0
 public function actionLink()
 {
     //	$lessons = Lesson::model()->findAllByAttributes(array('mediaType'=>'link'));
     $criteria = new CDbCriteria();
     $criteria->condition = "mediaType='' and mediaUri!=''";
     $lessons = Lesson::model()->findAll($criteria);
     foreach ($lessons as $lesson) {
         $link = new MediaLink();
         $link->url = $lesson->mediaUri;
         $link->title = $lesson->title;
         if ($link->save()) {
             $lesson->mediaType = "link";
             $lesson->mediaId = $link->getPrimaryKey();
             $lesson->save();
         }
     }
 }
Esempio n. 2
0
 public function afterSave(&$model, $created)
 {
     CakeLog::write('debug', $this->_dataToBeSaved);
     // if new mediafile is created and something is to store
     if ($created && $this->_dataToBeSaved) {
         App::import('Model', 'Trois.MediaLink');
         $mediaLink = new MediaLink();
         /*
          if( !empty($data['foreign_model']) )
          {
         */
         $data = $this->_dataToBeSaved;
         $data['mediafile_id'] = $model->id;
         $data['order'] = $mediaLink->getCount($data['foreign_model'], $data['foreign_field'], $data['foreign_key']);
         $mediaLink->create();
         $mediaLink->save($data);
         /*
          }else{
          foreach( $this->_dataToBeSaved as $data )
          {
          $data['mediafile_id'] =  $model->id;
         
          $data['order'] = $mediaLink->getCount(
          $data['foreign_model'],
          $data['foreign_field'],
          $data['foreign_key']
          );
         
          $mediaLink->create();
          $mediaLink->save( $data );
          }
          }
         */
     }
     $this->_dataToBeSaved = false;
 }
Esempio n. 3
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));
 }