Skip to content

Commit a88b1a0

Browse files
author
roman
committed
first
0 parents  commit a88b1a0

30 files changed

+2324
-0
lines changed

CommentAsset.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace yii2mod\comments;
4+
5+
use yii\web\AssetBundle;
6+
7+
/**
8+
* Class CommentAsset
9+
* @package yii2mod\comments
10+
*/
11+
class CommentAsset extends AssetBundle
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public $sourcePath = '@vendor/yii2mod/yii2-comments/assets';
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public $js = [
22+
'js/comment.js'
23+
];
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public $css = [
29+
'css/comment.css'
30+
];
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public $depends = [
36+
'yii\web\JqueryAsset',
37+
'yii\web\YiiAsset'
38+
];
39+
}

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Yii2 modules & extensions
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Module.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace yii2mod\comments;
4+
5+
use Yii;
6+
use yii2mod\comments\models\CommentModel;
7+
8+
/**
9+
* Class Module
10+
* @package yii2mod\comments
11+
*/
12+
class Module extends \yii\base\Module
13+
{
14+
/**
15+
* @var string module name
16+
*/
17+
public static $name = 'comment';
18+
19+
/**
20+
* @var string the class name of the [[identity]] object.
21+
*/
22+
public $userIdentityClass;
23+
24+
/**
25+
* @var string the class name of the comment model object, by default its yii2mod\comments\models\CommentModel::className();
26+
*/
27+
public $commentModelClass;
28+
29+
/**
30+
* @var string the namespace that controller classes are in.
31+
*/
32+
public $controllerNamespace = 'yii2mod\comments\controllers';
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function init()
38+
{
39+
if (empty($this->userIdentityClass)) {
40+
$this->userIdentityClass = Yii::$app->getUser()->identityClass;
41+
}
42+
43+
if (empty($this->commentModelClass)) {
44+
$this->commentModelClass = CommentModel::className();
45+
}
46+
47+
parent::init();
48+
}
49+
}

README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
Comments module for Yii2
2+
========================
3+
4+
This module provide a comments managing system for Yii2 application.
5+
6+
[![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-comments/v/stable)](https://packagist.org/packages/yii2mod/yii2-comments)
7+
[![Total Downloads](https://poser.pugx.org/yii2mod/yii2-comments/downloads)](https://packagist.org/packages/yii2mod/yii2-comments)
8+
[![License](https://poser.pugx.org/yii2mod/yii2-comments/license)](https://packagist.org/packages/yii2mod/yii2-comments)
9+
[![Build Status](https://travis-ci.org/yii2mod/yii2-comments.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-comments)
10+
11+
Installation
12+
------------
13+
14+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
15+
16+
Either run
17+
18+
```
19+
php composer.phar require --prefer-dist yii2mod/yii2-comments "*"
20+
```
21+
22+
or add
23+
24+
```json
25+
"yii2mod/yii2-comments": "*"
26+
```
27+
28+
to the require section of your composer.json.
29+
30+
31+
Configuration
32+
-----------------------
33+
34+
**Database Migrations**
35+
36+
Before using Comments Widget, we'll also need to prepare the database.
37+
```php
38+
php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations
39+
```
40+
41+
**Module setup**
42+
43+
To access the module, you need to add the following code to your application configuration:
44+
```php
45+
'modules' => [
46+
'comment' => [
47+
'class' => 'yii2mod\comments\Module'
48+
]
49+
]
50+
```
51+
52+
**Comments management section setup**
53+
54+
To access the comments management section, you need to add the following code to your application configuration:
55+
```php
56+
'controllerMap' => [
57+
'comments' => 'yii2mod\comments\controllers\ManageController'
58+
]
59+
```
60+
> Basically the above code must be placed in the `admin` module
61+
62+
You can then access to management section through the following URL:
63+
http://localhost/path/to/index.php?r=comments/index
64+
65+
> If you have added this controller in the module admin, the URL will look like the following
66+
> http://localhost/path/to/index.php?r=admin/comments/index
67+
68+
**Notes:**
69+
> 1) Delete button visible only for user with `admin` role.
70+
71+
> 2) When you delete a comment, all nested comments will be marked as `deleted`.
72+
73+
> 3) For change the any function in the CommentModel you can create your own model and change the property `commentModelClass` in the Comment Module.
74+
75+
> 4) You can implement your own function `getAvatar` in the `userIdentityClass`. Just create the `getAvatar` method in your User model, and return a image path.
76+
```php
77+
public function getAvatar()
78+
{
79+
// return some image path
80+
}
81+
```
82+
> 5) You can implement your own function `getUsername` in the `userIdentityClass`. Just create the `getUsername` method in your User model.
83+
```php
84+
public function getUsername()
85+
{
86+
// your custom code
87+
}
88+
```
89+
90+
Usage
91+
-------------------
92+
**Basic example:**
93+
```php
94+
// the model to which are added comments, for example:
95+
$model = Post::find()->where(['title' => 'some post title'])->one();
96+
97+
<?php echo \yii2mod\comments\widgets\Comment::widget([
98+
'model' => $model,
99+
'relatedTo' => 'User ' . \Yii::$app->user->identity->username . ' commented on the page ' . \yii\helpers\Url::current(), // for example
100+
'maxLevel' => 3, // maximum comments level, level starts from 1, null - unlimited level. Defaults to `7`
101+
'showDeletedComments' => true // show deleted comments. Defaults to `false`.
102+
]); ?>
103+
```
104+
105+
**You can use your own template for render comments:**
106+
107+
```php
108+
<?php echo \yii2mod\comments\widgets\Comment::widget([
109+
'model' => $model,
110+
'commentView' => '@app/views/site/comments/index' //path to your template
111+
]); ?>
112+
```
113+
114+
**Use the following code for multiple widgets on the same page:**
115+
```php
116+
echo \yii2mod\comments\widgets\Comment::widget([
117+
'model' => $model,
118+
]);
119+
120+
echo \yii2mod\comments\widgets\Comment::widget([
121+
'model' => $model2,
122+
'formId' => 'comment-form2',
123+
'pjaxContainerId' => 'unique-pjax-container-id' // also you can set the `pjaxContainerId`
124+
]);
125+
```
126+
127+
## Internationalization
128+
129+
All text and messages introduced in this extension are translatable under category 'yii2mod.comments'.
130+
You may use translations provided within this extension, using following application configuration:
131+
132+
```php
133+
return [
134+
'components' => [
135+
'i18n' => [
136+
'translations' => [
137+
'yii2mod.comments' => [
138+
'class' => 'yii\i18n\PhpMessageSource',
139+
'basePath' => '@yii2mod/comments/messages',
140+
],
141+
// ...
142+
],
143+
],
144+
// ...
145+
],
146+
// ...
147+
];
148+
```
149+
150+
151+
#### Example comments
152+
-----
153+
![Alt text](http://res.cloudinary.com/zfort/image/upload/v1467214676/comments-preview.png "Example comments")

0 commit comments

Comments
 (0)