Lesson frontend

parent c46cb168
...@@ -5,8 +5,8 @@ namespace common\modules\school; ...@@ -5,8 +5,8 @@ namespace common\modules\school;
class Module extends \common\components\WebModule class Module extends \common\components\WebModule
{ {
public $controllerNamespace = 'common\modules\school\controllers'; public $controllerNamespace = 'common\modules\school\controllers';
public $menu_icons = 'fa fa-comment-o'; public $menu_icons = 'fa fa-comment-o';
public static $active = true; public static $active = true;
...@@ -26,15 +26,15 @@ class Module extends \common\components\WebModule ...@@ -26,15 +26,15 @@ class Module extends \common\components\WebModule
{ {
return '1.0'; return '1.0';
} }
public function init() public function init()
{ {
parent::init(); parent::init();
// custom initialization code goes here // custom initialization code goes here
} }
public static function adminMenu() public static function adminMenu()
{ {
return array( return array(
'Список курсов' => '/school/courses-admin/manage', 'Список курсов' => '/school/courses-admin/manage',
......
<?php
namespace common\modules\school\components;
class Utilities
{
public static function checkurl($url) {
// режем левые символы и крайние пробелы
$url=trim($url);
// если пусто - выход
if (strlen($url)==0) return 1;
//проверяем УРЛ на правильность
if (!preg_match("~^(?:(?:https?|ftp|telnet)://(?:[a-z0-9_-]{1,32}".
"(?::[a-z0-9_-]{1,32})?@)?)?(?:(?:[a-z0-9-]{1,128}\.)+(?:com|net|".
"org|mil|edu|arpa|gov|biz|info|aero|inc|name|[a-z]{2})|(?!0)(?:(?".
"!0[^.]|255)[0-9]{1,3}\.){3}(?!0|255)[0-9]{1,3})(?:/[a-z0-9.,_@%&".
"?+=\~/-]*)?(?:#[^ '\"&<>]*)?$~i",$url,$ok))
return -1; // если не правильно - выход
// если нет протокала - добавить
if (!strstr($url,"://")) $url="http://".$url;
// заменить протокол на нижний регистр: hTtP -> http
$url=preg_replace("~^[a-z]+~ie","strtolower('\\0')",$url);
return $url;
}
}
\ No newline at end of file
...@@ -4,7 +4,9 @@ namespace common\modules\school\controllers; ...@@ -4,7 +4,9 @@ namespace common\modules\school\controllers;
use common\components\BaseController; use common\components\BaseController;
use common\modules\school\models\Courses;
use common\modules\school\models\SearchCourses; use common\modules\school\models\SearchCourses;
use common\modules\school\models\SearchLessons;
class CourseController extends BaseController class CourseController extends BaseController
{ {
...@@ -18,15 +20,20 @@ class CourseController extends BaseController ...@@ -18,15 +20,20 @@ class CourseController extends BaseController
public function actionIndex() public function actionIndex()
{ {
$searchModel = new SearchCourses(); $searchModel = new SearchCourses();
$search = \Yii::$app->request->queryParams; $search = \Yii::$app->request->queryParams;
$dataProvider = $searchModel->search($search); $dataProvider = $searchModel->search($search);
return $this->render('index', ['dataProvider' => $dataProvider]); return $this->render('index', ['dataProvider' => $dataProvider]);
} }
public function actionView() public function actionView($id)
{ {
return $this->render('view'); $model = Courses::findOne($id);
$searchModel = new SearchLessons();
$search['course_id'] = $id;
$dataProvider = $searchModel->search($search);
return $this->render('view', ['dataProvider' => $dataProvider, 'model' => $model]);
} }
} }
...@@ -36,32 +36,32 @@ class CoursesAdminController extends AdminController ...@@ -36,32 +36,32 @@ class CoursesAdminController extends AdminController
]; ];
} }
public function actionView($id) public function actionView($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
Yii::$app->controller->page_title = 'Просмотр курса'; Yii::$app->controller->page_title = 'Просмотр курса';
Yii::$app->controller->breadcrumbs = [ Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'], ['Список курсов' => '/school/courses-admin/manage'],
'Добавить курс' 'Добавить курс'
]; ];
return $this->render('view', [ return $this->render('view', [
'model' => $model, 'model' => $model,
]); ]);
} }
public function actionCreate() public function actionCreate()
{ {
$model = new Courses; $model = new Courses;
Yii::$app->controller->page_title = 'Добавить курс'; Yii::$app->controller->page_title = 'Добавить курс';
Yii::$app->controller->breadcrumbs = [ Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'], ['Список курсов' => '/school/courses-admin/manage'],
'Добавить курс' 'Добавить курс'
]; ];
if($model->load(Yii::$app->request->post())){ if($model->load(Yii::$app->request->post()) && $model->validate()){
//Try to get file info //Try to get file info
$model->upload_image = \yii\web\UploadedFile::getInstance($model, 'upload_image'); $model->upload_image = \yii\web\UploadedFile::getInstance($model, 'upload_image');
//If received, then I get the file name and asign it to $model->image in order to store it in db //If received, then I get the file name and asign it to $model->image in order to store it in db
...@@ -69,16 +69,14 @@ class CoursesAdminController extends AdminController ...@@ -69,16 +69,14 @@ class CoursesAdminController extends AdminController
$image_name = $model->upload_image->name; $image_name = $model->upload_image->name;
$model->image = $image_name; $model->image = $image_name;
} }
$model->save();
//I proceed to validate model. Notice that will validate that 'image' is required and also 'image_upload' as file, but this last is optional //If all went OK, then I proceed to save the image in filesystem
if ($model->validate() && $model->save()) { if(!empty($model->upload_image)){
$model->upload_image->saveAs($model->getPath().$image_name);
//If all went OK, then I proceed to save the image in filesystem
if(!empty($model->upload_image)){
$model->upload_image->saveAs($model->getPath().$image_name);
}
return $this->redirect(['view', 'id' => $model->id]);
} }
return $this->redirect(['view', 'id' => $model->id]);
} }
else else
{ {
...@@ -88,18 +86,18 @@ class CoursesAdminController extends AdminController ...@@ -88,18 +86,18 @@ class CoursesAdminController extends AdminController
'form' => $form->out 'form' => $form->out
]); ]);
} }
} }
public function actionUpdate($id) public function actionUpdate($id)
{ {
Yii::$app->controller->page_title = 'Редактировать курс'; Yii::$app->controller->page_title = 'Редактировать курс';
Yii::$app->controller->breadcrumbs = [ Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'], ['Список курсов' => '/school/courses-admin/manage'],
'Редактировать курс' 'Редактировать курс'
]; ];
$model = $this->findModel($id); $model = $this->findModel($id);
if($model->load(Yii::$app->request->post())){ if($model->load(Yii::$app->request->post()) && $model->validate()){
//Try to get file info //Try to get file info
$model->upload_image = \yii\web\UploadedFile::getInstance($model, 'upload_image'); $model->upload_image = \yii\web\UploadedFile::getInstance($model, 'upload_image');
...@@ -109,15 +107,13 @@ class CoursesAdminController extends AdminController ...@@ -109,15 +107,13 @@ class CoursesAdminController extends AdminController
$model->image = $image_name; $model->image = $image_name;
} }
//I proceed to validate model. Notice that will validate that 'image' is required and also 'image_upload' as file, but this last is optional $model->save();
if ($model->validate() && $model->save()) {
//If all went OK, then I proceed to save the image in filesystem //If all went OK, then I proceed to save the image in filesystem
if(!empty($model->upload_image)){ if(!empty($model->upload_image)){
$model->upload_image->saveAs($model->getPath().$image_name); $model->upload_image->saveAs($model->getPath().$image_name);
}
return $this->redirect(['view', 'id' => $model->id]);
} }
return $this->redirect(['view', 'id' => $model->id]);
} }
else else
{ {
...@@ -127,25 +123,26 @@ class CoursesAdminController extends AdminController ...@@ -127,25 +123,26 @@ class CoursesAdminController extends AdminController
'form' => $form->out 'form' => $form->out
]); ]);
} }
} }
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect(['manage']); return $this->redirect(['manage']);
} }
public function actionManage()
public function actionManage()
{ {
$searchModel = new SearchCourses(); $searchModel = new SearchCourses();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams["SearchCourses"]);
\yii::$app->controller->page_title = 'Управление курсами'; \yii::$app->controller->page_title = 'Управление курсами';
\yii::$app->controller->breadcrumbs = [ \yii::$app->controller->breadcrumbs = [
'Управление курсами', 'Управление курсами',
]; ];
return $this->render('manage', [ return $this->render('manage', [
...@@ -154,7 +151,7 @@ class CoursesAdminController extends AdminController ...@@ -154,7 +151,7 @@ class CoursesAdminController extends AdminController
]); ]);
} }
/** /**
* Finds the Faq model based on its primary key value. * Finds the Faq model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id * @param integer $id
...@@ -171,9 +168,9 @@ class CoursesAdminController extends AdminController ...@@ -171,9 +168,9 @@ class CoursesAdminController extends AdminController
} }
public function actionUpload() public function actionUpload()
{ {
$model = new Courses; $model = new Courses;
if (empty($_FILES['Courses'])) { if (empty($_FILES['Courses'])) {
echo json_encode(['error'=>'No files found for upload.']); echo json_encode(['error'=>'No files found for upload.']);
// or you can throw an exception // or you can throw an exception
return; // terminate return; // terminate
...@@ -215,5 +212,5 @@ class CoursesAdminController extends AdminController ...@@ -215,5 +212,5 @@ class CoursesAdminController extends AdminController
// return a json encoded response for plugin to process successfully // return a json encoded response for plugin to process successfully
echo json_encode($output); echo json_encode($output);
} }
} }
...@@ -4,6 +4,8 @@ namespace common\modules\school\controllers; ...@@ -4,6 +4,8 @@ namespace common\modules\school\controllers;
use common\components\BaseController; use common\components\BaseController;
use common\modules\school\models\Lessons;
class LessonController extends BaseController class LessonController extends BaseController
{ {
public static function actionsTitles() public static function actionsTitles()
...@@ -13,8 +15,9 @@ class LessonController extends BaseController ...@@ -13,8 +15,9 @@ class LessonController extends BaseController
]; ];
} }
public function actionView() public function actionView($id)
{ {
return $this->render('view'); $model = Lessons::findOne($id);
return $this->render('view', ['model' => $model]);
} }
} }
...@@ -35,25 +35,25 @@ class LessonsAdminController extends AdminController ...@@ -35,25 +35,25 @@ class LessonsAdminController extends AdminController
]; ];
} }
public function actionView($id) public function actionView($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
Yii::$app->controller->page_title = 'Просмотр урока'; Yii::$app->controller->page_title = 'Просмотр урока';
Yii::$app->controller->breadcrumbs = [ Yii::$app->controller->breadcrumbs = [
['Список уроков' => '/school/courses-admin/manage'], ['Список уроков' => '/school/courses-admin/manage'],
'Добавить урок' 'Добавить урок'
]; ];
return $this->render('view', [ return $this->render('view', [
'model' => $model, 'model' => $model,
]); ]);
} }
public function actionCreate() public function actionCreate()
{ {
$model = new Lessons; $model = new Lessons;
Yii::$app->controller->page_title = 'Добавить урок'; Yii::$app->controller->page_title = 'Добавить урок';
Yii::$app->controller->breadcrumbs = [ Yii::$app->controller->breadcrumbs = [
...@@ -72,11 +72,11 @@ class LessonsAdminController extends AdminController ...@@ -72,11 +72,11 @@ class LessonsAdminController extends AdminController
'form' => $form->out 'form' => $form->out
]); ]);
} }
} }
public function actionUpdate($id) public function actionUpdate($id)
{ {
Yii::$app->controller->page_title = 'Редактировать урок'; Yii::$app->controller->page_title = 'Редактировать урок';
Yii::$app->controller->breadcrumbs = [ Yii::$app->controller->breadcrumbs = [
['Список уроков' => '/school/courses-admin/manage'], ['Список уроков' => '/school/courses-admin/manage'],
'Редактировать урок' 'Редактировать урок'
...@@ -94,26 +94,25 @@ class LessonsAdminController extends AdminController ...@@ -94,26 +94,25 @@ class LessonsAdminController extends AdminController
'form' => $form->out 'form' => $form->out
]); ]);
} }
} }
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect(['manage']); return $this->redirect(['manage']);
} }
public function actionManage() public function actionManage()
{ {
$searchModel = new SearchLessons(); $searchModel = new SearchLessons();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams["SearchLessons"]);
\yii::$app->controller->page_title = 'Управление уроками'; \yii::$app->controller->page_title = 'Управление уроками';
\yii::$app->controller->breadcrumbs = [
'Управление уроками',
];
\yii::$app->controller->breadcrumbs = [
'Управление уроками',
];
return $this->render('manage', [ return $this->render('manage', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
...@@ -121,7 +120,7 @@ class LessonsAdminController extends AdminController ...@@ -121,7 +120,7 @@ class LessonsAdminController extends AdminController
]); ]);
} }
/** /**
* Finds the Faq model based on its primary key value. * Finds the Faq model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id * @param integer $id
......
...@@ -31,11 +31,12 @@ else { ...@@ -31,11 +31,12 @@ else {
$elements = [ $elements = [
'title' => ['type' => 'text'], 'title' => ['type' => 'text'],
'description' => ['type' => 'textarea'], 'description' => ['type' => 'textarea'],
'type' => [ 'description_for_course' => ['type' => 'textarea'],
'type' => 'dropdownlist', 'type' => [
'items' => Courses::$type_list, 'type' => 'dropdownlist',
], 'items' => Courses::$type_list,
],
'spec_proposition' => ['type' => 'checkbox'], 'spec_proposition' => ['type' => 'checkbox'],
'image' => $image, 'image' => $image,
]; ];
......
...@@ -6,11 +6,12 @@ use common\modules\school\models\Courses; ...@@ -6,11 +6,12 @@ use common\modules\school\models\Courses;
$elements = [ $elements = [
'title' => ['type' => 'text'], 'title' => ['type' => 'text'],
'video_id' => ['type' => 'text'], 'video_id' => ['type' => 'text'],
'text' => ['type' => 'textarea'], 'text' => ['type' => 'textarea'],
'course_id' => [ 'course_id' => [
'type' => 'dropdownlist', 'type' => 'dropdownlist',
'items' => ArrayHelper::map(Courses::find()->all(), 'id', 'title'), 'items' => ArrayHelper::map(Courses::find()->all(), 'id', 'title'),
], ],
'number' => ['type' => 'text'],
]; ];
return [ return [
......
...@@ -10,58 +10,59 @@ class Courses extends \common\components\ActiveRecordModel ...@@ -10,58 +10,59 @@ class Courses extends \common\components\ActiveRecordModel
{ {
const PAGE_SIZE = 10; const PAGE_SIZE = 10;
const TYPE_IT = 1; const TYPE_IT = 1;
const TYPE_IM = 2; const TYPE_IM = 2;
const TYPE_SB = 3; const TYPE_SB = 3;
const TYPE_DV = 4; const TYPE_DV = 4;
const IMAGES_FOLDER = '/uploads/courses/'; const IMAGES_FOLDER = '/uploads/courses/';
public $upload_image; public $upload_image;
public static $type_list = [ public static $type_list = [
self::TYPE_IT => 'Для сотрудников it-отрасли', self::TYPE_IT => 'Для сотрудников it-отрасли',
self::TYPE_IM => 'Для интернет-маркетологов', self::TYPE_IM => 'Для интернет-маркетологов',
self::TYPE_SB => 'Для собственников бизнеса', self::TYPE_SB => 'Для собственников бизнеса',
self::TYPE_DV => 'в разработке', self::TYPE_DV => 'в разработке',
]; ];
public static function tableName() public static function tableName()
{ {
return 'courses'; return 'courses';
} }
public function name() public function name()
{ {
return 'Курсы'; return 'Курсы';
} }
public function attributeLabels() public function attributeLabels()
{ {
return [ return [
'title' => 'Заголовок', 'title' => 'Заголовок',
'description' => 'Описание', 'description' => 'Описание',
'type' => 'Тип курса', 'type' => 'Тип курса',
'upload_image' => 'Изображения', 'upload_image' => 'Изображения',
'spec_proposition' => 'Специальное предложение' 'spec_proposition' => 'Специальное предложение',
]; 'description_for_course' => 'Описание для страницы курса'
} ];
}
/**
/**
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
[['title', 'description', 'type'], 'required'], [['title', 'description', 'type'], 'required'],
[['type', 'spec_proposition'], 'integer', 'max' => 11], [['type', 'spec_proposition'], 'integer', 'max' => 11],
[['title'], 'string', 'max' => 150], [['title'], 'string', 'max' => 150],
[['image'], 'string', 'max' => 100], [['image'], 'string', 'max' => 100],
[['description'], 'safe'], [['description', 'description_for_course'], 'safe'],
[['upload_image'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'], [['upload_image'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
]; ];
} }
/** /**
* @inheritdoc * @inheritdoc
...@@ -74,52 +75,50 @@ class Courses extends \common\components\ActiveRecordModel ...@@ -74,52 +75,50 @@ class Courses extends \common\components\ActiveRecordModel
} }
public function beforeDelete() public function beforeDelete()
{ {
if (parent::beforeDelete()) if (parent::beforeDelete())
{ {
$this->deleteFiles(); $this->deleteFiles();
return true; return true;
} }
else else
{ {
return false; return false;
} }
} }
public function getLessons() public function getLessons()
{ {
return $this->hasMany(Lessons::className(), ['course_id' => 'id']); return $this->hasMany(Lessons::className(), ['course_id' => 'id']);
} }
public function getPath() public function getPath()
{ {
return Yii::getAlias('@frontend/web') . self::IMAGES_FOLDER; return Yii::getAlias('@frontend/web') . self::IMAGES_FOLDER;
} }
public function getUrl($image) public function getUrl($image)
{ {
return Yii::$app->params['frontUrl'].self::IMAGES_FOLDER.$image; return Yii::$app->params['frontUrl'].self::IMAGES_FOLDER.$image;
} }
public function deleteFiles() public function deleteFiles()
{ {
if($this->image) if($this->image){
{ if(file_exists($this->getPath() . $this->image)){
if(file_exists($this->getPath() . $this->image))
{
unlink($this->getPath() . $this->image); unlink($this->getPath() . $this->image);
} }
} }
} }
public function getClassCourse($type) public function getClassCourse($type)
{ {
switch ($type) { switch ($type) {
case Courses::TYPE_IT: $class = 'it'; break; case Courses::TYPE_IT: $class = 'it'; break;
case Courses::TYPE_IM: $class = 'im'; break; case Courses::TYPE_IM: $class = 'im'; break;
case Courses::TYPE_SB: $class = 'sb'; break; case Courses::TYPE_SB: $class = 'sb'; break;
case Courses::TYPE_DV: $class = 'dv'; break; case Courses::TYPE_DV: $class = 'dv'; break;
} }
return $class; return $class;
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace common\modules\school\models; namespace common\modules\school\models;
use Yii; use common\modules\school\components\Utilities;
use common\modules\school\models\Courses; use common\modules\school\models\Courses;
...@@ -34,15 +34,15 @@ class Lessons extends \common\components\ActiveRecordModel ...@@ -34,15 +34,15 @@ class Lessons extends \common\components\ActiveRecordModel
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
[['title', 'text', 'video_id', 'course_id'], 'required'], [['title', 'video_id', 'course_id', 'number'], 'required'],
[['title'], 'string', 'max' => 150], [['title'], 'string', 'max' => 150],
[['video_id'], 'string', 'max' => 100], [['video_id'], 'string', 'max' => 100],
[['course_id'], 'integer', 'max' => 11], [['course_id', 'number'], 'integer', 'max' => 11],
[['text'], 'safe'], [['text'], 'safe'],
]; ];
} }
/** /**
* @inheritdoc * @inheritdoc
...@@ -52,9 +52,10 @@ class Lessons extends \common\components\ActiveRecordModel ...@@ -52,9 +52,10 @@ class Lessons extends \common\components\ActiveRecordModel
return [ return [
'id' => 'ID', 'id' => 'ID',
'title' => 'Заголовок', 'title' => 'Заголовок',
'text' => 'Текст', 'text' => 'Полезные материалы',
'video_id' => 'Код видео', 'video_id' => 'Код видео',
'course_id' => 'Курс', 'course_id' => 'Курс',
'number' => 'Номер урока',
]; ];
} }
...@@ -71,4 +72,31 @@ class Lessons extends \common\components\ActiveRecordModel ...@@ -71,4 +72,31 @@ class Lessons extends \common\components\ActiveRecordModel
{ {
return $this->hasOne(Courses::className(), ['id' => 'course_id']); return $this->hasOne(Courses::className(), ['id' => 'course_id']);
} }
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->video_id = $this->getVideoId();
return $this->video_id;
}
else {
return false;
}
}
public function getVideoId()
{
if ($this->video_id) {
if (Utilities::checkUrl($this->video_id)) {
if (strrpos($this->video_id, '=')){
$this->video_id=substr($this->video_id, strrpos($this->video_id, '=')+1);
}
}
return $this->video_id;
}
else {
return false;
}
}
} }
...@@ -42,19 +42,20 @@ class SearchCourses extends Courses ...@@ -42,19 +42,20 @@ class SearchCourses extends Courses
*/ */
public function search($params) public function search($params)
{ {
$query = Courses::find(); if ($params){
$params = array_filter($params);
$dataProvider = new ActiveDataProvider([ $query = Courses::findByCondition($params);
'query' => $query, }
]); else {
$query = Courses::find();
}
$this->load($params); $this->load($params);
/*if (!$this->validate()) {
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails // uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1'); // $query->where('0=1');
return $dataProvider; return $dataProvider;
} }*/
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,
...@@ -65,6 +66,11 @@ class SearchCourses extends Courses ...@@ -65,6 +66,11 @@ class SearchCourses extends Courses
->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'image', $this->image]); ->andFilterWhere(['like', 'image', $this->image]);
$query->orderBy(['id' => SORT_DESC]); $query->orderBy(['id' => SORT_DESC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $dataProvider; return $dataProvider;
} }
} }
...@@ -18,7 +18,7 @@ class SearchLessons extends Lessons ...@@ -18,7 +18,7 @@ class SearchLessons extends Lessons
public function rules() public function rules()
{ {
return [ return [
[['id', 'course_id'], 'integer'], [['id', 'course_id', 'number'], 'integer'],
[['video_id', 'title'], 'safe'], [['video_id', 'title'], 'safe'],
]; ];
} }
...@@ -41,27 +41,32 @@ class SearchLessons extends Lessons ...@@ -41,27 +41,32 @@ class SearchLessons extends Lessons
*/ */
public function search($params) public function search($params)
{ {
$query = Lessons::find(); if ($params){
$params = array_filter($params);
$dataProvider = new ActiveDataProvider([ $query = Lessons::findByCondition($params);
'query' => $query, }
]); else {
$query = Lessons::find();
}
$this->load($params); $this->load($params);
/*if (!$this->validate()) {
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails // uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1'); // $query->where('0=1');
return $dataProvider; return $dataProvider;
} }*/
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,
'course_id' => $this->course_id, 'course_id' => $this->course_id,
'number' => $this->number,
]); ]);
$query->andFilterWhere(['like', 'video_id', $this->video_id]) $query->andFilterWhere(['like', 'video_id', $this->video_id])
->andFilterWhere(['like', 'title', $this->title]); ->andFilterWhere(['like', 'title', $this->title]);
$query->orderBy(['id' => SORT_ASC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $dataProvider; return $dataProvider;
} }
......
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
<?php echo \yii\widgets\ListView::widget( [ <?php echo \yii\widgets\ListView::widget( [
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'itemView' => 'item-view', 'itemView' => 'item-view',
'itemOptions' => ['tag' => ''], 'itemOptions' => ['tag' => 'div'],
'options' => ['tag' => ''], 'options' => ['tag' => 'div'],
'emptyTextOptions' => [ 'tag' => 'div', 'class' => 'empty-text' ],
'layout' => '{items}<li><nav class="pages">{pager}</nav></li>', 'layout' => '{items}<li><nav class="pages">{pager}</nav></li>',
'pager' => [ 'pager' => [
'class' => 'common\components\zii\FrontLinkPager', 'class' => 'common\components\zii\FrontLinkPager',
......
<?php
use yii\helpers\Url;
?>
<div class="col-md-3 col-xs-6 col-sm-12">
<div class="ls_block_item">
<div class="line_ls">Урок <?php echo $model->number;?></div>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => $model->id]);?>" class="ls_block_title">
<?php echo $model->title;?>
</a>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => $model->id]);?>" class="ls_block_btn">
Смотреть
</a>
</div>
</div>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<div class="blip_kurs">За просмотр этих курсов<br> мы заплатим 15 000 руб.</div> <div class="blip_kurs">За просмотр этих курсов<br> мы заплатим 15 000 руб.</div>
<?php endif;?> <?php endif;?>
<div class="kurs_foot clearfix"> <div class="kurs_foot clearfix">
<a href="<?php echo Url::toRoute(['/school/course/view', 'id' => 1]);?>" class="kurs_bt">Подробнее</a> <a href="<?php echo Url::toRoute(['/school/course/view', 'id' => $model->id]);?>" class="kurs_bt">Подробнее</a>
</div> </div>
<div class="for_<?php echo $model->getClassCourse($model->type);?>"> <div class="for_<?php echo $model->getClassCourse($model->type);?>">
<div class="r_<?php echo $model->getClassCourse($model->type);?>"></div> <div class="r_<?php echo $model->getClassCourse($model->type);?>"></div>
......
...@@ -19,18 +19,16 @@ ...@@ -19,18 +19,16 @@
</div> </div>
</div> </div>
</section> </section>
<section class="les_list_top"> <section class="les_list_top" style="background: url(<?php echo $model->getUrl($model->image);?>) no-repeat center center">
<div class="ls_top_over"> <div class="ls_top_over">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-12 col-xs-12 col-sm-12"> <div class="col-md-12 col-xs-12 col-sm-12">
<h1 class="ls_title"> <h1 class="ls_title">
<span>Курс для менеджеров it-отрасли</span> <span><?php echo $model->title;?></span>
</h1> </h1>
<div class="ls_subtitle"> <div class="ls_subtitle">
<span>Если вы менеджер it отрасли или генеральный директоров в сфере</span> <?php echo $model->description_for_course;?>
<br>
<span>it отрасли, то вам будет полезно посмотреть этот учебный курс.</span>
</div> </div>
<br> <br>
<div class="ls_txt"><span>В роликах будет рассказываться:</span></div> <div class="ls_txt"><span>В роликах будет рассказываться:</span></div>
...@@ -43,44 +41,27 @@ ...@@ -43,44 +41,27 @@
<section class="ls_list_block"> <section class="ls_list_block">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-3 col-xs-6 col-sm-12">
<div class="ls_block_item"> <?php echo \yii\widgets\ListView::widget( [
<div class="line_ls">Урок 1</div> 'dataProvider' => $dataProvider,
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_title">Как правильно принимать задачи от заказчика</a> 'itemView' => 'item-view-lesson',
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_btn">Смотреть</a> 'itemOptions' => ['tag' => 'div'],
</div> 'options' => ['tag' => 'div'],
</div> 'emptyTextOptions' => [ 'tag' => 'div', 'class' => 'empty-text' ],
<div class="col-md-3 col-xs-6 col-sm-12"> 'layout' => '{items}<li><nav class="pages">{pager}</nav></li>',
<div class="ls_block_item"> 'pager' => [
<div class="line_ls">Урок 99</div> 'class' => 'common\components\zii\FrontLinkPager',
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_title">Как правильно ставить задачу исполнителям</a> 'activePageCssClass' => 'is-active',
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_btn">Смотреть</a> 'prevPageLabel' => '<span class="glyphicon glyphicon-chevron-left"></span>Предыдущая',
</div> 'nextPageLabel' => 'Следующая<span class="glyphicon glyphicon-chevron-right"></span>',
</div> 'options' => [
<div class="col-md-3 col-xs-6 col-sm-12"> 'class' => 'pages-list',
<div class="ls_block_item ls_fine"> ],
<div class="line_ls">Урок 3</div> ],
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_title">Как правильно выстроить взаимоотношения с заказчиком</a> ] );
<div class="ls_fine_txt">Урок просмотрен</div> ?>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_btn">Продолжить</a>
</div>
</div>
<div class="col-md-3 col-xs-6 col-sm-12">
<div class="ls_block_item">
<div class="line_ls">Урок 4</div>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_title">Как научиться изменять стоимость проекта</a>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_btn">Смотреть</a>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-md-3 col-xs-6 col-sm-12">
<div class="ls_block_item">
<div class="line_ls">Урок 2</div>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_title">Как работать с материалом</a>
<a href="<?php echo Url::toRoute(['/school/lesson/view', 'id' => 1]);?>" class="ls_block_btn">Смотреть</a>
</div>
</div>
<div class="col-md-3 col-xs-6 col-sm-12"> <div class="col-md-3 col-xs-6 col-sm-12">
<div class="ls_likes"> <div class="ls_likes">
<div class="ls_likes_title">Нравится курс?</div> <div class="ls_likes_title">Нравится курс?</div>
......
...@@ -25,12 +25,12 @@ use common\modules\school\models\Courses; ...@@ -25,12 +25,12 @@ use common\modules\school\models\Courses;
'filter' => Courses::$type_list, 'filter' => Courses::$type_list,
'value' => function($model) 'value' => function($model)
{ {
return Courses::$type_list[$model->type]; return Courses::$type_list[$model->type];
} }
], ],
[ [
'class' => 'common\components\ColorActionColumn', 'class' => 'common\components\ColorActionColumn',
'template' => '{view} {update}', 'template' => '{view} {update}',
], ],
], ],
]); ?> ]); ?>
\ No newline at end of file
...@@ -25,12 +25,12 @@ use common\modules\school\models\Courses; ...@@ -25,12 +25,12 @@ use common\modules\school\models\Courses;
<?= DetailView::widget([ <?= DetailView::widget([
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
'title', 'title',
'description', 'description',
[ [
'attribute' => 'type', 'attribute' => 'type',
'value' => Courses::$type_list[$model->type], 'value' => Courses::$type_list[$model->type],
], ],
], ],
]) ?> ]) ?>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-8 col-xs-8 col-sm-12"> <div class="col-md-8 col-xs-8 col-sm-12">
<h1 class="vc-title">Урок 1. Курс для менеджеров it-отрасли вторая строка</h1> <h1 class="vc-title">Урок <?php echo $model->number;?>. <?php echo $model->title;?></h1>
</div> </div>
<div class="col-md-3 col-md-offset-1 col-xs-4 col-sm-12"> <div class="col-md-3 col-md-offset-1 col-xs-4 col-sm-12">
<ul class="sh_social"> <ul class="sh_social">
...@@ -36,11 +36,16 @@ ...@@ -36,11 +36,16 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-12 col-xs-12 col-sm-12"> <div class="col-md-12 col-xs-12 col-sm-12">
<div class="ytb_video"> <div class="ytb_video">
<img src="/images/ytb_video.jpg" height="508" width="903" alt=""> <iframe width="903" height="508" src="https://www.youtube.com/embed/<?php echo $model->video_id ?>" frameborder="0" allowfullscreen></iframe>
</div> </div>
<div class="vc-subtitle">Оставляйте комментарии и проходите тестирование, что бы <span>получить приз 15 000 руб.</span></div>
<a href="#" class="vc-uslovia">Подробные условия конкурса</a> <?php if($model->course->spec_proposition):?>
<div class="vc-subtitle">Оставляйте комментарии и проходите тестирование, что бы <span>получить приз 15 000 руб.</span></div>
<a href="#" class="vc-uslovia">Подробные условия конкурса</a>
<?php endif;?>
</div> </div>
</div> </div>
</div> </div>
...@@ -62,62 +67,16 @@ ...@@ -62,62 +67,16 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-12 col-xs-12 col-sm-12"> <?php if($model->text):?>
<h2>Полезные материалы</h2> <div class="row">
</div> <div class="col-md-12 col-xs-12 col-sm-12">
</div> <h2>Полезные материалы</h2>
<div class="row">
<div class="col-md-12 col-xs-12 col-sm-12">
<strong>“Пессимист - тот, кто жалуется на шум, когда стучит возможность”</strong>
<p>Сервис для закрепления и защиты своих проектов по поставке или внедрению продукции и решений Schneider Electric. Поставщики регистрируют проекты и предоставляют по ним ключевую информацию. Если проект будет защищен, в системе, то другой поставщик не сможет его выполнить.<br> Разработанный сервис позволяет пользователям, через личный кабинет, вносить <a href="#">заявки</a> на будущие проекты </p>
<p><img src="/images/test_img.jpg" height="145" width="230"> Сервис для закрепления и защиты своих проектов по поставке или внедрению продукции и решений Schneider Electric. Поставщики регистрируют проекты и предоставляют по ним ключевую информацию. Если проект будет защищен, в системе, то другой поставщик не сможет его выполнить.<br> Разработанный сервис позволяет пользователям, через личный кабинет, вносить заявки на будущие проекты и вести учет всех поданных ранее заявок.</p>
<p>Сервис для закрепления и защиты своих проектов по поставке или внедрению продукции и решений Schneider Electric. Поставщики регистрируют проекты и предоставляют по ним ключевую информацию. Если проект будет защищен, в системе, то другой поставщик не сможет его выполнить.</p>
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-6 col-sm-12">
<ol class="ol_list">
<li>Защита соединения TLS и/или SSL протоколом</li>
<li>Защита данных шифрованием</li>
<li>Двухфакторная аутентификация</li>
<li>Подтверждение операции по SMS или ЭЦП</li>
</ol>
</div>
<div class="col-md-6 col-xs-6 col-sm-12">
<ul class="ul_list">
<li>Защита соединения TLS и/или SSL протоколом</li>
<li>Защита данных шифрованием</li>
<li>Двухфакторная аутентификация</li>
<li>Подтверждение операции по SMS или ЭЦП</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12 col-xs-12 col-sm-12">
<div class="tb_vp">
<table width="940px">
<thead height="60px">
<tr>
<th width="310px">Тип взаимодействия с<br> заказчиком</th>
<th width="230px">Плюсы</th>
<th>Минусы</th>
</tr>
</thead>
<tbody><tr>
<th>Заказчик работает на прямую<br> с исполнителем</th>
<th>Вы экономите на менеджменте<br> Задачи выполняются быстрее</th>
<th>Есть риск увода специалиста<br> Нет защиты от негатива заказчика.<br> Сложнее предлагать новые услуги<br> Задачи выполняются не полностью, т.к. нет эксперта, кторый может корректно формулировать задачу</th>
</tr>
<tr>
<th>Заказчик работает на прямую<br> с исполнителем</th>
<th>Вы экономите на менеджменте<br> Задачи выполняются быстрее</th>
<th>Есть риск увода специалиста<br> Нет защиты от негатива заказчика.<br> Сложнее предлагать новые услуги<br> Задачи выполняются не полностью, т.к. нет эксперта, кторый может корректно формулировать задачу</th>
</tr>
</tbody></table>
</div> </div>
</div> </div>
</div> <?php echo $model->text;?>
<?php endif;?>
<div class="row"> <div class="row">
<div class="col-md-6 col-xs-6 col-sm-12"> <div class="col-md-6 col-xs-6 col-sm-12">
<i class="ai_format"></i> <i class="ai_format"></i>
......
...@@ -21,21 +21,29 @@ use common\modules\school\models\Courses; ...@@ -21,21 +21,29 @@ use common\modules\school\models\Courses;
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'columns' => [ 'columns' => [
'title', 'title',
'video_id', [
'attribute' => 'video_id',
'filter' => false,
'value' => function($model)
{
return $model->video_id;
}
],
[ [
'attribute' => 'course_id', 'attribute' => 'course_id',
'filter' => Html::dropDownList('SearchCourses[course_id]', 'filter' => Html::dropDownList('SearchLessons[course_id]',
$searchModel->course_id, $searchModel->course_id,
ArrayHelper::map(Courses::find()->all(),'id','title'), ArrayHelper::map(Courses::find()->all(),'id','title'),
['class'=>'form-control','prompt'=>'Курс']), ['class'=>'form-control','prompt'=>'Курс']),
'value' => function($model) 'value' => function($model)
{ {
return $model->course->title; return $model->course->title;
} }
], ],
'number',
[ [
'class' => 'common\components\ColorActionColumn', 'class' => 'common\components\ColorActionColumn',
'template' => '{view} {update}', 'template' => '{view} {update}',
], ],
], ],
]); ?> ]); ?>
\ No newline at end of file
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\DetailView; use yii\widgets\DetailView;
use common\modules\school\models\Courses;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
?> ?>
...@@ -25,16 +23,13 @@ use common\modules\school\models\Courses; ...@@ -25,16 +23,13 @@ use common\modules\school\models\Courses;
<?= DetailView::widget([ <?= DetailView::widget([
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
'title', 'title',
'video_id', 'video_id',
[ [
'attribute' => 'course_id', 'attribute' => 'course_id',
'filter' => false, 'value' => $model->course->title,
'value' => function($model)
{
return $model->course->title;
}
], ],
'number',
], ],
]) ?> ]) ?>
......
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160202_205332_add_field_to_lessons_table extends Migration
{
public function safeUp()
{
$this->addColumn('lessons', 'number', Schema::TYPE_INTEGER . '(11) NOT NULL');
}
public function safeDown()
{
$this->dropColumn('lessons', 'number');
}
}
<?php
use yii\db\Migration;
use yii\db\Schema;
class m160202_215135_add_field_to_courses_table extends Migration
{
public function safeUp()
{
$this->addColumn('courses', 'description_for_course', Schema::TYPE_TEXT . ' NOT NULL');
}
public function safeDown()
{
$this->dropColumn('courses', 'description_for_course');
}
}
...@@ -9578,7 +9578,7 @@ thead tr th { ...@@ -9578,7 +9578,7 @@ thead tr th {
} }
.les_list_top { .les_list_top {
background: url(../images/les_top_bg.jpg) no-repeat center center; /*background: url(../images/les_top_bg.jpg) no-repeat center center;*/
width: 100%; width: 100%;
height: 377px; height: 377px;
background-size: cover; background-size: cover;
...@@ -11453,3 +11453,9 @@ h6 { ...@@ -11453,3 +11453,9 @@ h6 {
margin-top: 30px; margin-top: 30px;
} }
} }
.empty-text{
margin-bottom: 30px;
}
.row li{
list-style: none;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment