@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | class PropertyTerm extends BaseTerm { |
19 | 19 | |
20 | - public $templateFile = '@nkostadinov/taxonomy/migrations/template/properties.php' ; |
|
20 | + public $templateFile = '@nkostadinov/taxonomy/migrations/template/properties.php'; |
|
21 | 21 | |
22 | 22 | public $updateOnExist = true; |
23 | 23 | |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | 'value' => Schema::TYPE_STRING, |
34 | 34 | ]); |
35 | 35 | if ($migration->db->driverName === 'mysql') { |
36 | - $migration->addForeignKey('fk_' . $this->getTable() . '_' . $this->getRefTableName(), $this->getTable(), 'object_id', $this->getRefTableName(), 'id', 'CASCADE'); |
|
37 | - $migration->addForeignKey('fk_' . $this->getTable() . '_' . TaxonomyTerms::tableName(), $this->getTable(), 'term_id', TaxonomyTerms::tableName(), 'id', 'CASCADE'); |
|
36 | + $migration->addForeignKey('fk_'.$this->getTable().'_'.$this->getRefTableName(), $this->getTable(), 'object_id', $this->getRefTableName(), 'id', 'CASCADE'); |
|
37 | + $migration->addForeignKey('fk_'.$this->getTable().'_'.TaxonomyTerms::tableName(), $this->getTable(), 'term_id', TaxonomyTerms::tableName(), 'id', 'CASCADE'); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function addTerm($object_id, $params) |
42 | 42 | { |
43 | - foreach($params as $item => $value) { |
|
43 | + foreach ($params as $item => $value) { |
|
44 | 44 | $term = TaxonomyTerms::findOne(['term' => $item, 'taxonomy_id' => $this->id]); |
45 | 45 | if (!isset($term)) { |
46 | 46 | $term = new TaxonomyTerms(); |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | } catch (Exception $e) { |
67 | 67 | $transaction->rollBack(); |
68 | 68 | } |
69 | - } elseif($this->updateOnExist) { |
|
70 | - $this->getDb()->createCommand()->update($this->getTable(), [ 'value' => $value ], $data)->execute(); |
|
69 | + } elseif ($this->updateOnExist) { |
|
70 | + $this->getDb()->createCommand()->update($this->getTable(), ['value' => $value], $data)->execute(); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | public function removeTerm($object_id, $params = []) |
76 | 76 | { |
77 | 77 | $terms = $this->getTerms($object_id, isset($params['name']) ? $params['name'] : []); |
78 | - foreach($terms as $term=>$value) { |
|
78 | + foreach ($terms as $term=>$value) { |
|
79 | 79 | $term = $this->getTaxonomyTerm($term); |
80 | 80 | $data['term_id'] = $term->id; |
81 | 81 | $data['object_id'] = $object_id; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $this->getDb()->createCommand()->delete($this->getTable(), $data)->execute(); |
86 | 86 | |
87 | 87 | $term->updateCounters(['total_count' => -1]); |
88 | - TaxonomyDef::updateAllCounters(['total_count' => -1], [ 'id' => $this->id ]); |
|
88 | + TaxonomyDef::updateAllCounters(['total_count' => -1], ['id' => $this->id]); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | public function getTerms($object_id, $name = []) |
94 | 94 | { |
95 | 95 | $query = (new Query()) |
96 | - ->select(TaxonomyTerms::tableName() . '.term, ' . $this->getTable() . '.value') |
|
96 | + ->select(TaxonomyTerms::tableName().'.term, '.$this->getTable().'.value') |
|
97 | 97 | ->from(TaxonomyTerms::tableName()) |
98 | - ->innerJoin($this->getTable(), $this->getTable() . '.term_id = taxonomy_terms.id and ' . $this->getTable() . '.object_id=:object_id', |
|
98 | + ->innerJoin($this->getTable(), $this->getTable().'.term_id = taxonomy_terms.id and '.$this->getTable().'.object_id=:object_id', |
|
99 | 99 | [':object_id' => $object_id]) |
100 | - ->andFilterWhere([TaxonomyTerms::tableName() . '.term' => $name]); |
|
101 | - foreach($query->all() as $v) |
|
100 | + ->andFilterWhere([TaxonomyTerms::tableName().'.term' => $name]); |
|
101 | + foreach ($query->all() as $v) |
|
102 | 102 | $result[$v['term']] = $v['value']; |
103 | 103 | return isset($result) ? $result : []; |
104 | 104 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | public function canInstall() { |
77 | - if(!$this->getTable()) |
|
77 | + if (!$this->getTable()) |
|
78 | 78 | return 'Missing "table" property'; |
79 | 79 | return true; |
80 | 80 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function getTaxonomyTerm($name, $create = true) |
83 | 83 | { |
84 | 84 | $term = TaxonomyTerms::findOne(['term'=>$name, 'taxonomy_id' => $this->id]); |
85 | - if($create and !isset($term)) |
|
85 | + if ($create and !isset($term)) |
|
86 | 86 | { |
87 | 87 | $term = new TaxonomyTerms(); |
88 | 88 | $term->taxonomy_id = $this->id; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | public function getRefTableName() |
97 | 97 | { |
98 | - if(strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name |
|
98 | + if (strpos($this->refTable, '\\') === FALSE) //not an AR class but a table name |
|
99 | 99 | return $this->refTable; |
100 | 100 | else |
101 | 101 | return call_user_func([$this->refTable, 'tableName']); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | if (!preg_match('/^\w+$/', $this->name)) { |
117 | 117 | throw new Exception('The migration name should contain letters, digits and/or underscore characters only.'); |
118 | 118 | } |
119 | - $name = 'm' . gmdate('ymd_His') . '_' . $this->name; |
|
119 | + $name = 'm'.gmdate('ymd_His').'_'.$this->name; |
|
120 | 120 | return $name; |
121 | 121 | } |
122 | 122 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | { |
125 | 125 | |
126 | 126 | $name = $this->getMigrationFile(); |
127 | - $file = \Yii::getAlias($this->migrationPath . DIRECTORY_SEPARATOR . $name . '.php'); |
|
127 | + $file = \Yii::getAlias($this->migrationPath.DIRECTORY_SEPARATOR.$name.'.php'); |
|
128 | 128 | |
129 | 129 | //$data = get_object_vars($this); |
130 | 130 | $data = []; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $data['migration'] = $name; |
136 | 136 | |
137 | 137 | $this->migration = $name; |
138 | - $content = \Yii::$app->getView()->renderFile(\Yii::getAlias($this->templateFile), [ 'data' => $data ]); |
|
138 | + $content = \Yii::$app->getView()->renderFile(\Yii::getAlias($this->templateFile), ['data' => $data]); |
|
139 | 139 | file_put_contents($file, $content); |
140 | 140 | return $name; |
141 | 141 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | */ |
63 | 63 | public function getTerm($termName, $reload = false) |
64 | 64 | { |
65 | - if(!isset($this->_taxonomy[$termName]) or $reload) { |
|
65 | + if (!isset($this->_taxonomy[$termName]) or $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); |