/**
  * Updates an existing Banner model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $resourceModel = new Resource();
         $model = $resourceModel->uploadImg($model, 'img');
         $model->update_time = Common::getTime();
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('update', ['model' => $model]);
 }
Exemple #2
0
 /**
  * [transcode Transcode video]
  * @param  [Resource] $model []
  * @return [bool]        [success or failed]
  */
 public function transcode(Resource $model)
 {
     if ($model->save()) {
         $rootPath = Yii::$app->params['uploadUrl'];
         $time = time();
         exec("ffmpeg -i {$rootPath}{$model->url} -f mp4 -vcodec libx264 -s 640x360 {$rootPath}/uploads/video/{$model->name}.{$time}.mp4", $res, $rc);
         if (!$rc) {
             $model->status = static::STATUS_AUTHEN;
             $model->extension = 'mp4';
             $model->url = "/uploads/video/{$model->name}.{$time}.mp4";
             $model->update_time = Common::getTime();
             if ($model->save()) {
                 return true;
             }
         }
     }
     return false;
 }
Exemple #3
0
 public function validateAttr(Task $model)
 {
     if ($model->task_type == static::TYPE_CHOICE) {
         if (!$model['option_A']) {
             $model->addError('option_A', Yii::t('app', 'The option_A cannot be blank.'));
         }
         if (!$model['option_B']) {
             $model->addError('option_B', Yii::t('app', 'The option_B cannot be blank.'));
         }
         if (!$model['answer_choice']) {
             $model->addError('answer_choice', Yii::t('app', 'The answer_choice cannot be blank.'));
         }
         $optionArr = ['A' => $model['option_A'], 'B' => $model['option_B'], 'C' => $model['option_C'], 'D' => $model['option_D']];
         $optionArr = array_filter($optionArr);
         $choiceArr = $model['answer_choice'];
         if (!$this->validateAnswer($optionArr, $choiceArr)) {
             $model->addError('answer_choice', Yii::t('app', 'The answer_choice is not correct.'));
         }
         unset($model['answer_choice']);
         $model->option_json = json_encode($optionArr);
         $model->answer_json = json_encode($choiceArr);
         if ($model->is_timing == static::IS_NOT_TIMING) {
             $model->complete_time = '00:00';
         }
     }
     // if ($model->task_type == static::TYPE_SHORT_ANSWER || $model->task_type == static::TYPE_CALCULATION) {
     //     if (empty($model->answer_json)) {
     //         $model->addError('answer_json', Yii::t('app', 'The answer_json cannot be blank.'));
     //     }
     // }
     if ($model->task_type == static::TYPE_CODING) {
         if (empty($model['code_test_one_input'])) {
             $model->addError('code_test_one_input', Yii::t('app', 'code_test_one_input cannot be blank.'));
         }
         if (empty($model['code_test_one_output'])) {
             $model->addError('code_test_one_output', Yii::t('app', 'code_test_one_output cannot be blank.'));
         }
     }
     $model->update_time = Common::getTime();
     return $model;
 }
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['user_id', 'course_id', 'content'], 'required'], [['user_id', 'course_id', 'score', 'up_count', 'down_count', 'comment_type', 'root_id'], 'integer'], [['comment_time'], 'safe'], [['content'], 'string', 'max' => 255], ['comment_time', 'default', 'value' => Common::getTime()], ['comment_type', 'default', 'value' => self::COMMENT_TYPE_COMMENT]];
 }
Exemple #5
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['user_id', 'course_id', 'type'], 'required'], [['user_id', 'course_id', 'type', 'learn_status', 'learn_time_total'], 'integer'], [['learn_time', 'create_time'], 'safe'], ['create_time', 'default', 'value' => Common::getTime()], ['type', 'default', 'value' => self::TYPE_LEARN], ['learn_status', 'default', 'value' => self::LEARN_STATUS_NOT_FINISH], ['learn_time_total', 'default', 'value' => self::LEARN_TIME_TOTAL_DEFAULT], ['learn_time', 'default', 'value' => Common::getTime()]];
 }
