Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Mar 9, 2021
0 parents commit bfd068f
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# composer package patch
vendor/
composer.lock

# Windows Files
Thumbs.db

# OSX
.DS_Store
29 changes: 29 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, dynamikaweb
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
dynamikaweb/yii2-chat
===========================
[![Latest Stable Version](https://img.shields.io/github/v/release/dynamikaweb/yii2-chat)](https://github.com/dynamikaweb/yii2-chat/releases)
[![Total Downloads](https://poser.pugx.org/dynamikaweb/yii2-chat/downloads)](https://packagist.org/packages/dynamikaweb/yii2-chat)
[![License](https://img.shields.io/github/license/dynamikaweb/yii2-chat)](https://github.com/dynamikaweb/yii2-chat/blob/master/LICENSE)

Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```SHELL
$ composer require dynamikaweb/yii2-chat "*"
```

or add

```JSON
"dynamikaweb/yii2-chat": "*"
```

to the `require` section of your `composer.json` file.

How to Use
----------
```PHP
use dynamikaweb\chat\Chat;

echo ChatView::widget([
'dataProvider' => $dataProvider,
'receive' => function ($model, $key, $index) {
return [
'right' => $index % 2,
'title' => $model->title,
'message' => $model->message
];
}
]);
```
4 changes: 4 additions & 0 deletions assets/message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span class="dynamika-chat-{{sign}}">
<a href="#{{key}}" id="{{key}}">{{title}}</a>
<p>{{message}}</p>
</span>
3 changes: 3 additions & 0 deletions assets/messenger.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<section class="dynamika-chat">
{{messages}}
</section>
44 changes: 44 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.dynamika-chat {
width: 100%;
display: flex;
flex-direction: column;
}

.dynamika-chat a {
display: inline-block;
margin-top: -16px;
text-decoration: none;
color: black;
}

.dynamika-chat span {
margin: 16px 8;
border-radius: 32px;
display: inline-block;
}

.dynamika-chat p {
text-align: justify;
padding-bottom: 8px;
padding: 16px;
}

.dynamika-chat-right {
background-color: rgba(174, 213, 7, .75);
margin-left: 25% !important;
border-top-right-radius: 0px !important;
}

.dynamika-chat-left {
background-color: rgba(128,128,128, 0.75);
margin-right: 25% !important;
border-top-left-radius: 0px !important;
}

.dynamika-chat-right a {
float: right;
}

.dynamika-chat-left a {
float: left;
}
36 changes: 36 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "dynamikaweb/yii2-chat",
"description": "Web chat widget list view",
"type": "yii2-extension",
"keywords": [
"dynamika",
"yii",
"yii2",
"yii 2",
"chat",
"widget"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Rodrigo Dornelles",
"email": "[email protected]",
"role": "Developer"
}
],
"support": {
"issues": "http://github.com/dynamikaweb/yii2-chat/issues",
"source": "http://github.com/dynamikaweb/yii2-chat"
},
"require": {
"php": ">=5.5.0",
"yiisoft/yii2": "*"
},
"minimum-stability": "dev",
"prefer-stable": false,
"autoload": {
"psr-4": {
"dynamikaweb\\chat\\": "src"
}
}
}
49 changes: 49 additions & 0 deletions src/Chat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace dynamikaweb\chat;

use yii\widgets\BaseListView;
use yii\helpers\Inflector;
use yii\helpers\Html;

class Chat extends BaseListView
{
public $receive;

public $file_messenger = '@vendor/dynamikaweb/yii2-chat/assets/messenger.html';
public $file_message = '@vendor/dynamikaweb/yii2-chat/assets/message.html';

/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
ChatAsset::register($this->view);
}

public function renderItems()
{
$models = $this->dataProvider->getModels();
$keys = $this->dataProvider->getKeys();
$rows = [];

foreach (array_values($models) as $index => $model) {
$rows[] = $this->renderItem($model, $keys[$index], $index);
}

return strtr($this->view->renderFile($this->file_messenger), [
'{{messages}}' => implode("\n", $rows)
]);
}

public function renderItem($model, $key, $index)
{
$receive = (object) call_user_func($this->receive, $model, $key, $index, $this);
return strtr($this->view->renderFile($this->file_message), [
'{{key}}' => Inflector::slug("{$receive->title}-{$key}"),
'{{sign}}' => $receive->right? 'right': 'left',
'{{message}}' => $receive->message,
'{{title}}' => $receive->title
]);
}
}
14 changes: 14 additions & 0 deletions src/ChatAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace dynamikaweb\chat;

use yii\web\AssetBundle;

class ChatAsset extends AssetBundle
{
public $sourcePath = '@vendor/dynamikaweb/yii2-chat/assets';

public $css = [
'style.css'
];
}

0 comments on commit bfd068f

Please sign in to comment.