Skip to content

Commit 16e0c24

Browse files
author
igor-chepurnoi
committed
update README, fix depends
1 parent 8d32cfe commit 16e0c24

File tree

4 files changed

+70
-63
lines changed

4 files changed

+70
-63
lines changed

README.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
Star Rating Widget for Yii 2
2-
============================
1+
<p align="center">
2+
<a href="https://github.com/yiisoft" target="_blank">
3+
<img src="https://avatars0.githubusercontent.com/u/993323" height="100px">
4+
</a>
5+
<h1 align="center">Star Rating Widget for Yii 2</h1>
6+
<br>
7+
</p>
8+
39
Star Rating widget based on Raty extension https://github.com/wbotelhos/raty
410

511
[![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-star-rating/v/stable)](https://packagist.org/packages/yii2mod/yii2-star-rating) [![Total Downloads](https://poser.pugx.org/yii2mod/yii2-star-rating/downloads)](https://packagist.org/packages/yii2mod/yii2-star-rating) [![License](https://poser.pugx.org/yii2mod/yii2-star-rating/license)](https://packagist.org/packages/yii2mod/yii2-star-rating)
@@ -17,7 +23,7 @@ php composer.phar require --prefer-dist yii2mod/yii2-star-rating "*"
1723

1824
or add
1925

20-
```json
26+
```
2127
"yii2mod/yii2-star-rating": "*"
2228
```
2329

@@ -29,26 +35,25 @@ Once the extension is installed, simply add widget to your page as follows:
2935

3036
1) Usage with ActiveForm and model
3137
```php
32-
echo $form->field($model, 'attribute')->widget(\yii2mod\rating\StarRating::className(), [
33-
'options' => [
34-
// Your additional tag options
35-
],
36-
'clientOptions' => [
37-
// Your client options
38-
]
39-
]);
40-
41-
```
38+
echo $form->field($model, 'attribute')->widget(\yii2mod\rating\StarRating::class, [
39+
'options' => [
40+
// Your additional tag options
41+
],
42+
'clientOptions' => [
43+
// Your client options
44+
],
45+
]);
46+
```
4247

4348
2) Usage without a model
4449
```php
45-
echo \yii2mod\rating\StarRating::widget([
46-
'name' => "input_name",
47-
'value' => 5,
48-
'clientOptions' => [
49-
// Your client options
50-
]
51-
]);
50+
echo \yii2mod\rating\StarRating::widget([
51+
'name' => 'input_name',
52+
'value' => 5,
53+
'clientOptions' => [
54+
// Your client options
55+
],
56+
]);
5257
```
5358

5459
Star Rating Options

StarRating.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22

33
namespace yii2mod\rating;
44

5-
use yii\widgets\InputWidget;
6-
use Yii;
75
use yii\helpers\Html;
86
use yii\helpers\Json;
7+
use yii\widgets\InputWidget;
98

109
/**
1110
* Class StarRating
12-
* @package yii2mod\rating
1311
*
14-
* Usage example:
15-
* ~~~
16-
* \yii2mod\rating\StarRating::widget([
17-
* 'name' => "input_name",
18-
* 'value' => 5,
19-
* 'clientOptions' => [
20-
* // Your client options
21-
* ]
22-
* ]);
23-
* ~~~
12+
* @package yii2mod\rating
2413
*/
2514
class StarRating extends InputWidget
2615
{
@@ -36,13 +25,12 @@ class StarRating extends InputWidget
3625

3726
/**
3827
* Init widget, configure client options
39-
*
40-
* @return void
4128
*/
4229
public function init()
4330
{
44-
$this->configureClientOptions();
4531
parent::init();
32+
33+
$this->configureClientOptions();
4634
}
4735

4836
/**
@@ -53,6 +41,7 @@ public function init()
5341
public function run()
5442
{
5543
$this->registerAssets();
44+
5645
return Html::tag('div', '', $this->options);
5746
}
5847

@@ -71,21 +60,21 @@ protected function registerAssets()
7160

7261
/**
7362
* Configure client options
74-
*
75-
* @return void
7663
*/
7764
protected function configureClientOptions()
7865
{
7966
$assetBundle = StarRatingAsset::register($this->view);
67+
8068
if (!isset($this->clientOptions['score'])) {
8169
$this->clientOptions['score'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
8270
}
71+
8372
if (!isset($this->clientOptions['path'])) {
8473
$this->clientOptions['path'] = $assetBundle->baseUrl . $this->assetBundleImagePath;
8574
}
75+
8676
if (!isset($this->clientOptions['scoreName']) && $this->hasModel()) {
8777
$this->clientOptions['scoreName'] = Html::getInputName($this->model, $this->attribute);
8878
}
8979
}
90-
9180
}

StarRatingAsset.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* Class StarRatingAsset
9+
*
910
* @package yii2mod\rating
1011
*/
1112
class StarRatingAsset extends AssetBundle
@@ -14,22 +15,25 @@ class StarRatingAsset extends AssetBundle
1415
* @var string
1516
*/
1617
public $sourcePath = '@bower/raty';
18+
1719
/**
1820
* @var array
1921
*/
2022
public $css = [
21-
'lib/jquery.raty.css'
23+
'lib/jquery.raty.css',
2224
];
25+
2326
/**
2427
* @var array
2528
*/
2629
public $js = [
27-
'lib/jquery.raty.js'
30+
'lib/jquery.raty.js',
2831
];
32+
2933
/**
3034
* @var array
3135
*/
3236
public $depends = [
33-
'yii\web\YiiAsset',
37+
'yii\web\JqueryAsset',
3438
];
35-
}
39+
}

composer.json

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
{
2-
"name": "yii2mod/yii2-star-rating",
3-
"description": "Star rating widget based on jQuery Raty https://github.com/wbotelhos/raty",
4-
"type": "yii2-extension",
5-
"keywords": ["yii2", "module"],
6-
"license": "MIT",
7-
"authors": [
8-
{
9-
"name": "Igor Chepurnoy",
10-
"email": "igorzfort@gmail.com"
11-
}
12-
],
13-
"require": {
14-
"yiisoft/yii2": "*",
15-
"bower-asset/raty" : "*"
16-
},
17-
"autoload": {
18-
"psr-4": {
19-
"yii2mod\\rating\\": ""
20-
}
21-
}
2+
"name": "yii2mod/yii2-star-rating",
3+
"description": "Star rating widget based on jQuery Raty https://github.com/wbotelhos/raty",
4+
"type": "yii2-extension",
5+
"keywords": [
6+
"yii2",
7+
"module"
8+
],
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Igor Chepurnoy",
13+
"email": "igorzfort@gmail.com"
14+
}
15+
],
16+
"require": {
17+
"yiisoft/yii2": "*",
18+
"bower-asset/raty": "*"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"yii2mod\\rating\\": ""
23+
}
24+
},
25+
"repositories": [
26+
{
27+
"type": "composer",
28+
"url": "https://asset-packagist.org"
29+
}
30+
]
2231
}

0 commit comments

Comments
 (0)