Exemple #6
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $rules_parent = parent::rules();
     $rules_course = [[['category', 'difficulty_level', 'teacher_id', 'status', 'learner_count', 'introduction', 'notice', 'gains', 'create_time', 'update_time'], 'safe'], [['teacher_id', 'status', 'category', 'learner_count'], 'integer'], [['introduction', 'notice', 'gains'], 'string', 'max' => 500], ['teacher_id', 'default', 'value' => Yii::$app->user->id], ['difficulty_level', 'default', 'value' => static::LEVEL_ELEMENTARY], ['status', 'default', 'value' => static::STATUS_VALID], ['icon', 'file', 'extensions' => static::$iconFormats], [['create_time', 'update_time'], 'default', 'value' => Common::getTime()]];
     return array_merge($rules_parent, $rules_course);
 }
Exemple #7
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['question_id', 'content', 'answer_user_id', 'answered_user_id'], 'required'], [['question_id', 'answer_user_id', 'answered_user_id', 'asker_status', 'reply_status'], 'integer'], [['content'], 'string'], [['create_time'], 'safe'], ['create_time', 'default', 'value' => Common::getTime()]];
 }
Exemple #8
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['user_id', 'course_id'], 'required'], [['user_id', 'course_id', 'nut_count'], 'integer'], [['create_time', 'update_time'], 'safe'], ['nut_count', 'default', 'value' => self::NUT_COUNT_DEFAULT], [['create_time', 'update_time'], 'default', 'value' => Common::getTime()]];
 }
Exemple #9
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['img'], 'required'], [['create_time', 'update_time'], 'safe'], [['title'], 'string', 'max' => 20], [['img', 'jump_target'], 'string', 'max' => 255], ['img', 'file', 'extensions' => ['png', 'jpg', 'jpeg', 'gif'], 'maxSize' => 1024 * 1024], [['create_time', 'update_time'], 'default', 'value' => Common::getTime()]];
 }
Exemple #10
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['user_id', 'content', 'course_id', 'root_id'], 'required'], [['user_id', 'course_id', 'root_id', 'views'], 'integer'], [['content'], 'string'], [['create_time'], 'safe'], ['create_time', 'default', 'value' => Common::getTime()]];
 }
Exemple #11
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['username', 'password', 'email'], 'required'], [['sex', 'type', 'status'], 'integer'], [['register_time', 'login_time'], 'safe'], ['username', 'string', 'min' => 2, 'max' => 16], ['password', 'string', 'min' => 6, 'max' => 16], [['email', 'head_picture', 'accessToken', 'authKey', 'signature'], 'string', 'max' => 255], [['phone_number'], 'string', 'max' => 11], [['faculty'], 'string', 'max' => 20], [['login_ip'], 'string', 'max' => 15], ['sex', 'default', 'value' => self::SEX_FEMALE], ['type', 'default', 'value' => self::TYPE_STUDENT], ['status', 'default', 'value' => self::STATUS_NORMAL], ['login_ip', 'default', 'value' => self::getIp()], [['login_time', 'register_time'], 'default', 'value' => Common::getTime()], ['username', 'unique', 'on' => 'signup'], ['password', 'compare', 'on' => 'signup'], ['password', 'match', 'pattern' => '/^[A-Za-z0-9\\-_]+$/', 'on' => 'signup', 'message' => '{attribute}为字母,数字和下划线组成'], ['password', 'validatePassword', 'on' => 'login'], ['email', 'email', 'on' => 'signup'], ['email', 'email', 'on' => 'profile'], ['rememberMe', 'boolean', 'on' => 'signup'], ['head_picture', 'file', 'extensions' => ['png', 'jpg', 'jpeg'], 'maxSize' => 1024 * 1024 * 1024, 'on' => 'profile'], ['head_picture', 'string', 'min' => 3, 'max' => 255, 'on' => 'refreshHeadPic']];
 }
Exemple #12
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['chapter_id', 'user_id', 'learn_status'], 'required'], [['chapter_id', 'user_id', 'learn_status', 'learn_time_total', 'learn_point'], 'integer'], [['learn_time'], 'safe'], ['learn_time_total', 'default', 'value' => self::LEARN_TIME_TOTAL_DEFAULT], ['learn_time', 'default', 'value' => Common::getTime()], ['learn_point', 'default', 'value' => self::LEARN_PONIT_DEFAULT]];
 }
Exemple #13
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['name', 'alias', 'direction'], 'required'], [['direction'], 'integer'], [['create_time'], 'safe'], [['name', 'alias'], 'string', 'max' => 20], ['create_time', 'default', 'value' => Common::getTime()]];
 }