Commit 33d72d12 authored by Виталий Мурашко's avatar Виталий Мурашко

Merge branch 'master' of http://git.task-on.com/ktask/task-on.com

parents 43352fa5 7ec50275
......@@ -120,4 +120,13 @@ a.desc:after {
.file-widget{
margin-bottom: 20px;
}
.control-label {min-width: 100px;}
\ No newline at end of file
.control-label {min-width: 100px;}
.file-drop-zone {
height: auto;
}
.file-drop-zone-title {
padding: 35px 10px;
}
.file-preview-image {
height: 100px !important;
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ use Yii;
use common\modules\languages\models\Languages;
use common\modules\blog\models\PostLang;
use common\modules\blog\models\PostTag;
use common\modules\users\models\User;
use common\models\MetaTags;
/**
......@@ -52,7 +53,7 @@ class Post extends \common\components\ActiveRecordModel
{
return [
[['url', 'active'], 'required'],
[['active', 'created_at', 'updated_at'], 'integer'],
[['active', 'created_at', 'updated_at', 'author_id'], 'integer'],
[['url'], 'string', 'max' => 255],
[['url'], 'unique'],
[['preview', 'unlinkFile', 'tags'], 'safe'],
......@@ -100,6 +101,7 @@ class Post extends \common\components\ActiveRecordModel
{
return [
'id' => 'ID',
'author_id' => 'Автор',
'url' => 'Ссылка',
'active' => 'Видимость',
'file' => 'Изображение',
......@@ -173,10 +175,31 @@ class Post extends \common\components\ActiveRecordModel
return $this->hasMany(PostTagAssign::className(), ['post_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthor()
{
return $this->hasOne(User::className(), ['id' => 'author_id']);
}
public function getThumbnailUrl()
{
$path = pathinfo($this->preview);
return $path['dirname'] . '/' . $path['filename'] . '.thumb.' . $path['extension'];
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert))
{
$this->author_id = Yii::$app->user->identity->id;
return true;
}
else
{
return false;
}
}
}
......@@ -61,6 +61,18 @@ $this->params['breadcrumbs'][] = $this->title;
return null;
}
],
[
'attribute' => 'author_id',
'value' => function($model)
{
if($model->author)
{
return $model->author->surname . ' ' . $model->author->name;
}
return null;
}
],
[
'class' => 'common\components\ColorActionColumn',
......
......@@ -62,20 +62,28 @@ class CoursesAdminController extends AdminController
];
if($model->load(Yii::$app->request->post()) && $model->validate()){
//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;
if ($model->filename) {
$model->image = $model->filename;
}
else {
//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;
}
}
$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);
if (!$model->filename) {
//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
......@@ -169,7 +177,7 @@ class CoursesAdminController extends AdminController
public function actionUpload()
{
$model = new Courses;
if (empty($_FILES['Courses'])) {
if (empty($_FILES['Courses'])) {
echo json_encode(['error'=>'No files found for upload.']);
// or you can throw an exception
return; // terminate
......@@ -183,10 +191,10 @@ class CoursesAdminController extends AdminController
$paths= [];
// get file names
$filename = $images['name']["upload_image"];
//$filename = $images['name']["upload_image"];
// loop and process files
$ext = explode('.', basename($filename));
$target = $model->getPath() . md5(uniqid()) . "." . array_pop($ext);
//$ext = explode('.', basename($filename));
$target = $model->getPath() . $images['name']["upload_image"];//md5(uniqid()) . "." . array_pop($ext);
if(move_uploaded_file($images['tmp_name']["upload_image"], $target)) {
$success = true;
$paths[] = $target;
......
......@@ -7,30 +7,33 @@ use yii\helpers\Url;
use common\modules\school\models\Courses;
use common\modules\testings\models\Test;
$initialImages = '';
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>";
$initialImages[] = Html::img($model->getUrl($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,
'overwriteInitial'=>true,
'initialPreview'=>$initialImages,
],
'pluginEvents' => [
'fileuploaded'=>"function(event, data, previewId, index) {
$(\"[name='Courses[filename]']\").val(data.files[0].name);
}",
'fileclear'=>"function(event) {
$(\"[name='Courses[filename]']\").val();
}",
],
])."</div>";
$elements = [
'test_id' => ['type' => 'dropdownlist', 'items' => ArrayHelper::map(Test::find()->all(), 'id', 'name', 'session.name'), 'empty' => 'Не задан'],
'title' => ['type' => 'text'],
......@@ -41,6 +44,7 @@ $elements = [
'items' => Courses::$type_list,
],
'spec_proposition' => ['type' => 'checkbox'],
'filename' => ['type' => 'hidden'],
'image' => $image,
];
......
......@@ -20,6 +20,8 @@ class Courses extends \common\components\ActiveRecordModel
public $upload_image;
public $filename;
public static $type_list = [
self::TYPE_IT => 'Для сотрудников it-отрасли',
self::TYPE_IM => 'Для интернет-маркетологов',
......@@ -60,7 +62,7 @@ class Courses extends \common\components\ActiveRecordModel
[['type', 'spec_proposition', 'test_id'], 'integer'],
[['title'], 'string', 'max' => 150],
[['image'], 'string', 'max' => 100],
[['description', 'description_for_course'], 'safe'],
[['description', 'description_for_course', 'filename'], 'safe'],
[['upload_image'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
];
}
......@@ -88,6 +90,12 @@ class Courses extends \common\components\ActiveRecordModel
}
}
public function afterFind() {
$this->filename = $this->image;
parent::afterFind();
}
public function getLessons()
{
return $this->hasMany(Lessons::className(), ['course_id' => 'id']);
......
......@@ -146,10 +146,34 @@ class TestController extends \common\components\BaseController
public function actionGenPass($id)
{
$passing = $this->findModel($id);
$transaction = Yii::$app->db->beginTransaction();
$test = $this->findModel($id);
try
{
$passing = Passing::find()->where([
'user_id' => Yii::$app->user->identity->id,
'test_id' => $id
])->one();
if(!$passing)
{
$passing = new Passing;
$passing->user_id = Yii::$app->user->identity->id;
$passing->test_id = $id;
}
$transaction->commit();
}
catch (\Exception $e)
{
$transaction->rollBack();
throw $e;
}
$mg_gammas = array();
$te_gammas = array();
$user_id = Yii::app()->request->cookies[self::AUTH_COOKIE]->value;
$cr3 = new CDbCriteria;
......
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160219_112010_add_post_column extends Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
$this->addColumn('posts', 'author_id', Schema::TYPE_INTEGER . '(11) NOT NULL AFTER `active`');
}
public function safeDown()
{
$this->dropColumn('posts', 'author_id');
}
}
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