@@ -19,6 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | class Migrator extends \yii\console\controllers\MigrateController |
21 | 21 | { |
22 | + /** |
|
23 | + * @param string $id |
|
24 | + */ |
|
22 | 25 | public function __construct($id, $module, $config = []) |
23 | 26 | { |
24 | 27 | parent::__construct($id, $module, $config); // TODO: Change the autogenerated stub |
@@ -64,7 +67,7 @@ discard block |
||
64 | 67 | |
65 | 68 | /** |
66 | 69 | * Lists all TaxonomyDef models. |
67 | - * @return mixed |
|
70 | + * @return string |
|
68 | 71 | * @throws InvalidConfigException |
69 | 72 | */ |
70 | 73 | public function actionIndex() |
@@ -84,7 +87,7 @@ discard block |
||
84 | 87 | /** |
85 | 88 | * Displays a single TaxonomyDef model. |
86 | 89 | * @param integer $id |
87 | - * @return mixed |
|
90 | + * @return string |
|
88 | 91 | */ |
89 | 92 | public function actionView($id) |
90 | 93 | { |
@@ -157,7 +160,7 @@ discard block |
||
157 | 160 | * Deletes an existing TaxonomyDef model. |
158 | 161 | * If deletion is successful, the browser will be redirected to the 'index' page. |
159 | 162 | * @param integer $id |
160 | - * @return mixed |
|
163 | + * @return \yii\web\Response |
|
161 | 164 | */ |
162 | 165 | public function actionDelete($id) |
163 | 166 | { |
@@ -8,7 +8,6 @@ |
||
8 | 8 | use nkostadinov\taxonomy\models\TaxonomyDefSearch; |
9 | 9 | use yii\base\InvalidConfigException; |
10 | 10 | use yii\data\ActiveDataProvider; |
11 | -use yii\helpers\Url; |
|
12 | 11 | use yii\web\Controller; |
13 | 12 | use yii\web\NotFoundHttpException; |
14 | 13 | use yii\filters\VerbFilter; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | ob_start(); |
30 | 30 | //$this->migrationPath = Yii::getAlias($migrationPath); |
31 | - if($this->beforeAction('up')) |
|
31 | + if ($this->beforeAction('up')) |
|
32 | 32 | $this->migrateUp($class); |
33 | 33 | $result = ob_get_contents(); |
34 | 34 | return $result; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | { |
39 | 39 | ob_start(); |
40 | 40 | //$this->migrationPath = Yii::getAlias($migrationPath); |
41 | - if($this->beforeAction('down')) |
|
41 | + if ($this->beforeAction('down')) |
|
42 | 42 | $this->migrateDown($class); |
43 | 43 | $result = ob_get_contents(); |
44 | 44 | return $result; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function actionIndex() |
71 | 71 | { |
72 | - if(!$this->getComponent()->isInstalled()) |
|
72 | + if (!$this->getComponent()->isInstalled()) |
|
73 | 73 | throw new InvalidConfigException("Please run the migration first!"); |
74 | 74 | |
75 | 75 | $searchModel = new TaxonomyDefSearch(); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | public function getComponent() |
194 | 194 | { |
195 | - if(\Yii::$app->has($this->module->component)) |
|
195 | + if (\Yii::$app->has($this->module->component)) |
|
196 | 196 | return \Yii::$app->{$this->module->component}; |
197 | 197 | else |
198 | 198 | throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})"); |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | |
201 | 201 | public function actionInstall() |
202 | 202 | { |
203 | - if(!$this->getComponent()->isInstalled() and \Yii::$app->request->isPost) { |
|
203 | + if (!$this->getComponent()->isInstalled() and \Yii::$app->request->isPost) { |
|
204 | 204 | //start installation |
205 | - if($this->getComponent()) { |
|
205 | + if ($this->getComponent()) { |
|
206 | 206 | $this->getComponent()->install(); |
207 | 207 | |
208 | - $this->redirect(['/'.$this->module->id . '/' . $this->id . '/index']); |
|
208 | + $this->redirect(['/'.$this->module->id.'/'.$this->id.'/index']); |
|
209 | 209 | } else |
210 | 210 | throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})"); |
211 | 211 | } |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | { |
29 | 29 | ob_start(); |
30 | 30 | //$this->migrationPath = Yii::getAlias($migrationPath); |
31 | - if($this->beforeAction('up')) |
|
32 | - $this->migrateUp($class); |
|
31 | + if($this->beforeAction('up')) { |
|
32 | + $this->migrateUp($class); |
|
33 | + } |
|
33 | 34 | $result = ob_get_contents(); |
34 | 35 | return $result; |
35 | 36 | } |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | ob_start(); |
40 | 41 | //$this->migrationPath = Yii::getAlias($migrationPath); |
41 | - if($this->beforeAction('down')) |
|
42 | - $this->migrateDown($class); |
|
42 | + if($this->beforeAction('down')) { |
|
43 | + $this->migrateDown($class); |
|
44 | + } |
|
43 | 45 | $result = ob_get_contents(); |
44 | 46 | return $result; |
45 | 47 | } |
@@ -69,8 +71,9 @@ discard block |
||
69 | 71 | */ |
70 | 72 | public function actionIndex() |
71 | 73 | { |
72 | - if(!$this->getComponent()->isInstalled()) |
|
73 | - throw new InvalidConfigException("Please run the migration first!"); |
|
74 | + if(!$this->getComponent()->isInstalled()) { |
|
75 | + throw new InvalidConfigException("Please run the migration first!"); |
|
76 | + } |
|
74 | 77 | |
75 | 78 | $searchModel = new TaxonomyDefSearch(); |
76 | 79 | $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
@@ -192,10 +195,11 @@ discard block |
||
192 | 195 | |
193 | 196 | public function getComponent() |
194 | 197 | { |
195 | - if(\Yii::$app->has($this->module->component)) |
|
196 | - return \Yii::$app->{$this->module->component}; |
|
197 | - else |
|
198 | - throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})"); |
|
198 | + if(\Yii::$app->has($this->module->component)) { |
|
199 | + return \Yii::$app->{$this->module->component}; |
|
200 | + } else { |
|
201 | + throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})"); |
|
202 | + } |
|
199 | 203 | } |
200 | 204 | |
201 | 205 | public function actionInstall() |
@@ -206,8 +210,9 @@ discard block |
||
206 | 210 | $this->getComponent()->install(); |
207 | 211 | |
208 | 212 | $this->redirect(['/'.$this->module->id . '/' . $this->id . '/index']); |
209 | - } else |
|
210 | - throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})"); |
|
213 | + } else { |
|
214 | + throw new InvalidConfigException("Cannot find taxonomy component({$this->module->component})"); |
|
215 | + } |
|
211 | 216 | } |
212 | 217 | return $this->render('install'); |
213 | 218 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace nkostadinov\taxonomy\models; |
4 | 4 | |
5 | -use Yii; |
|
6 | 5 | use yii\base\Model; |
7 | 6 | use yii\data\ActiveDataProvider; |
8 | 7 | use nkostadinov\taxonomy\models\TaxonomyDef; |
@@ -18,9 +18,9 @@ |
||
18 | 18 | { |
19 | 19 | $this->joinTables(); |
20 | 20 | |
21 | - if(!empty($tags)) |
|
21 | + if (!empty($tags)) |
|
22 | 22 | $this->getQuery() |
23 | - ->andFilterWhere([ TaxonomyTerms::tableName() . '.term' => $tags ]); |
|
23 | + ->andFilterWhere([TaxonomyTerms::tableName().'.term' => $tags]); |
|
24 | 24 | |
25 | 25 | return $this->getQuery(); |
26 | 26 | } |
@@ -18,9 +18,10 @@ |
||
18 | 18 | { |
19 | 19 | $this->joinTables(); |
20 | 20 | |
21 | - if(!empty($tags)) |
|
22 | - $this->getQuery() |
|
21 | + if(!empty($tags)) { |
|
22 | + $this->getQuery() |
|
23 | 23 | ->andFilterWhere([ TaxonomyTerms::tableName() . '.term' => $tags ]); |
24 | + } |
|
24 | 25 | |
25 | 26 | return $this->getQuery(); |
26 | 27 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * User: Phreak |
|
3 | + * User: Phreak |
|
4 | 4 | * Date: 13.02.2015 |
5 | 5 | * Time: 09:31 ч. |
6 | 6 | */ |
@@ -22,8 +22,8 @@ |
||
22 | 22 | |
23 | 23 | /** @var ActiveRecord $this->owner */ |
24 | 24 | $this->getQuery() |
25 | - ->leftJoin($this->taxonomy->table, $this->taxonomy->table . '.object_id = ' . $model::tableName() . '.id') |
|
26 | - ->leftJoin(TaxonomyTerms::tableName(), TaxonomyTerms::tableName() . '.id = ' . $this->taxonomy->table . '.term_id'); |
|
25 | + ->leftJoin($this->taxonomy->table, $this->taxonomy->table.'.object_id = '.$model::tableName().'.id') |
|
26 | + ->leftJoin(TaxonomyTerms::tableName(), TaxonomyTerms::tableName().'.id = '.$this->taxonomy->table.'.term_id'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -74,8 +74,9 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | public function canInstall() { |
77 | - if(!$this->getTable()) |
|
78 | - return 'Missing "table" property'; |
|
77 | + if(!$this->getTable()) { |
|
78 | + return 'Missing "table" property'; |
|
79 | + } |
|
79 | 80 | return true; |
80 | 81 | } |
81 | 82 | |
@@ -95,10 +96,12 @@ discard block |
||
95 | 96 | |
96 | 97 | public function getRefTableName() |
97 | 98 | { |
98 | - if(strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name |
|
99 | + if(strpos($this->refTable, '\\') === FALSE) { |
|
100 | + //not an AR class but a table name |
|
99 | 101 | return $this->refTable; |
100 | - else |
|
101 | - return call_user_func([$this->refTable, 'tableName']); |
|
102 | + } else { |
|
103 | + return call_user_func([$this->refTable, 'tableName']); |
|
104 | + } |
|
102 | 105 | } |
103 | 106 | |
104 | 107 | public function getTable() |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | if ($object_id) { |
23 | 23 | $query->innerJoin($this->table, $this->table . '.term_id = taxonomy_terms.id') |
24 | - ->onCondition("$this->table.object_id = $object_id"); |
|
24 | + ->onCondition("$this->table.object_id = $object_id"); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | return ArrayHelper::getColumn($query->all(), 'term'); |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | |
36 | 36 | public function removeTerm($object_id, $params = []) |
37 | 37 | { |
38 | - if(empty($params)) { |
|
38 | + if (empty($params)) { |
|
39 | 39 | $params = $this->getTerms($object_id); |
40 | 40 | } |
41 | 41 | |
42 | - foreach($params as $item) { |
|
42 | + foreach ($params as $item) { |
|
43 | 43 | $term = $this->getTaxonomyTerm($item); |
44 | 44 | $data['term_id'] = $term->id; |
45 | 45 | $data['object_id'] = $object_id; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $this->getDb()->createCommand()->delete($this->table, $data)->execute(); |
50 | 50 | |
51 | 51 | $term->updateCounters(['total_count' => -1]); |
52 | - Taxonomydef::updateAllCounters(['total_count' => -1], [ 'id' => $this->id ]); |
|
52 | + Taxonomydef::updateAllCounters(['total_count' => -1], ['id' => $this->id]); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | ->andFilterWhere(['taxonomy_terms.term' => $name]); |
63 | 63 | |
64 | 64 | if ($object_id) { |
65 | - $query->innerJoin($this->table, $this->table . '.term_id = taxonomy_terms.id') |
|
65 | + $query->innerJoin($this->table, $this->table.'.term_id = taxonomy_terms.id') |
|
66 | 66 | ->onCondition("$this->table.object_id = $object_id"); |
67 | 67 | } |
68 | 68 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | public function canInstall() { |
110 | - if(!$this->getTable()) |
|
110 | + if (!$this->getTable()) |
|
111 | 111 | return 'Missing "table" property'; |
112 | 112 | return true; |
113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | public function getTaxonomyTerm($name, $create = true) |
116 | 116 | { |
117 | 117 | $term = TaxonomyTerms::findOne(['term'=>$name, 'taxonomy_id' => $this->id]); |
118 | - if($create and !isset($term)) { |
|
118 | + if ($create and !isset($term)) { |
|
119 | 119 | $term = new TaxonomyTerms(); |
120 | 120 | $term->taxonomy_id = $this->id; |
121 | 121 | $term->term = $name; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | public function getRefTableName() |
130 | 130 | { |
131 | - if(strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name |
|
131 | + if (strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name |
|
132 | 132 | return $this->refTable; |
133 | 133 | else |
134 | 134 | return call_user_func([$this->refTable, 'tableName']); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if (!preg_match('/^\w+$/', $this->name)) { |
150 | 150 | throw new Exception('The migration name should contain letters, digits and/or underscore characters only.'); |
151 | 151 | } |
152 | - $name = 'm' . gmdate('ymd_His') . '_' . $this->name; |
|
152 | + $name = 'm'.gmdate('ymd_His').'_'.$this->name; |
|
153 | 153 | return $name; |
154 | 154 | } |
155 | 155 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | |
159 | 159 | $name = $this->getMigrationFile(); |
160 | - $file = Yii::getAlias($this->migrationPath . DIRECTORY_SEPARATOR . $name . '.php'); |
|
160 | + $file = Yii::getAlias($this->migrationPath.DIRECTORY_SEPARATOR.$name.'.php'); |
|
161 | 161 | |
162 | 162 | //$data = get_object_vars($this); |
163 | 163 | $data = []; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $data['migration'] = $name; |
169 | 169 | |
170 | 170 | $this->migration = $name; |
171 | - $content = Yii::$app->getView()->renderFile(Yii::getAlias($this->templateFile), [ 'data' => $data ]); |
|
171 | + $content = Yii::$app->getView()->renderFile(Yii::getAlias($this->templateFile), ['data' => $data]); |
|
172 | 172 | file_put_contents($file, $content); |
173 | 173 | return $name; |
174 | 174 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | $message = Yii::$app->session->getFlash('info'); |
14 | 14 | ?> |
15 | 15 | <div class="taxonomy-def-index"> |
16 | - <?php if(isset($message)) |
|
16 | + <?php if (isset($message)) |
|
17 | 17 | echo Alert::widget([ |
18 | 18 | 'options' => [ |
19 | 19 | 'class' => 'alert-info', |
@@ -13,13 +13,14 @@ |
||
13 | 13 | $message = Yii::$app->session->getFlash('info'); |
14 | 14 | ?> |
15 | 15 | <div class="taxonomy-def-index"> |
16 | - <?php if(isset($message)) |
|
16 | + <?php if(isset($message)) { |
|
17 | 17 | echo Alert::widget([ |
18 | 18 | 'options' => [ |
19 | 19 | 'class' => 'alert-info', |
20 | 20 | ], |
21 | 21 | 'body' => nl2br($message), |
22 | 22 | ]); |
23 | +} |
|
23 | 24 | ?> |
24 | 25 | |
25 | 26 | <h1><?= Html::encode($this->title) ?></h1> |
@@ -5,7 +5,7 @@ |
||
5 | 5 | /* @var $this yii\web\View */ |
6 | 6 | /* @var $model nkostadinov\taxonomy\models\TaxonomyDef */ |
7 | 7 | |
8 | -$this->title = 'Update Taxonomy Def: ' . ' ' . $model->name; |
|
8 | +$this->title = 'Update Taxonomy Def: '.' '.$model->name; |
|
9 | 9 | $this->params['breadcrumbs'][] = ['label' => 'Taxonomy Defs', 'url' => ['index']]; |
10 | 10 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; |
11 | 11 | $this->params['breadcrumbs'][] = 'Update'; |
@@ -62,7 +62,7 @@ |
||
62 | 62 | */ |
63 | 63 | public function getTerm($termName, $reload = false) |
64 | 64 | { |
65 | - if(!isset($this->_taxonomy[$termName]) || $reload) { |
|
65 | + if (!isset($this->_taxonomy[$termName]) || $reload) { |
|
66 | 66 | $tax = TaxonomyDef::findOne(['name' => $termName]); |
67 | 67 | \Yii::getLogger()->log("Initialising term $termName", Logger::LEVEL_INFO, 'nkostadinov.taxonomy.terms'); |
68 | 68 | $this->_taxonomy[$termName] = \Yii::createObject($tax->attributes); |
@@ -17,13 +17,13 @@ |
||
17 | 17 | $this->joinTables(); |
18 | 18 | |
19 | 19 | |
20 | - if(!empty($name)) |
|
20 | + if (!empty($name)) |
|
21 | 21 | $this->getQuery() |
22 | - ->andFilterWhere([ TaxonomyTerms::tableName() . '.term' => $name ]); |
|
22 | + ->andFilterWhere([TaxonomyTerms::tableName().'.term' => $name]); |
|
23 | 23 | |
24 | - if(!empty($value)) |
|
24 | + if (!empty($value)) |
|
25 | 25 | $this->getQuery() |
26 | - ->andFilterWhere([ $this->taxonomy->table . '.value' => $value ]); |
|
26 | + ->andFilterWhere([$this->taxonomy->table.'.value' => $value]); |
|
27 | 27 | |
28 | 28 | return $this->getQuery(); |
29 | 29 | } |
@@ -17,13 +17,15 @@ |
||
17 | 17 | $this->joinTables(); |
18 | 18 | |
19 | 19 | |
20 | - if(!empty($name)) |
|
21 | - $this->getQuery() |
|
20 | + if(!empty($name)) { |
|
21 | + $this->getQuery() |
|
22 | 22 | ->andFilterWhere([ TaxonomyTerms::tableName() . '.term' => $name ]); |
23 | + } |
|
23 | 24 | |
24 | - if(!empty($value)) |
|
25 | - $this->getQuery() |
|
25 | + if(!empty($value)) { |
|
26 | + $this->getQuery() |
|
26 | 27 | ->andFilterWhere([ $this->taxonomy->table . '.value' => $value ]); |
28 | + } |
|
27 | 29 | |
28 | 30 | return $this->getQuery(); |
29 | 31 | } |