diff --git a/common/models/Chat.php b/common/models/Chat.php
index 0c8164d..40abb9c 100644
--- a/common/models/Chat.php
+++ b/common/models/Chat.php
@@ -75,6 +75,6 @@ class Chat extends \yii\db\ActiveRecord
*/
public function getMessages()
{
- return $this->hasMany(Message::className(), ['chat_id' => 'chat_id'])->orderBy('message_id')->all() ;
+ return $this->hasMany(Message::className(), ['chat_id' => 'chat_id'])->orderBy('message_id') ;
}
}
diff --git a/common/models/File.php b/common/models/File.php
index fc4af38..33cd82d 100644
--- a/common/models/File.php
+++ b/common/models/File.php
@@ -3,6 +3,7 @@
namespace common\models;
use Yii;
+use yii\web\UploadedFile;
/**
* This is the model class for table "file".
@@ -46,4 +47,24 @@ class File extends \yii\db\ActiveRecord
'dir' => 'Dir',
];
}
+
+ /**
+ * @param UploadedFile $file
+ * @return file id in model File
+ */
+
+ public function saveFile(UploadedFile $file){
+ $imgDir = Yii::getAlias('@storage/'.'user_'.\Yii::$app->user->id.'/files/');
+ $uploadName = $file->baseName.'_'. time().'.'.$file->extension;
+ if(!is_dir($imgDir)) {
+ mkdir($imgDir, 0755, true);
+ }
+
+ if($file->saveAs($imgDir.$uploadName)){
+ $this->dir = '/storage/user_'.\Yii::$app->user->id.'/files/'.$uploadName;
+ $this->name = $file->baseName.'.'.$file->extension;
+ $this->save();
+ return $this->file_id;
+ }
+ }
}
diff --git a/common/models/Message.php b/common/models/Message.php
index 08d3a8a..fa700fd 100644
--- a/common/models/Message.php
+++ b/common/models/Message.php
@@ -4,6 +4,7 @@ namespace common\models;
use Yii;
+
/**
* This is the model class for table "message".
*
@@ -19,6 +20,9 @@ use Yii;
*/
class Message extends \yii\db\ActiveRecord
{
+
+ public $file;
+
/**
* @inheritdoc
*/
@@ -35,7 +39,7 @@ class Message extends \yii\db\ActiveRecord
return [
[['chat_id', 'user_id', 'status'], 'integer'],
[['text'], 'string'],
- [['date'], 'safe'],
+ [['date','file'], 'safe'],
[['files'], 'string', 'max' => 255],
[['chat_id'], 'exist', 'skipOnError' => true, 'targetClass' => Chat::className(), 'targetAttribute' => ['chat_id' => 'chat_id']],
];
@@ -65,6 +69,19 @@ class Message extends \yii\db\ActiveRecord
return $this->hasOne(Chat::className(), ['chat_id' => 'chat_id']);
}
+ public function getUser()
+ {
+ return $this->hasOne(UserInfo::className(), ['user_id' => 'user_id']);
+ }
+
+ public function getFilesList(){
+ $files = json_decode($this->files);
+ return File::findAll($files);
+
+ }
+
+
+
public function isMy(){
if($this->user_id == \Yii::$app->user->id){
return true;
diff --git a/frontend/controllers/ChatController.php b/frontend/controllers/ChatController.php
index 648242b..b994254 100755
--- a/frontend/controllers/ChatController.php
+++ b/frontend/controllers/ChatController.php
@@ -2,6 +2,7 @@
namespace frontend\controllers;
use common\models\Chat;
+use common\models\File;
use common\models\Message;
use Yii;
use common\models\User;
@@ -9,6 +10,7 @@ use yii\data\ActiveDataProvider;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
+use yii\web\UploadedFile;
/**
@@ -54,7 +56,9 @@ class ChatController extends Controller
'or',
['from_user'=> $user->id,],
['to_user'=> $user->id,],
- ])->one();
+ ])
+ ->with('messages.user')
+ ->one();
if(!$chat instanceof Chat){
$chat = new Chat();
$chat->from_user = $user->id;
@@ -67,18 +71,48 @@ class ChatController extends Controller
$post = \Yii::$app->request->post();
if(isset($post)){
-
-
$message = new Message();
-
if($message->load($post, 'Message')){
$message->chat_id = $chat->chat_id;
$message->user_id = $user->id;
+
+ $message->file = UploadedFile::getInstances($message, 'file');
+
+ if(!empty($message->file)) {
+
+ if(is_array($message->file)){
+
+ foreach($message->file as $file){
+
+ if($file instanceof UploadedFile){
+
+ $file_model = new File();
+ $file_id[] = $file_model->saveFile($file);
+
+ }
+
+ }
+
+ } else {
+
+ if($message->file instanceof UploadedFile){
+
+ $file_model = new File();
+ $file_id[] = $file_model->saveFile($message->file);
+ }
+
+ }
+
+ $message->files = json_encode($file_id);
+ }
+
+
$message->save();
return $this->redirect(['chat/message', 'user_id'=>$user_id]);
+
}
}
diff --git a/frontend/views/chat/message.php b/frontend/views/chat/message.php
index e02442a..c45c595 100755
--- a/frontend/views/chat/message.php
+++ b/frontend/views/chat/message.php
@@ -1,6 +1,7 @@
registerJsFile("/js/forms.js");
@@ -93,27 +94,35 @@ $this->registerJsFile("/js/forms.js");
messages as $message):?>
isMy()):?>
@@ -122,15 +131,19 @@ $this->registerJsFile("/js/forms.js");
diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css
index 74b0b7b..5fe16a3 100755
--- a/frontend/web/css/style.css
+++ b/frontend/web/css/style.css
@@ -4112,7 +4112,7 @@ ul.min_markers_two
/***js_scroll***/
.jspContainer{overflow:hidden;position:relative}.jspPane{position:absolute}.jspVerticalBar{position:absolute;top:0;right:0;width:16px;height:100%;background:red}.jspHorizontalBar{position:absolute;bottom:0;left:0;width:100%;height:16px;background:red}.jspCap{display:none}.jspHorizontalBar .jspCap{float:left}.jspTrack{background:#dde;position:relative}.jspDrag{background:#bbd;position:relative;top:0;left:0;cursor:pointer}.jspHorizontalBar .jspTrack,.jspHorizontalBar .jspDrag{float:left;height:100%}.jspArrow{background:#50506d;text-indent:-20000px;display:block;cursor:pointer;padding:0;margin:0}.jspArrow.jspDisabled{cursor:default;background:#80808d}.jspVerticalBar .jspArrow{height:16px}.jspHorizontalBar .jspArrow{width:16px;float:left;height:100%}.jspVerticalBar .jspArrow:focus{outline:none}.jspCorner{background:#eeeef4;float:left;height:100%}* html .jspCorner{margin:0 -3px 0 0}
/*** message-read***/
-.comments_block{width:938px;height:498px;background-color:#fcfcfc;border:1px solid #b7b7b7;border-right:none;margin-bottom:57px;color:#333;font-family:Roboto;font-size:13px;position:relative;overflow:hidden;outline:none}.comment_type{width:940px}.comment_type .pole{width:660px;margin:0 auto;position:relative}.comment_type .mes_title{font-size:18px;color:#333;margin:18px 0}.message_text{width:638px;height:78px;resize:none;border:1px solid #c2c2c2;margin:0 auto;margin-bottom:26px;margin-top:18px;padding:10px;font-family:Roboto}.send_mess_but{outline:none;border:none;cursor:pointer;font-size:12px!important;padding-top:2px;width:170px;height:43px;text-align:center;text-transform:uppercase;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr = '#148ad6',endColorstr = '#0072bc');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr = '#148ad6',endColorstr = '#0072bc')";background-image:-moz-linear-gradient(top,#148ad6,#0072bc);background-image:-ms-linear-gradient(top,#148ad6,#0072bc);background-image:-o-linear-gradient(top,#148ad6,#0072bc);background-image:-webkit-gradient(linear,center top,center bottom,from(#148ad6),to(#0072bc));background-image:-webkit-linear-gradient(top,#148ad6,#0072bc);background-image:linear-gradient(top,#148ad6,#0072bc);color:#fff;border-bottom:2px solid #0054a6;border-radius:4px;transition:.1s;top:170px;line-height:3.5}.send_mess_but:hover{opacity:.9}.send_mess_but:active{line-height:3.7}.pick_file{position:absolute;top:170px;right:0;width:130px}.pick_file .link:after{content:'';background:url(/images/skrpk.png) left center no-repeat;position:absolute;width:19px;height:21px;left:-28px;top:0}.pick_file .link{text-transform:uppercase;color:#0276c0;font-size:13px;cursor:pointer;text-decoration:none;border-bottom:1px solid #70b2db;position:relative}.pick_file .capt{color:#c2c2c2;font-size:11px;line-height:16px;margin-top:3px}.comment_text{position:relative;padding:12px 13px;width:602px;border:1px solid #c2c2c2;min-height:74px;left:10px;line-height:1.3;background-color:#fff}.comment.left .comment_text{float:left}.comment.right .comment_text{float:right}.comment.left .comment_text:before{content:'';background:url(/images/mes_bord_left.png);position:absolute;width:11px;height:11px;top:-1px;left:-11px}.comment.right .comment_text:before{content:'';background:url(/images/mes_bord_right.png);position:absolute;width:11px;height:11px;top:-1px;right:-11px}.comment.left .author_pic{float:left;margin:0 10px}.comment.right .author_pic{float:right;margin:0 25px 0 30px}.comment_time{color:#c6c6c6;font-family:Roboto;font-size:13px;font-weight:600;line-height:32px;position:absolute}.comment.left .comment_time{top:17px;right:-64px}.comment.right .comment_time{top:18px;left:-64px}.comment{position:relative;margin:30px 21px 30px 1px}.comment .offer_link a{color:#0173bd;position:relative}.comment .offer_link a:before{content:'';position:absolute;background:url(/images/skrpk_sm.png) left center no-repeat;width:19px;height:21px;left:-26px;top:-3px}.comment.right .offer_link{float:right;margin-right:94px;margin-top:12px;margin-bottom:-17px}.comment.left .offer_link{left:104px;bottom:-27px}.comment_block .content{overflow:auto;width:938px;height:498px}.fileform{background-color:#FFF;border:1px solid #CCC;border-radius:2px;cursor:pointer;height:26px;overflow:hidden;padding:2px;position:relative;text-align:left;vertical-align:middle;width:230px}.comment_type form{width:660px;margin:0 auto}.comment_type form label{color:#333;font-family:Roboto;font-size:18px}.input_file_text{color:#c2c2c2;font-size:11px;font-family:Roboto;width:125px;position:absolute;right:0;line-height:16px;top:18px;overflow:hidden;text-overflow:ellipsis;white-space:pre-line}.inputfile{float:right;position:relative;width:153px;padding-bottom:10px;background:url(/images/skrpk.png);background-repeat:no-repeat}.input_file{opacity:0;cursor:pointer;width:160px}.inputfile .file_input_title{position:absolute;color:#0276c0;border-bottom:1px solid #0276c0;text-transform:uppercase;font-family:Roboto;font-size:13px;right:0}.jspArrow{background-color:#0173bd;width:20px;height:20px}.jspVerticalBar{width:20px}.jspVerticalBar .jspArrow{height:20px}.jspTrack{background:#ebebeb;position:relative}.jspDrag{background:#c2c2c2;position:relative;top:0;left:0;cursor:pointer;border-left:2px solid #ebebeb;border-right:2px solid #ebebeb}.jspVerticalBar{background:#ebebeb}.jspArrowUp{background:#0173bd url(/images/scroll_up.png) center center no-repeat}.jspArrowUp:hover{opacity:.8}.jspArrowUp:active{background-position-y:1px!important}.jspDisabled.jspArrowUp{background:#80808d url(/images/scroll_up_grey.png) center center no-repeat}.jspArrowDown{background:#0173bd url(/images/scroll_down.png) center center no-repeat}.jspArrowDown:hover{opacity:.8}.jspArrowDown:active{background-position-y:1px!important}.jspArrowDown{background:#0173bd url(/images/scroll_down.png) center center no-repeat}.jspDisabled.jspArrowDown{background:#80808d url(/images/scroll_down_grey.png) center center no-repeat}.jspContainer{outline:none;border:none}
+.comments_block{width:938px;height:498px;background-color:#fcfcfc;border:1px solid #b7b7b7;border-right:none;margin-bottom:57px;color:#333;font-family:Roboto;font-size:13px;position:relative;overflow:hidden;outline:none}.comment_type{width:940px}.comment_type .pole{width:660px;margin:0 auto;position:relative}.comment_type .mes_title{font-size:18px;color:#333;margin:18px 0}.message_text{width:638px;height:78px;resize:none;border:1px solid #c2c2c2;margin:0 auto;margin-bottom:26px;margin-top:18px;padding:10px;font-family:Roboto}.send_mess_but{outline:none;border:none;cursor:pointer;font-size:12px!important;padding-top:2px;width:170px;height:43px;text-align:center;text-transform:uppercase;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr = '#148ad6',endColorstr = '#0072bc');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr = '#148ad6',endColorstr = '#0072bc')";background-image:-moz-linear-gradient(top,#148ad6,#0072bc);background-image:-ms-linear-gradient(top,#148ad6,#0072bc);background-image:-o-linear-gradient(top,#148ad6,#0072bc);background-image:-webkit-gradient(linear,center top,center bottom,from(#148ad6),to(#0072bc));background-image:-webkit-linear-gradient(top,#148ad6,#0072bc);background-image:linear-gradient(top,#148ad6,#0072bc);color:#fff;border-bottom:2px solid #0054a6;border-radius:4px;transition:.1s;top:170px;line-height:3.5}.send_mess_but:hover{opacity:.9}.send_mess_but:active{line-height:3.7}.pick_file{position:absolute;top:170px;right:0;width:130px}.pick_file .link:after{content:'';background:url(/images/skrpk.png) left center no-repeat;position:absolute;width:19px;height:21px;left:-28px;top:0}.pick_file .link{text-transform:uppercase;color:#0276c0;font-size:13px;cursor:pointer;text-decoration:none;border-bottom:1px solid #70b2db;position:relative}.pick_file .capt{color:#c2c2c2;font-size:11px;line-height:16px;margin-top:3px}.comment_text{position:relative;padding:12px 13px;width:602px;border:1px solid #c2c2c2;min-height:74px;left:10px;line-height:1.3;background-color:#fff}.comment.left .comment_text{float:left}.comment.right .comment_text{float:right}.comment.left .comment_text:before{content:'';background:url(/images/mes_bord_left.png);position:absolute;width:11px;height:11px;top:-1px;left:-11px}.comment.right .comment_text:before{content:'';background:url(/images/mes_bord_right.png);position:absolute;width:11px;height:11px;top:-1px;right:-11px}.comment.left .author_pic{float:left;margin:0 10px}.comment.right .author_pic{float:right;margin:0 25px 0 30px}.comment_time{color:#c6c6c6;font-family:Roboto;font-size:13px;font-weight:600;line-height:32px;position:absolute}.comment.left .comment_time{top: 17px; right: -120px; width: 100px;}.comment.right .comment_time{ top: 18px; left: -88px; width: 100px;}.comment{position:relative;margin:30px 21px 30px 1px}.comment .offer_link a{color:#0173bd;position:relative}.comment .offer_link a:before{content:'';position:absolute;background:url(/images/skrpk_sm.png) left center no-repeat;width:19px;height:21px;left:-26px;top:-3px}.comment.right .offer_link{float:right;margin-right:94px;margin-top:12px;margin-bottom:-17px}.comment.left .offer_link{left:104px;bottom:-27px}.comment_block .content{overflow:auto;width:938px;height:498px}.fileform{background-color:#FFF;border:1px solid #CCC;border-radius:2px;cursor:pointer;height:26px;overflow:hidden;padding:2px;position:relative;text-align:left;vertical-align:middle;width:230px}.comment_type form{width:660px;margin:0 auto}.comment_type form label{color:#333;font-family:Roboto;font-size:18px}.input_file_text{color:#c2c2c2;font-size:11px;font-family:Roboto;width:125px;position:absolute;right:0;line-height:16px;top:18px;overflow:hidden;text-overflow:ellipsis;white-space:pre-line}.inputfile{float:right;position:relative;width:153px;padding-bottom:10px;background-repeat:no-repeat}.input_file{opacity:0;cursor:pointer;width:160px}.inputfile .file_input_title{position:absolute;color:#0276c0;border-bottom:1px solid #0276c0;text-transform:uppercase;font-family:Roboto;font-size:13px;right:0}.jspArrow{background-color:#0173bd;width:20px;height:20px}.jspVerticalBar{width:20px}.jspVerticalBar .jspArrow{height:20px}.jspTrack{background:#ebebeb;position:relative}.jspDrag{background:#c2c2c2;position:relative;top:0;left:0;cursor:pointer;border-left:2px solid #ebebeb;border-right:2px solid #ebebeb}.jspVerticalBar{background:#ebebeb}.jspArrowUp{background:#0173bd url(/images/scroll_up.png) center center no-repeat}.jspArrowUp:hover{opacity:.8}.jspArrowUp:active{background-position-y:1px!important}.jspDisabled.jspArrowUp{background:#80808d url(/images/scroll_up_grey.png) center center no-repeat}.jspArrowDown{background:#0173bd url(/images/scroll_down.png) center center no-repeat}.jspArrowDown:hover{opacity:.8}.jspArrowDown:active{background-position-y:1px!important}.jspArrowDown{background:#0173bd url(/images/scroll_down.png) center center no-repeat}.jspDisabled.jspArrowDown{background:#80808d url(/images/scroll_down_grey.png) center center no-repeat}.jspContainer{outline:none;border:none}
/***form-order***/
#modal_form_offer {height: 505px;}
#modal_form_offer,#modal_form_question, #modal_form_question{margin-top: 70px;}
--
libgit2 0.21.4
- 18:00 + = $message->date ?>