Course administration panel

parent 59f3382b
<?php
$menu = \common\components\AppManager::getAdminMenu();
?>
<!-- begin sidebar nav -->
<ul class="nav">
......
......@@ -116,4 +116,7 @@ a.desc:after {
.advanced-filter input[type="date"] {
width: 145px;
}
.file-widget{
margin-bottom: 20px;
}
\ No newline at end of file
......@@ -6314,4 +6314,4 @@ body.flat-black {
}
.profile-section .title small {
font-weight: normal;
}
\ No newline at end of file
}
Test
\ No newline at end of file
......@@ -9,10 +9,6 @@ class Module extends \common\components\WebModule
public $menu_icons = 'fa fa-comment-o';
public static $active = true;
public static $base_module = true;
public static function name()
{
......@@ -41,7 +37,8 @@ class Module extends \common\components\WebModule
public static function adminMenu()
{
return array(
'Список курсов' => '/school/courses-admin/manage',
'Список уроков' => '/school/lessons-admin/manage',
);
}
}
......@@ -4,6 +4,8 @@ namespace common\modules\school\controllers;
use common\components\BaseController;
use common\modules\school\models\SearchCourses;
class CourseController extends BaseController
{
public static function actionsTitles()
......@@ -16,7 +18,11 @@ class CourseController extends BaseController
public function actionIndex()
{
return $this->render('index');
$searchModel = new SearchCourses();
$search = \Yii::$app->request->queryParams;
$dataProvider = $searchModel->search($search);
return $this->render('index', ['dataProvider' => $dataProvider]);
}
public function actionView()
......
<?php
namespace common\modules\school\controllers;
use Yii;
use common\components\AdminController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\modules\school\models\Courses;
use common\modules\school\models\SearchCourses;
class CoursesAdminController extends AdminController
{
public static function actionsTitles()
{
return array(
'View' => 'Просмотр курса',
'Create' => 'Создание курса',
'Update' => 'Редактирование курса',
'Delete' => 'Удаление курса',
'Manage' => 'Управление курсами',
'Upload' => 'Временное сохранение изображения',
);
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionView($id)
{
$model = $this->findModel($id);
Yii::$app->controller->page_title = 'Просмотр курса';
Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'],
'Добавить курс'
];
return $this->render('view', [
'model' => $model,
]);
}
public function actionCreate()
{
$model = new Courses;
Yii::$app->controller->page_title = 'Добавить курс';
Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'],
'Добавить курс'
];
if($model->load(Yii::$app->request->post())){
//Try to get file info
$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(!empty($model->upload_image)){
$image_name = $model->upload_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
if ($model->validate() && $model->save()) {
//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]);
}
}
else
{
$form = new \common\components\BaseForm('/common/modules/school/forms/CourseForm', $model);
return $this->render('create', [
'model' => $model,
'form' => $form->out
]);
}
}
public function actionUpdate($id)
{
Yii::$app->controller->page_title = 'Редактировать курс';
Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'],
'Редактировать курс'
];
$model = $this->findModel($id);
if($model->load(Yii::$app->request->post())){
//Try to get file info
$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(!empty($model->upload_image)){
$image_name = $model->upload_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
if ($model->validate() && $model->save()) {
//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]);
}
}
else
{
$form = new \common\components\BaseForm('/common/modules/school/forms/CourseForm', $model);
return $this->render('update', [
'model' => $model,
'form' => $form->out
]);
}
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['manage']);
}
public function actionManage()
{
$searchModel = new SearchCourses();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
\yii::$app->controller->page_title = 'Управление курсами';
\yii::$app->controller->breadcrumbs = [
'Управление курсами',
];
return $this->render('manage', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Finds the Faq model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Faq the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Courses::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
public function actionUpload()
{
$model = new Courses;
if (empty($_FILES['Courses'])) {
echo json_encode(['error'=>'No files found for upload.']);
// or you can throw an exception
return; // terminate
}
// get the files posted
$images = $_FILES['Courses'];
$success = null;
// file paths to store
$paths= [];
// get file names
$filename = $images['name']["upload_image"];
// loop and process files
$ext = explode('.', basename($filename));
$target = $model->getPath() . md5(uniqid()) . "." . array_pop($ext);
if(move_uploaded_file($images['tmp_name']["upload_image"], $target)) {
$success = true;
$paths[] = $target;
} else {
$success = false;
break;
}
// check and process based on successful status
if ($success === true) {
$output = [];
} elseif ($success === false) {
$output = ['error'=>'Error while uploading images. Contact the system administrator'];
foreach ($paths as $file) {
unlink($file);
}
} else {
$output = ['error'=>'No files were processed.'];
}
// return a json encoded response for plugin to process successfully
echo json_encode($output);
}
}
<?php
namespace common\modules\school\controllers;
use Yii;
use common\components\AdminController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\modules\school\models\Lessons;
use common\modules\school\models\SearchLessons;
class LessonsAdminController extends AdminController
{
public static function actionsTitles()
{
return array(
'View' => 'Просмотр урока',
'Create' => 'Создание урока',
'Update' => 'Редактирование урока',
'Delete' => 'Удаление урока',
'Manage' => 'Управление уроками',
);
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionView($id)
{
$model = $this->findModel($id);
Yii::$app->controller->page_title = 'Просмотр урока';
Yii::$app->controller->breadcrumbs = [
['Список уроков' => '/school/courses-admin/manage'],
'Добавить урок'
];
return $this->render('view', [
'model' => $model,
]);
}
public function actionCreate()
{
$model = new Lessons;
Yii::$app->controller->page_title = 'Добавить урок';
Yii::$app->controller->breadcrumbs = [
['Список курсов' => '/school/courses-admin/manage'],
'Добавить урок'
];
if ($model->load(Yii::$app->request->post()) && $model->save()){
return $this->redirect(['manage']);
}
else
{
$form = new \common\components\BaseForm('/common/modules/school/forms/LessonForm', $model);
return $this->render('create', [
'model' => $model,
'form' => $form->out
]);
}
}
public function actionUpdate($id)
{
Yii::$app->controller->page_title = 'Редактировать урок';
Yii::$app->controller->breadcrumbs = [
['Список уроков' => '/school/courses-admin/manage'],
'Редактировать урок'
];
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['manage']);
}
else
{
$form = new \common\components\BaseForm('/common/modules/school/forms/LessonForm', $model);
return $this->render('update', [
'model' => $model,
'form' => $form->out
]);
}
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['manage']);
}
public function actionManage()
{
$searchModel = new SearchLessons();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
\yii::$app->controller->page_title = 'Управление уроками';
\yii::$app->controller->breadcrumbs = [
'Управление уроками',
];
return $this->render('manage', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Finds the Faq model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Faq the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Lessons::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
use yii\helpers\Html;
use kartik\file\FileInput;
use yii\helpers\Url;
use common\modules\school\models\Courses;
if ($model->image) {
$image = "<div class='file-widget'>".FileInput::widget([
'model' => $model,
'attribute' => 'upload_image',
'language' => 'en',
'options' => ['multiple' => false, 'accept' => 'image/*'],
'pluginOptions' => [/*'uploadUrl' => Url::to(['/school/courses-admin/upload']),*/'showUpload' => false,
'initialPreview'=>[
Html::img($model->getUrl($model->image))
],
'overwriteInitial'=>true]
])."</div>";
}
else {
$image = "<div class='file-widget'>".FileInput::widget([
'model' => $model,
'attribute' => 'upload_image',
'language' => 'en',
'options' => ['multiple' => false, 'accept' => 'image/*'],
'pluginOptions' => [/*'uploadUrl' => Url::to(['/school/courses-admin/upload']),*/'showUpload' => false,
'overwriteInitial'=>true]
])."</div>";
}
$elements = [
'title' => ['type' => 'text'],
'description' => ['type' => 'textarea'],
'type' => [
'type' => 'dropdownlist',
'items' => Courses::$type_list,
],
'spec_proposition' => ['type' => 'checkbox'],
'image' => $image,
];
return [
'activeForm'=>[
'id' => 'course-form',
'options' => [
'enctype' => 'multipart/form-data'
],
],
'elements' => $elements,
'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Cохранить']
]
];
<?php
use yii\helpers\ArrayHelper;
use common\modules\school\models\Courses;
$elements = [
'title' => ['type' => 'text'],
'video_id' => ['type' => 'text'],
'text' => ['type' => 'textarea'],
'course_id' => [
'type' => 'dropdownlist',
'items' => ArrayHelper::map(Courses::find()->all(), 'id', 'title'),
],
];
return [
'activeForm'=>[
'id' => 'lesson-form',
],
'elements' => $elements,
'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Cохранить']
]
];
<?php
namespace common\modules\school\models;
use Yii;
use common\modules\school\models\Lessons;
class Courses extends \common\components\ActiveRecordModel
{
const PAGE_SIZE = 10;
const TYPE_IT = 1;
const TYPE_IM = 2;
const TYPE_SB = 3;
const TYPE_DV = 4;
const IMAGES_FOLDER = '/uploads/courses/';
public $upload_image;
public static $type_list = [
self::TYPE_IT => 'Для сотрудников it-отрасли',
self::TYPE_IM => 'Для интернет-маркетологов',
self::TYPE_SB => 'Для собственников бизнеса',
self::TYPE_DV => 'в разработке',
];
public static function tableName()
{
return 'courses';
}
public function name()
{
return 'Курсы';
}
public function attributeLabels()
{
return [
'title' => 'Заголовок',
'description' => 'Описание',
'type' => 'Тип курса',
'upload_image' => 'Изображения',
'spec_proposition' => 'Специальное предложение'
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title', 'description', 'type'], 'required'],
[['type', 'spec_proposition'], 'integer', 'max' => 11],
[['title'], 'string', 'max' => 150],
[['image'], 'string', 'max' => 100],
[['description'], 'safe'],
[['upload_image'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
];
}
public function beforeDelete()
{
if (parent::beforeDelete())
{
$this->deleteFiles();
return true;
}
else
{
return false;
}
}
public function getLessons()
{
return $this->hasMany(Lessons::className(), ['course_id' => 'id']);
}
public function getPath()
{
return Yii::getAlias('@frontend/web') . self::IMAGES_FOLDER;
}
public function getUrl($image)
{
return Yii::$app->params['frontUrl'].self::IMAGES_FOLDER.$image;
}
public function deleteFiles()
{
if($this->image)
{
if(file_exists($this->getPath() . $this->image))
{
unlink($this->getPath() . $this->image);
}
}
}
public function getClassCourse($type)
{
switch ($type) {
case Courses::TYPE_IT: $class = 'it'; break;
case Courses::TYPE_IM: $class = 'im'; break;
case Courses::TYPE_SB: $class = 'sb'; break;
case Courses::TYPE_DV: $class = 'dv'; break;
}
return $class;
}
}
<?php
namespace common\modules\school\models;
use Yii;
use common\modules\school\models\Courses;
/**
* This is the model class for table "testings_questions_image".
*
* @property integer $id
* @property integer $question_id
* @property string $filename
*/
class Lessons extends \common\components\ActiveRecordModel
{
const PAGE_SIZE = 10;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'lessons';
}
public function name()
{
return 'Изображения для вопросов';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title', 'text', 'video_id', 'course_id'], 'required'],
[['title'], 'string', 'max' => 150],
[['video_id'], 'string', 'max' => 100],
[['course_id'], 'integer', 'max' => 11],
[['text'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Заголовок',
'text' => 'Текст',
'video_id' => 'Код видео',
'course_id' => 'Курс',
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
];
}
public function getCourse()
{
return $this->hasOne(Courses::className(), ['id' => 'course_id']);
}
}
<?php
namespace common\modules\school\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\modules\school\models\Courses;
/**
* SearchCourses represents the model behind the search form about `common\modules\Lessons\models\Courses`.
*/
class SearchCourses extends Courses
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'type'], 'integer'],
[['description', 'title', 'image'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Courses::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'type' => $this->type,
]);
$query->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'image', $this->image]);
$query->orderBy(['id' => SORT_DESC]);
return $dataProvider;
}
}
<?php
namespace common\modules\school\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\modules\school\models\Lessons;
/**
* SearchLessons represents the model behind the search form about `common\modules\school\models\Lessons`.
*/
class SearchLessons extends Lessons
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'course_id'], 'integer'],
[['video_id', 'title'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Lessons::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'course_id' => $this->course_id,
]);
$query->andFilterWhere(['like', 'video_id', $this->video_id])
->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider;
}
}
<?php
use yii\helpers\Url;
?>
<section class="sh_kurs">
<div class="container">
<div class="row">
......@@ -27,60 +23,23 @@ use yii\helpers\Url;
</div>
<div class="row">
<div class="col-md-12 col-xs-12 col-sm-12">
<div class="kurs_item">
<div class="kurs_img">
<img src="images/kurs1.jpg" height="262" width="907" alt="">
</div>
<div class="kurs_over">
<h1 class="kurs_title"><span>Курс для менеджеров it-отрасли</span></h1><br>
<span class="kurs_sub-title"><span>Научим как правильно ставить задачи, контролировать исполнителей</span><br> <span>и определять приоритеты в работе.</span></span>
<div class="blip_kurs">За просмотр этих курсов<br> мы заплатим 15 000 руб.</div>
<div class="kurs_foot clearfix">
<a href="<?php echo Url::toRoute(['/school/course/view', 'id' => 1]);?>" class="kurs_bt">Подробнее</a>
</div>
<div class="for_it"><div class="r_it"></div>Для сотрудников it-отрасли</div>
</div>
</div>
<div class="kurs_item">
<div class="kurs_img">
<img src="images/kurs2.jpg" height="262" width="907" alt="">
</div>
<div class="kurs_over">
<h1 class="kurs_title"><span>Интернет-маркетинг для бизнеса</span></h1><br>
<span class="kurs_sub-title"><span>Расскажем как оценить работу подрятной организации и научиться работать с показателями статистики</span></span>
<div class="kurs_foot clearfix">
<a href="<?php echo Url::toRoute(['/school/course/view', 'id' => 1]);?>" class="kurs_bt">Подробнее</a>
</div>
<div class="for_im"><div class="r_im"></div>Для интернет-маркетологов</div>
</div>
</div>
<div class="kurs_item">
<div class="kurs_img">
<img src="images/kurs3.jpg" height="262" width="907" alt="">
</div>
<div class="kurs_over">
<h1 class="kurs_title"><span>Как автоматизировать бизнес<br></span> <span>второй уровень заголовка</span></h1><br>
<span class="kurs_sub-title"><span>Покажем пример автоматизации бизнеса и рассмотрим реальные проблемы с которыми сталкивались</span><br><span>предприниматели.</span></span>
<div class="kurs_foot clearfix">
<a href="<?php echo Url::toRoute(['/school/course/view', 'id' => 1]);?>" class="kurs_bt">Подробнее</a>
</div>
<div class="for_sb"><div class="r_sb"></div>Для собственников бизнеса</div>
</div>
</div>
<div class="kurs_item">
<div class="kurs_img">
<img src="images/kurs4.jpg" height="262" width="907" alt="">
</div>
<div class="kurs_over lock">
<h1 class="kurs_title"><span>Как организовать процесс в веб-студии</span></h1><br>
<span class="kurs_sub-title"><span>Живое наставничество как создать веб-студию с "нуля".</span></span>
<div class="kurs_lock"></div>
<div class="kurs_foot clearfix">
<a href="#" class="kurs_bt">Предварительная регистрация</a>
</div>
<div class="for_dv"><div class="r_dv"></div>в разработке</div>
</div>
</div>
<?php echo \yii\widgets\ListView::widget( [
'dataProvider' => $dataProvider,
'itemView' => 'item-view',
'itemOptions' => ['tag' => ''],
'options' => ['tag' => ''],
'layout' => '{items}<li><nav class="pages">{pager}</nav></li>',
'pager' => [
'class' => 'common\components\zii\FrontLinkPager',
'activePageCssClass' => 'is-active',
'prevPageLabel' => '<span class="glyphicon glyphicon-chevron-left"></span>Предыдущая',
'nextPageLabel' => 'Следующая<span class="glyphicon glyphicon-chevron-right"></span>',
'options' => [
'class' => 'pages-list',
],
],
] );
?>
</div>
</div>
</div>
......
<?php
use yii\helpers\Url;
use common\modules\school\models\Courses;
?>
<div class="kurs_item">
<div class="kurs_img">
<img src="<?php echo $model->getUrl($model->image);?>" height="262" width="907" alt="">
</div>
<div class="kurs_over">
<h1 class="kurs_title"><span><?php echo $model->title;?></span></h1><br>
<span class="kurs_sub-title"><?php echo $model->description;?></span>
<?php if($model->spec_proposition):?>
<div class="blip_kurs">За просмотр этих курсов<br> мы заплатим 15 000 руб.</div>
<?php endif;?>
<div class="kurs_foot clearfix">
<a href="<?php echo Url::toRoute(['/school/course/view', 'id' => 1]);?>" class="kurs_bt">Подробнее</a>
</div>
<div class="for_<?php echo $model->getClassCourse($model->type);?>">
<div class="r_<?php echo $model->getClassCourse($model->type);?>"></div>
<?php echo Courses::$type_list[$model->type]?>
</div>
</div>
</div>
<?php
use yii\helpers\Html;
use \common\components\zii\AdminGrid;
use common\modules\school\models\Courses;
/* @var $this yii\web\View */
/* @var $searchModel common\modules\faq\models\SearchFaq */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<p>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php echo AdminGrid::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'title',
[
'attribute' => 'type',
'filter' => Courses::$type_list,
'value' => function($model)
{
return Courses::$type_list[$model->type];
}
],
[
'class' => 'common\components\ColorActionColumn',
'template' => '{view} {update}',
],
],
]); ?>
\ No newline at end of file
<?php
echo $form;
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use common\modules\school\models\Courses;
/* @var $this yii\web\View */
?>
<div class="faq-view">
<p>
<?= Html::a(Yii::t('content', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<!-- <?= Html::a(Yii::t('content', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('content', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?> -->
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'title',
'description',
[
'attribute' => 'type',
'value' => Courses::$type_list[$model->type],
],
],
]) ?>
</div>
<?php
use yii\helpers\Html;
use \common\components\zii\AdminGrid;
use \yii\helpers\ArrayHelper;
use common\modules\school\models\Courses;
/* @var $this yii\web\View */
/* @var $searchModel common\modules\faq\models\SearchFaq */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<p>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php echo AdminGrid::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'title',
'video_id',
[
'attribute' => 'course_id',
'filter' => Html::dropDownList('SearchCourses[course_id]',
$searchModel->course_id,
ArrayHelper::map(Courses::find()->all(),'id','title'),
['class'=>'form-control','prompt'=>'Курс']),
'value' => function($model)
{
return $model->course->title;
}
],
[
'class' => 'common\components\ColorActionColumn',
'template' => '{view} {update}',
],
],
]); ?>
\ No newline at end of file
<?php
echo $form;
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use common\modules\school\models\Courses;
/* @var $this yii\web\View */
?>
<div class="faq-view">
<p>
<?= Html::a(Yii::t('content', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<!-- <?= Html::a(Yii::t('content', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('content', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?> -->
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'title',
'video_id',
[
'attribute' => 'course_id',
'filter' => false,
'value' => function($model)
{
return $model->course->title;
}
],
],
]) ?>
</div>
......@@ -32,7 +32,8 @@
"tecnick.com/tcpdf": "dev-master",
"mikehaertl/phpwkhtmltopdf": "^2.0@dev",
"himiklab/yii2-sitemap-module" : "*",
"mirocow/yii2-minify-view" : "*"
"mirocow/yii2-minify-view" : "*",
"kartik-v/yii2-widget-fileinput": "@dev"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
......
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160129_215306_create_table_courses extends Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql')
{
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
// Структура таблицы `courses`
$this->createTable('courses', [
'id' => Schema::TYPE_PK,
'title' => Schema::TYPE_STRING . '(150) NOT NULL',
'description' => Schema::TYPE_TEXT . ' NOT NULL',
'type' => Schema::TYPE_INTEGER . '(11) NOT NULL',
'image' => Schema::TYPE_STRING . '(100)',
], $tableOptions);
}
public function safeDown()
{
$this->dropTable('courses');
}
}
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160129_215506_create_table_lessons extends Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql')
{
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
// Структура таблицы `lessons`
$this->createTable('lessons', [
'id' => Schema::TYPE_PK,
'title' => Schema::TYPE_STRING . '(150) NOT NULL',
'text' => Schema::TYPE_TEXT . ' NOT NULL',
'course_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
'video_id' => Schema::TYPE_STRING . '(100) NOT NULL',
], $tableOptions);
$this->createIndex('FK_lessons_courses', 'lessons', 'course_id');
}
public function safeDown()
{
$this->dropTable('lessons');
}
}
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160201_200213_add_field_to_courses_table extends Migration
{
public function safeUp()
{
$this->addColumn('courses', 'spec_proposition', Schema::TYPE_INTEGER . '(11)');
}
public function safeDown()
{
$this->dropColumn('courses', 'spec_proposition');
}
}
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