/** * 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)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Lecture(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Lecture'])) { $model->attributes = $_POST['Lecture']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
function testCreate_OneToMany() { $this->_createModelAndIncludeThem('lecture', 'Lecture'); $this->_createModelAndIncludeThem('course', 'Course'); $course = new Course(); $course->setTitle($course_title = 'bar'); $course->save(); $lecture = new Lecture(); $lecture->setTitle($lecture_title = 'foo'); $lecture->setCourse($course); $lecture->save(); $loaded_lecture = lmbActiveRecord::findById('Lecture', $lecture->getId()); $this->assertEqual($loaded_lecture->getTitle(), $lecture_title); $this->assertEqual($loaded_lecture->getCourse()->getId(), $course->getId()); $loaded_course = lmbActiveRecord::findById('Course', $course->getId()); $this->assertEqual($loaded_course->getLectures()->at(0)->getId(), $lecture->getId()); }
public static function addNewLesson($module, $title, $lang, $teacher){ $lecture = new Lecture(); $lecture->title = $title; $lecture->idModule = $module; // $order = Yii::app()->db->createCommand() // ->select('order') // ->from('lectures') // ->order('order DESC') // ->limit('1') // ->queryRow()["order"]; $order = Lecture::model()->count("idModule=$module and `order`>0"); $lecture->order = ++$order; $lecture->language = $lang; $lecture->idTeacher = $teacher; $lecture->alias = 'lecture'.$order; // if (!$lecture->isNewRecord) { $lecture->save(); // } else { // throw new CHttpException(422, 'Така лекція вже існує.'); // } return $order; }