Commit 639b1840 authored by Shakarim Sapa's avatar Shakarim Sapa

Merge remote-tracking branch 'origin/master'

parents b0952341 d4119a2c
<?php
namespace common\assets;
class JqueryCookieAsset extends \yii\web\AssetBundle
{
public $sourcePath = '@bower/jquery-cookie/src';
public $js = [
'jquery.cookie.js',
];
public $depends = [
'yii\web\JqueryAsset',
];
}
\ No newline at end of file
...@@ -27,6 +27,8 @@ abstract class BaseController extends Controller ...@@ -27,6 +27,8 @@ abstract class BaseController extends Controller
{ {
parent::init(); parent::init();
$this->_initSession();
$this->_initLanguage(); $this->_initLanguage();
if (YII_DEBUG) if (YII_DEBUG)
{ {
...@@ -34,6 +36,14 @@ abstract class BaseController extends Controller ...@@ -34,6 +36,14 @@ abstract class BaseController extends Controller
} }
} }
private function _initSession()
{
if(!Yii::$app->session->has('SessionData'))
{
$request = Yii::$app->request;
Yii::$app->session->set('SessionData', [$request->url, $request->referrer]);
}
}
private function _initLanguage() private function _initLanguage()
{ {
......
...@@ -4,7 +4,8 @@ namespace common\modules\bids\models; ...@@ -4,7 +4,8 @@ namespace common\modules\bids\models;
use Yii; use Yii;
use \common\models\Settings; use common\models\Settings;
use common\modules\sessions\models\Session;
/** /**
* This is the model class for table "bids". * This is the model class for table "bids".
...@@ -133,10 +134,17 @@ class Bid extends \common\components\ActiveRecordModel ...@@ -133,10 +134,17 @@ class Bid extends \common\components\ActiveRecordModel
{ {
try try
{ {
$session = null;
if(Yii::$app->session->has('Session'))
{
$session = Session::findOne(Yii::$app->session->get('Session'));
}
$email = Settings::getValue('bids-support-email'); $email = Settings::getValue('bids-support-email');
$message = Yii::$app->controller->view->render('@common/modules/bids/views/bid/mail-all', [ $message = Yii::$app->controller->view->render('@common/modules/bids/views/bid/mail-all', [
'model' => $this 'model' => $this,
'session' => $session
]); ]);
$headers = "MIME-Version: 1.0\r\n". $headers = "MIME-Version: 1.0\r\n".
......
...@@ -14,4 +14,12 @@ Email: <?=$model->email?><br> ...@@ -14,4 +14,12 @@ Email: <?=$model->email?><br>
Файл: <?=($model->filename?Html::a($model->filename,\Yii::$app->params['frontUrl'].Bid::FILE_FOLDER.$model->filename):'')?><br> Файл: <?=($model->filename?Html::a($model->filename,\Yii::$app->params['frontUrl'].Bid::FILE_FOLDER.$model->filename):'')?><br>
Дата добавления заявки: <?=date('d.m.Y H:i:s', $model->created_at)?><br> Дата добавления заявки: <?=date('d.m.Y H:i:s', $model->created_at)?><br>
\ No newline at end of file
<?php if($session) : ?>
Реферер: <?=$session->referer?><br>
Заявка отправлена со страницы: <?=$session->url?><br>
<?php endif; ?>
\ No newline at end of file
<?php
namespace common\modules\school\models;
use Yii;
use common\modules\school\models\Lessons;
/**
* This is the model class for table "testings_questions_image".
*
* @property integer $id
* @property integer $question_id
* @property string $filename
*/
class LessonImage extends \common\components\ActiveRecordModel
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'school_lessons_image';
}
public function name()
{
return 'Документы для уроков';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['lesson_id', 'filename'], 'required'],
[['lesson_id'], 'integer'],
[['filename'], 'string', 'max' => 50],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'lesson_id' => 'Урок',
'filename' => 'Документ',
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
];
}
public function getLesson()
{
return $this->hasOne(Lessons::className(), ['id' => 'lesson_id']);
}
public function getUrl()
{
return Yii::$app->params['frontUrl'] . Lessons::IMAGES_FOLDER . $this->filename;
}
}
...@@ -17,6 +17,9 @@ class Lessons extends \common\components\ActiveRecordModel ...@@ -17,6 +17,9 @@ class Lessons extends \common\components\ActiveRecordModel
{ {
const PAGE_SIZE = 10; const PAGE_SIZE = 10;
const IMAGES_FOLDER = '/uploads/lessons_docs/';
public $filesUpload;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -41,6 +44,7 @@ class Lessons extends \common\components\ActiveRecordModel ...@@ -41,6 +44,7 @@ class Lessons extends \common\components\ActiveRecordModel
[['video_id'], 'string', 'max' => 100], [['video_id'], 'string', 'max' => 100],
[['course_id', 'number'], 'integer'], [['course_id', 'number'], 'integer'],
[['text'], 'safe'], [['text'], 'safe'],
[['filesUpload'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif, rar, ai, ppt, doc, docx'],
]; ];
} }
...@@ -99,4 +103,57 @@ class Lessons extends \common\components\ActiveRecordModel ...@@ -99,4 +103,57 @@ class Lessons extends \common\components\ActiveRecordModel
return false; return false;
} }
} }
public function getFiles()
{
return $this->hasMany(LessonImage::className(), ['lesson_id' => 'id']);
}
public function getPath()
{
return Yii::getAlias('@frontend/web') . self::IMAGES_FOLDER;
}
public function upload()
{
if ($this->validate())
{
if(!file_exists($this->getPath()))
{
mkdir($this->getPath(), 0777, true);
}
foreach ($this->filesUpload as $file)
{
$filename = date('dmYHis-') . uniqid() . '.' . $file->extension;
$file->saveAs($this->getPath() . $filename);
$image = new LessonImage;
$image->lesson_id = $this->id;
$image->filename = $filename;
$image->save();
}
return true;
}
else
{
return false;
}
}
public function deleteFiles()
{
if($this->files)
{
foreach ($this->files as $file)
{
if(file_exists($this->getPath() . $file->filename))
{
unlink($this->getPath() . $file->filename);
}
$file->delete();
}
}
}
} }
<?php
namespace common\modules\sessions;
/**
* sessions module definition class
*/
class Module extends \common\components\WebModule
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'common\modules\sessions\controllers';
public $menu_icons = 'fa fa-eye';
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
public static function description()
{
return 'Сессии';
}
public static function version()
{
return '1.0';
}
public static function name()
{
return 'Управление сессиями';
}
public static function adminMenu()
{
return array(
// 'Сессии' => '/sessions/post-admin/manage',
);
}
}
<?php
namespace common\modules\sessions\controllers;
use Yii;
use yii\web\Response;
use common\components\BaseController;
use common\modules\sessions\models\Session;
/**
* Default controller for the `sessions` module
*/
class DefaultController extends BaseController
{
public static function actionsTitles()
{
return [
'Add' => 'Фиксация сессии',
];
}
/**
* Renders the index view for the module
* @return string
*/
public function actionAdd()
{
Yii::$app->response->format = Response::FORMAT_JSON;
if(!Yii::$app->session->has('Session'))
{
list($url, $referrer) = Yii::$app->session->get('SessionData');
$request = Yii::$app->request;
$session = new Session;
$session->PHPSESSID = Yii::$app->session->id;
$session->ip = $request->userIP;
$session->url = $url;
$session->referer = $referrer;
$session->save();
Yii::$app->session->set('Session', $session->id);
}
return ['success' => true];
}
}
<?php
namespace common\modules\sessions\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "sessions".
*
* @property integer $id
* @property string $PHPSESSID
* @property integer $user_id
* @property string $ip
* @property string $url
* @property integer $created_at
*/
class Session extends \common\components\ActiveRecordModel
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'sessions';
}
public function name()
{
return 'Сессия';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => null,
'value' => time(),
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
// [['PHPSESSID', 'ip', 'url'], 'required'],
[['user_id', 'created_at'], 'integer'],
[['url', 'referer'], 'string'],
[['PHPSESSID'], 'string', 'max' => 32],
[['ip'], 'string', 'max' => 15],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'PHPSESSID' => 'Сессия',
'user_id' => 'Пользователь',
'ip' => 'IP',
'url' => 'Ссылка',
'created_at' => 'Дата добавления',
];
}
}
<div class="sessions-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
"mirocow/yii2-minify-view" : "*", "mirocow/yii2-minify-view" : "*",
"kartik-v/yii2-widget-fileinput": "@dev", "kartik-v/yii2-widget-fileinput": "@dev",
"nodge/yii2-eauth": "~2.0", "nodge/yii2-eauth": "~2.0",
"xj/yii2-tagit-widget": "*" "xj/yii2-tagit-widget": "*",
"bower-asset/jquery-cookie": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-codeception": "*", "yiisoft/yii2-codeception": "*",
......
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160217_095148_create_school_lessons_image extends Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql')
{
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
// Структура таблицы `school_lessons_image`
$this->createTable('school_lessons_image', [
'id' => Schema::TYPE_PK,
'filename' => Schema::TYPE_STRING . '(50) NOT NULL',
'lesson_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
], $tableOptions);
$this->createIndex('FK_school_lessons_image_lessons', 'school_lessons_image', 'lesson_id');
}
public function safeDown()
{
$this->dropTable('school_lessons_image');
}
}
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160217_124741_add_sessions_table extends Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
$this->createTable('sessions', [
'id' => Schema::TYPE_PK,
'PHPSESSID' => Schema::TYPE_STRING . '(32) NOT NULL',
'user_id' => Schema::TYPE_INTEGER . '(11) DEFAULT NULL',
'ip' => Schema::TYPE_STRING . '(15) NOT NULL',
'url' => Schema::TYPE_TEXT . ' DEFAULT NULL',
'referer' => Schema::TYPE_TEXT . ' DEFAULT NULL',
'created_at' => Schema::TYPE_INTEGER . '(11) DEFAULT NULL',
]);
$this->createIndex('sessions_PHPSESSID', 'sessions', 'PHPSESSID');
}
public function safeDown()
{
$this->dropIndex('sessions_PHPSESSID', 'sessions');
$this->dropTable('sessions');
}
}
...@@ -25,5 +25,6 @@ class AppAsset extends AssetBundle ...@@ -25,5 +25,6 @@ class AppAsset extends AssetBundle
public $depends = [ public $depends = [
'yii\web\YiiAsset', 'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
'common\assets\JqueryCookieAsset',
]; ];
} }
...@@ -24,6 +24,7 @@ return [ ...@@ -24,6 +24,7 @@ return [
'testings' => ['class' => 'common\modules\testings\Module',], 'testings' => ['class' => 'common\modules\testings\Module',],
'users' => ['class' => 'common\modules\users\users',], 'users' => ['class' => 'common\modules\users\users',],
'blog' => ['class' => 'common\modules\blog\Module'], 'blog' => ['class' => 'common\modules\blog\Module'],
'sessions' => ['class' => 'common\modules\sessions\Module'],
'sitemap' => [ 'sitemap' => [
'class' => 'frontend\modules\sitemap\Sitemap', 'class' => 'frontend\modules\sitemap\Sitemap',
'models' => [ 'models' => [
......
...@@ -6,4 +6,8 @@ $(document).ready(function() { ...@@ -6,4 +6,8 @@ $(document).ready(function() {
return false; return false;
}); });
$.ajax({
url: "/sessions/default/add"
});
}); });
\ 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