-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bubasuma
committed
Dec 6, 2015
1 parent
47d7e02
commit 7920deb
Showing
38 changed files
with
478 additions
and
575 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
<?php | ||
/** | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
namespace bubasuma\simplechat; | ||
|
||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Class BaseAsset | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class BaseAsset extends AssetBundle | ||
{ | ||
public $css = [ | ||
|
@@ -15,7 +26,8 @@ class BaseAsset extends AssetBundle | |
'yii\bootstrap\BootstrapAsset', | ||
]; | ||
|
||
public function init(){ | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->sourcePath = __DIR__ . '/assets'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
namespace bubasuma\simplechat; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: buba | ||
* Date: 18.10.15 | ||
* Time: 10:00 | ||
* Class ConversationAsset | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class ConversationAsset extends AssetBundle | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
namespace bubasuma\simplechat; | ||
|
||
use yii\helpers\ArrayHelper; | ||
use yii\helpers\Html; | ||
use yii\helpers\Json; | ||
use yii\widgets\ListView; | ||
|
||
|
||
/** | ||
* Class ConversationWidget | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class ConversationWidget extends ListView | ||
{ | ||
public $user; | ||
|
@@ -20,10 +31,11 @@ class ConversationWidget extends ListView | |
private $tag; | ||
|
||
|
||
public function registerJs(){ | ||
public function registerJs() | ||
{ | ||
$id = $this->options['id']; | ||
if(!isset($this->clientOptions['selector'])){ | ||
$this->clientOptions['selector'] = '.' . strstr($this->itemOptions['class'],' ',true); | ||
if (!isset($this->clientOptions['selector'])) { | ||
$this->clientOptions['selector'] = '.' . strstr($this->itemOptions['class'], ' ', true); | ||
} | ||
$options = Json::htmlEncode($this->clientOptions); | ||
$user = Json::htmlEncode($this->user); | ||
|
@@ -44,8 +56,8 @@ public function init() | |
if (!isset($this->itemOptions['class'])) { | ||
$this->itemOptions['class'] = 'conv-item'; | ||
} | ||
$this->tag = ArrayHelper::remove($this->options,'tag', 'div'); | ||
echo Html::beginTag($this->tag,$this->options); | ||
$this->tag = ArrayHelper::remove($this->options, 'tag', 'div'); | ||
echo Html::beginTag($this->tag, $this->options); | ||
|
||
} | ||
|
||
|
@@ -73,16 +85,16 @@ public function renderItem($model, $key, $index) | |
$options = $this->itemOptions; | ||
$tag = ArrayHelper::remove($options, 'tag', 'div'); | ||
if ($tag !== false) { | ||
$options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; | ||
$options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string)$key; | ||
$options['data-contact'] = $model['contact_id']; | ||
if(isset($this->clientOptions['unreadCssClass'])){ | ||
if (isset($this->clientOptions['unreadCssClass'])) { | ||
if ($model['new_messages'] > 0) { | ||
Html::addCssClass($options,$this->clientOptions['unreadCssClass']); | ||
Html::addCssClass($options, $this->clientOptions['unreadCssClass']); | ||
} | ||
} | ||
if(isset($this->clientOptions['currentCssClass'])){ | ||
if (isset($this->clientOptions['currentCssClass'])) { | ||
if ($model['contact_id'] == \Yii::$app->request->get('contactId')) { | ||
Html::addCssClass($options,$this->clientOptions['currentCssClass']); | ||
Html::addCssClass($options, $this->clientOptions['currentCssClass']); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: buba | ||
* Date: 24.10.15 | ||
* Time: 10:30 | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
namespace bubasuma\simplechat; | ||
|
||
|
||
use yii\base\Arrayable; | ||
use yii\base\ArrayableTrait; | ||
use yii\base\InvalidConfigException; | ||
use yii\data\ActiveDataProvider; | ||
use yii\db\QueryInterface; | ||
use yii\helpers\ArrayHelper; | ||
|
||
/** | ||
* Class DataProvider | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class DataProvider extends ActiveDataProvider implements Arrayable | ||
{ | ||
use ArrayableTrait; | ||
|
@@ -33,10 +37,10 @@ public function init() | |
} | ||
|
||
$request = \Yii::$app->request; | ||
if($request->post('key')){ | ||
if(!strcmp('history', $request->post('type'))){ | ||
if ($request->post('key')) { | ||
if (!strcmp('history', $request->post('type'))) { | ||
$this->query->andWhere(['<', 'id', $request->post('key')]); | ||
}else{ | ||
} else { | ||
$this->query->andWhere(['>', 'id', $request->post('key')]); | ||
} | ||
} | ||
|
@@ -48,7 +52,7 @@ public function init() | |
protected function prepareTotalCount() | ||
{ | ||
$query = clone $this->query; | ||
return (int) $query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db); | ||
return (int)$query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db); | ||
} | ||
|
||
/** | ||
|
@@ -65,13 +69,13 @@ protected function prepareModels() | |
$query->addOrderBy($sort->getOrders()); | ||
} | ||
|
||
if($this->formatter !== null) { | ||
if ($this->formatter !== null) { | ||
$models = []; | ||
foreach($query->all($this->db) as $index => $model){ | ||
foreach ($query->all($this->db) as $index => $model) { | ||
$models[$index] = call_user_func($this->formatter, $model); | ||
} | ||
return $models; | ||
}else{ | ||
} else { | ||
return $query->all($this->db); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
<?php | ||
/** | ||
* @link http://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license http://www.yiiframework.com/license/ | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
namespace bubasuma\simplechat; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* @author Qiang Xue <[email protected]> | ||
* @since 2.0 | ||
* Class DemoAsset | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class DemoAsset extends AssetBundle | ||
{ | ||
|
@@ -26,7 +28,8 @@ class DemoAsset extends AssetBundle | |
'bubasuma\simplechat\BaseAsset', | ||
]; | ||
|
||
public function init(){ | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->sourcePath = __DIR__ . '/assets'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
namespace bubasuma\simplechat; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: buba | ||
* Date: 18.10.15 | ||
* Time: 10:00 | ||
* Class MessageAsset | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class MessageAsset extends AssetBundle | ||
{ | ||
public $js = [ | ||
'js/messages.js', | ||
]; | ||
|
||
public function init(){ | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->sourcePath = __DIR__ . '/assets'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* @link https://github.com/bubasuma/yii2-simplechat | ||
* @copyright Copyright (c) 2015 bubasuma | ||
* @license http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
namespace bubasuma\simplechat; | ||
|
||
use yii\helpers\ArrayHelper; | ||
use yii\helpers\Html; | ||
use yii\helpers\Json; | ||
use yii\helpers\Url; | ||
use yii\widgets\ListView; | ||
|
||
|
||
/** | ||
* Class MessageWidget | ||
* @package bubasuma\simplechat | ||
* | ||
* @author Buba Suma <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
class MessageWidget extends ListView | ||
{ | ||
/** | ||
|
@@ -26,7 +37,7 @@ class MessageWidget extends ListView | |
|
||
public $formParams = []; | ||
|
||
public $formOptions = ['method'=>'post']; | ||
public $formOptions = ['method' => 'post']; | ||
|
||
public $clientOptions = []; | ||
|
||
|
@@ -37,21 +48,21 @@ class MessageWidget extends ListView | |
|
||
public function renderForm() | ||
{ | ||
$action = ArrayHelper::remove($this->formOptions,'action','/message/' . $this->contact['id']); | ||
$method = ArrayHelper::remove($this->formOptions,'method','post'); | ||
$action = ArrayHelper::remove($this->formOptions, 'action', ''); | ||
$method = ArrayHelper::remove($this->formOptions, 'method', 'post'); | ||
|
||
if(!isset($this->formOptions['id'])){ | ||
if (!isset($this->formOptions['id'])) { | ||
$this->formOptions['id'] = 'msg-form'; | ||
} | ||
|
||
$content = Html::beginForm($action,$method,$this->formOptions); | ||
$content = Html::beginForm($action, $method, $this->formOptions); | ||
|
||
if (is_string($this->formView)) { | ||
$content .= $this->getView()->render($this->formView, array_merge([ | ||
'widget' => $this, | ||
], $this->formParams)); | ||
} else { | ||
$content .= call_user_func($this->formView,$this); | ||
$content .= call_user_func($this->formView, $this); | ||
} | ||
|
||
$content .= Html::endForm(); | ||
|
@@ -60,10 +71,11 @@ public function renderForm() | |
|
||
} | ||
|
||
public function registerJs(){ | ||
public function registerJs() | ||
{ | ||
$id = $this->options['id']; | ||
if(!isset($this->clientOptions['selector'])){ | ||
$this->clientOptions['selector'] = '.' . strstr($this->itemOptions['class'],' ',true); | ||
if (!isset($this->clientOptions['selector'])) { | ||
$this->clientOptions['selector'] = '.' . strstr($this->itemOptions['class'], ' ', true); | ||
} | ||
$this->clientOptions['form'] = '#' . $this->formOptions['id']; | ||
$options = Json::htmlEncode($this->clientOptions); | ||
|
@@ -86,8 +98,8 @@ public function init() | |
if (!isset($this->itemOptions['class'])) { | ||
$this->itemOptions['class'] = 'msg-item'; | ||
} | ||
$this->tag = ArrayHelper::remove($this->options,'tag', 'div'); | ||
echo Html::beginTag($this->tag,$this->options); | ||
$this->tag = ArrayHelper::remove($this->options, 'tag', 'div'); | ||
echo Html::beginTag($this->tag, $this->options); | ||
|
||
} | ||
|
||
|
@@ -116,7 +128,7 @@ public function renderItem($model, $key, $index) | |
$options = $this->itemOptions; | ||
$tag = ArrayHelper::remove($options, 'tag', 'div'); | ||
if ($tag !== false) { | ||
$options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; | ||
$options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string)$key; | ||
|
||
return Html::tag($tag, $content, $options); | ||
} else { | ||
|
@@ -153,6 +165,6 @@ public function getId() | |
{ | ||
$users = [$this->user['id'], $this->contact['id']]; | ||
sort($users); | ||
return md5(implode('&',$users)); | ||
return md5(implode('&', $users)); | ||
} | ||
} |
Oops, something went wrong.