Exemplo n.º 1
0
 protected function beforeSave()
 {
     if ($this->mediaType !== $this->_oldMediaType || $this->mediaType === $this->_oldMediaType && $this->mediaId == $this->_oldMediaId) {
         if ($this->_oldMediaType == "video") {
             $this->file->delete();
         } else {
             if ($this->_oldMediaType == "link") {
                 $this->mediaLink->delete();
             }
         }
     }
     if ($this->mediaType == "quiz" && $this->mediaId == 0) {
         $quiz = new Quiz();
         $quiz->save();
         $this->mediaId = $quiz->getPrimaryKey();
     }
     if (!$this->weight || !$this->number) {
         $criteria = new CDbCriteria();
         $criteria->condition = "courseId=" . intval($this->courseId);
         $criteria->select = "max(weight) as maxWeight,max(number) as maxNumber";
         $lesson = Lesson::model()->find($criteria);
         $chapter = Chapter::model()->find($criteria);
     }
     if (!$this->weight) {
         if (!$lesson && !chapter) {
             $this->weight = 1;
         } else {
             if (!$lesson) {
                 $this->weight = $chapter->maxWeight + 1;
             } else {
                 if (!$chapter) {
                     $this->weight = $lesson->maxWeight + 1;
                 } else {
                     $this->weight = max(array($chapter->maxWeight, $lesson->maxWeight)) + 1;
                 }
             }
         }
     }
     if (!$this->number) {
         if ($lesson) {
             $this->number = $lesson->maxNumber + 1;
         } else {
             $this->number = 1;
         }
     }
     return parent::beforeSave();
 }
Exemplo n.º 2
0
 protected function beforeSave()
 {
     //删除文件
     // if(!$this->isNewRecord){
     // 	if($this->mediaType!==$this->_oldMediaType
     // 		||($this->mediaType===$this->_oldMediaType && $this->mediaId!==$this->_oldMediaId)){
     // 		error_log(print_r($this,true));
     // 		if($this->_oldMediaType=="video"){
     // 			$this->file->delete();
     // 		}else if($this->_oldMediaType=="link"){
     // 			$this->mediaLink->delete();
     // 		}
     // 	}
     // }
     //创建quiz
     if ($this->mediaType == "quiz" && $this->mediaId == 0) {
         $quiz = new Quiz();
         $quiz->save();
         $this->mediaId = $quiz->getPrimaryKey();
     }
     if ($this->mediaType == "text" && $this->mediaId == 0) {
         $quiz = new Text();
         $quiz->save();
         $this->mediaId = $quiz->getPrimaryKey();
     }
     //设置课时数
     if (!$this->weight || !$this->number) {
         $criteria = new CDbCriteria();
         $criteria->condition = "courseId=" . intval($this->courseId);
         $criteria->select = "max(weight) as maxWeight,max(number) as maxNumber";
         $lesson = Lesson::model()->find($criteria);
         $chapter = Chapter::model()->find($criteria);
     }
     if (!$this->weight) {
         if (!$lesson && !chapter) {
             $this->weight = 1;
         } else {
             if (!$lesson) {
                 $this->weight = $chapter->maxWeight + 1;
             } else {
                 if (!$chapter) {
                     $this->weight = $lesson->maxWeight + 1;
                 } else {
                     $this->weight = max(array($chapter->maxWeight, $lesson->maxWeight)) + 1;
                 }
             }
         }
     }
     if (!$this->number) {
         if ($lesson) {
             $this->number = $lesson->maxNumber + 1;
         } else {
             $this->number = 1;
         }
     }
     return parent::beforeSave();
 }
Exemplo n.º 3
0
 public function actionUpdateQuiz($id)
 {
     $lesson = $this->loadModel($id);
     if (!$lesson->quiz) {
         $quiz = new Quiz();
         $quiz->save();
         $lesson->deleteMedia();
         $lesson->mediaId = $quiz->getPrimaryKey();
         $lesson->save();
     }
     $this->redirect(array('quiz/view', 'id' => $quiz->id));
 }