Completed
Push — master ( 072afe...b82396 )
by Nikola
02:32
created
components/terms/PropertyTerm.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 } catch (Exception $e) {
67 67
                     $transaction->rollBack();
68 68
                 }
69
-            } elseif($this->updateOnExist) {
69
+            } elseif ($this->updateOnExist) {
70 70
                 $this->getDb()->createCommand()->update($this->getTable(), ['value' => $value], $data)->execute();
71 71
             }
72 72
         }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     public function removeTerm($object_id, $params = [])
76 76
     {
77 77
         $terms = $this->getTerms($object_id, $params);
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
 block discarded – undo
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,11 +93,11 @@  discard block
 block discarded – undo
93 93
     public function getTerms($object_id = null, $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]);
100
+            ->andFilterWhere([TaxonomyTerms::tableName().'.term' => $name]);
101 101
 
102 102
         return ArrayHelper::map($query->all(), 'term', 'value');
103 103
     }
Please login to merge, or discard this patch.