/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Lecture();
     if (isset($_POST['Lecture'])) {
         $model->attributes = $_POST['Lecture'];
         if (empty($model->owner_by)) {
             $model->owner_by = Yii::app()->user->getId();
         }
         if ($model->save()) {
             if (!Yii::app()->user->checkAccess('adminLecture')) {
                 $model->is_active = 0;
                 $adminUserIds = Yii::app()->db->createCommand()->select('userid')->from('authassignment')->where('itemname=:itemname', array(':itemname' => 'admin'))->queryColumn();
                 foreach ($adminUserIds as $id) {
                     $message = new Message();
                     $message->id_from = Yii::app()->user->getId();
                     $message->id_user = $id;
                     $message->subject = 'A new lecture is created';
                     $message->message = "User " . CHtml::link($this->viewer->username, $this->createUrl('account/view', array('id' => $this->viewer->getPrimaryKey()))) . " have just created the lecture " . CHtml::link($model->title, $this->createUrl('lecture/view', array('id' => $model->getPrimaryKey())));
                     $message->save();
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
         //            $model->fileIntro = $file = CUploadedFile::getInstance($model, 'fileIntro');
         //            if ($model->validate(array('fileIntro'))) {
         //                if ($file) {
         //                    $fileName = Yii::app()->params['video'] . '/' . $file->getName();
         //                    if (file_exists($fileName)) {
         //                        $fileName = Yii::app()->params['video'] . '/'
         //                                . time() . '_' . $file->getName();
         //                    }
         //                    if ($file->saveAs(strtolower($fileName), true)) {
         //                        /* $videoHelper = new CVideo();
         //                          $videoThumbnailName = $videoHelper->create_thumbnail($fileName,
         //                          Yii::app()->params['videoWidth'],
         //                          Yii::app()->params['videoHeight'],
         //                          Yii::app()->params['videoThumbnail']
         //                          );
         //                          $convertVideoFileName = $videoHelper->convertVideo($fileName);
         //
         //                          $model->path_video_intro = $convertVideoFileName;
         //                          $model->path_video_thumbnail = $videoThumbnailName; */
         //                        $model->path_video_intro = $fileName;
         //                        $model->path_video_thumbnail = Yii::app()->params['defaultLectureThumbnail'];
         //                    }
         //                }
         //                if ($model->save()) {
         //                    $this->redirect(array('view', 'id' => $model->id));
         //                }
         //            }
     }
     $params = $this->getActionParams();
     if ($params && array_key_exists('idCategory', $params)) {
         $model->id_category = (int) $params['idCategory'];
     }
     if (Yii::app()->user->checkAccess('adminLecture')) {
         $model->is_active = 1;
     }
     $this->render('create', array('model' => $model));
 }