Skip to content

Commit

Permalink
comment + lisense + author
Browse files Browse the repository at this point in the history
  • Loading branch information
bubasuma committed Dec 6, 2015
1 parent 47d7e02 commit 7920deb
Show file tree
Hide file tree
Showing 38 changed files with 478 additions and 575 deletions.
6 changes: 0 additions & 6 deletions .directory

This file was deleted.

16 changes: 14 additions & 2 deletions BaseAsset.php
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 = [
Expand All @@ -15,7 +26,8 @@ class BaseAsset extends AssetBundle
'yii\bootstrap\BootstrapAsset',
];

public function init(){
public function init()
{
parent::init();
$this->sourcePath = __DIR__ . '/assets';
}
Expand Down
15 changes: 10 additions & 5 deletions ConversationAsset.php
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
{
Expand Down
36 changes: 24 additions & 12 deletions ConversationWidget.php
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;
Expand All @@ -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);
Expand All @@ -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);

}

Expand Down Expand Up @@ -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']);
}
}

Expand Down
30 changes: 17 additions & 13 deletions DataProvider.php
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;
Expand All @@ -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')]);
}
}
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

Expand Down
17 changes: 10 additions & 7 deletions DemoAsset.php
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
{
Expand All @@ -26,7 +28,8 @@ class DemoAsset extends AssetBundle
'bubasuma\simplechat\BaseAsset',
];

public function init(){
public function init()
{
parent::init();
$this->sourcePath = __DIR__ . '/assets';
}
Expand Down
18 changes: 12 additions & 6 deletions MessageAsset.php
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';
}
Expand Down
42 changes: 27 additions & 15 deletions MessageWidget.php
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
{
/**
Expand All @@ -26,7 +37,7 @@ class MessageWidget extends ListView

public $formParams = [];

public $formOptions = ['method'=>'post'];
public $formOptions = ['method' => 'post'];

public $clientOptions = [];

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);

}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -153,6 +165,6 @@ public function getId()
{
$users = [$this->user['id'], $this->contact['id']];
sort($users);
return md5(implode('&',$users));
return md5(implode('&', $users));
}
}
Loading

0 comments on commit 7920deb

Please sign in to comment.