Skip to content

Commit b77e39f

Browse files
committed
first publishing2
1 parent 168751b commit b77e39f

File tree

5 files changed

+17
-114
lines changed

5 files changed

+17
-114
lines changed

Poll.php

+3-49
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,6 @@ private function createResult() {
7474
return $modelsaved;
7575
}
7676

77-
// private function createResult($model) {
78-
// $modelsaved = false;
79-
// $answers = $model->id_answer;
80-
// foreach ($answers as $id_answer) {
81-
// $modelMulti = new PollsResult();
82-
// $modelMulti->id_user = $model->id_user;
83-
// $modelMulti->id_poll = $model->id_poll;
84-
// $modelMulti->num = $model->num;
85-
// $modelMulti->create_at = $model->create_at;
86-
// $modelMulti->ip = $model->ip;
87-
// $modelMulti->host = $model->host;
88-
// $modelMulti->id_answer = $id_answer;
89-
//
90-
// if (!$modelMulti->save()) {
91-
// $modelsaved = false;
92-
// print_r($modelMulti->errors);
93-
// return false;
94-
// } else {
95-
//
96-
// $modelsaved = true;
97-
// }
98-
// }
99-
// return $modelsaved;
100-
// }
101-
10277
/**
10378
* set $model properties
10479
* @param type $model
@@ -123,26 +98,8 @@ private function setModel() {
12398
$this->model->id_user = Yii::$app->user->getId();
12499
}
125100
}
126-
//return $this->model;
127101
}
128102

129-
// private function setModel($model) {
130-
// $model->id_poll = $this->pollsProvider->id;
131-
// $model->num = 1;
132-
// $model->create_at = date("Y-m-d H:i:s");
133-
// $model->ip = Yii::$app->request->getUserIP();
134-
// $model->host = Yii::$app->request->getUserHost();
135-
// if ($this->pollsProvider->anonymous) {
136-
// $model->scenario = PollsResult::SCENARIO_ANONYMOUS;
137-
// $model->id_user = 0;
138-
// } else {
139-
// if (!Yii::$app->user->isGuest) {
140-
// $model->id_user = Yii::$app->user->getId();
141-
// }
142-
// }
143-
// return $model;
144-
// }
145-
146103
/**
147104
* Return poll for voting
148105
* @return type Polls
@@ -153,7 +110,7 @@ public function getProvider() {
153110
} else {
154111
$pollVote = Polls::getPollToday();
155112
if (isset($pollVote)) {
156-
$this->idPoll = $pollVote->id_poll;
113+
$this->idPoll = $pollVote->id;
157114
}
158115
return $pollVote;
159116
}
@@ -168,7 +125,7 @@ public function run() {
168125
PollAsset::register($this->getView());
169126

170127
$this->model = new PollsResult();
171-
$this->pollsProvider = $this->getProvider();
128+
$this->pollsProvider = $this->getProvider();//barbaric of course
172129
if (!isset($this->pollsProvider)) {
173130
return;
174131
}
@@ -194,16 +151,13 @@ public function run() {
194151
return; //if show result wasn't allowed nothing would happen
195152
}
196153
$searchModel = new PollsResultSearch();
197-
198-
// $dataProvider = PollsResult::getResults($this->idPoll);//
199-
$dataProvider = $searchModel->search(['id_poll' => $this->idPoll]); //$searchModel->search(Yii::$app->request->queryParams);
154+
$dataProvider = $searchModel->search(['id_poll' => $this->idPoll]);
200155
if (!isset($this->resultView)) {
201156
return \Yii::$app->controller->renderPartial('@vendor/lslsoft/yii2-poll/views/chart', ['dataProvider' => $dataProvider,
202157
'searchModel' => $searchModel,
203158
'question' => $this->pollsProvider->question,
204159
'sumRes' => $this->model->num]);
205160
}
206-
207161
return \Yii::$app->controller->renderPartial('@vendor/lslsoft/yii2-poll/views/table', ['dataProvider' => $dataProvider,
208162
'searchModel' => $searchModel,
209163
'question' => $this->pollsProvider->question,

README.md

+7-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
This is simple poll widget for yii2 framework.
44
You can use both single and multiple answer.
55

6+
([More information lslsoft.com](http://lslsoft.com/2017/01/22/simple-poll-widget-for-yii2/)
7+
68
### Installing
79

810
Yii2-poll can be installed using composer. Run following command to download and install yii2-poll:
@@ -30,7 +32,7 @@ to apply migrations add in your config file
3032
```php
3133
'migrate-lslsoft-create' => [
3234
'class' => 'yii\console\controllers\MigrateController',
33-
'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations',
35+
'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations/create',
3436
'migrationTable' => 'migration_lslsoft_create',
3537
],
3638
```
@@ -47,7 +49,7 @@ and for inserting some sample data:
4749
```php
4850
'migrate-lslsoft-insert' => [
4951
'class' => 'yii\console\controllers\MigrateController',
50-
'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations',
52+
'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations/insert',
5153
'migrationTable' => 'migration_lslsoft_insert',
5254
],
5355

@@ -151,7 +153,7 @@ CREATE TABLE `polls_result` (
151153
```
152154
153155
154-
<<<<<<< HEAD
156+
155157
### Author
156158
157159
* **Leonid Lyalin**
@@ -160,33 +162,14 @@ CREATE TABLE `polls_result` (
160162
161163
This project is licensed under the BSD-3-Clause
162164
163-
### Acknowledgments
164-
=======
165-
166-
## Built With
167-
168-
* [Dropwizard](http://www.dropwizard.io/1.0.2/docs/) - The web framework used
169-
* [Maven](https://maven.apache.org/) - Dependency Management
170-
* [ROME](https://rometools.github.io/rome/) - Used to generate RSS Feeds
171-
172-
## Contributing
173165
174-
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
175-
176-
## Versioning
177-
178-
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).
179-
180-
## Authors
166+
### Authors
181167
182168
* **Leonid Lyalin**
183169
184-
## License
185170
186-
This project is licensed under the BSD-3-Clause
171+
### Acknowledgments
187172
188-
## Acknowledgments
189-
>>>>>>> origin/master
190173
191174
* Thanks to all Yii framework team for inspiration and special thanks to Alexander Makarov (@samdark)
192175
* Thanks to @Insolita for magic yii2-migrik

models/Polls.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function getPollToday() {
9898

9999
/**
100100
* Return poll according to id
101-
* @param type $id - id of poll
101+
* @param type $id_poll - id of poll
102102
* @return type poll
103103
*/
104104
public static function getIdPoll($id_poll) {

models/PollsResult.php

+6-25
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ class PollsResult extends \yii\db\ActiveRecord {
3535
*/
3636
const SCENARIO_ANONYMOUS = 'anonymous';
3737

38-
/**
39-
*
40-
* @property array for checkboxlist checked items
41-
*
42-
* @todo make this property to work in form checkBoxList instead of 'id_poll'
43-
*/
44-
//public $result;
45-
4638
public static function tableName() {
4739
return 'polls_result';
4840
}
@@ -63,18 +55,6 @@ public function rules() {
6355
];
6456
}
6557

66-
/**
67-
*
68-
* @return scenario for
69-
*/
70-
// public function scenarios()
71-
// {
72-
// return [
73-
// 'default' =>['num', 'id_poll', 'id_answer', 'id_user'],
74-
// self::SCENARIO_SINGLE => ['num', 'id_poll', 'id_answer', 'id_user'],
75-
// self::SCENARIO_MULTIPLE => ['num', 'id_poll', 'id_user'],
76-
// ];
77-
// }
7858
/**
7959
* @inheritdoc
8060
* @todo change 'app'/'polls'
@@ -144,11 +124,12 @@ public static function getMaxNum($id_poll) {
144124
->where('id_poll=:id_poll', ['id_poll' => $id_poll])
145125
->max('num');
146126
}
147-
/**
148-
* Return joined number of records
149-
* @param integer $id_poll
150-
* @return PollsResult set of records
151-
*/
127+
128+
/**
129+
* Return joined number of records
130+
* @param integer $id_poll
131+
* @return PollsResult set of records
132+
*/
152133
public static function getResults($id_poll) {
153134
return self::find()
154135
->select('id_answer, count(`id_answer`) as `res`')

models/PollsResultSearch.php

-15
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,10 @@ public function search($params) {
4646
->groupBy(['id_answer'])
4747
->where(['polls_result.id_poll'=>$params['id_poll']]);
4848

49-
// add conditions that should always apply here
50-
5149
$dataProvider = new ActiveDataProvider([
5250
'query' => $query,
5351
]);
5452

55-
// if (!($this->load($params) && $this->validate())) {
56-
// // uncomment the following line if you do not want to return any records when validation fails
57-
// // $query->where('0=1');
58-
// $query->where(['polls_result.id_poll'=>$params['id_poll']]);
59-
// $query->joinWith(['idAnswer']);
60-
// return $dataProvider;
61-
// }
62-
63-
// $query->joinWith('idAnswer');
64-
//
65-
// $query->groupBy(['id_answer']);
66-
67-
6853
return $dataProvider;
6954
}
7055

0 commit comments

Comments
 (0)