@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | class m170302_104953_create_rejections extends Migration |
6 | 6 | { |
7 | - private $tableName ='rejection'; |
|
7 | + private $tableName = 'rejection'; |
|
8 | 8 | |
9 | 9 | |
10 | 10 | public function safeUp() |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | 'time_rejected' => $this->dateTime()->notNull()->comment('Rejection time'), |
22 | 22 | ]); |
23 | 23 | |
24 | - $this->addForeignKey('fk_rejection_survey_id',$this->tableName,'survey_id','survey','survey_id'); |
|
25 | - $this->addForeignKey('fk_rejection_respondent_id','rejection','respondent_id','respondent','respondent_id'); |
|
24 | + $this->addForeignKey('fk_rejection_survey_id', $this->tableName, 'survey_id', 'survey', 'survey_id'); |
|
25 | + $this->addForeignKey('fk_rejection_respondent_id', 'rejection', 'respondent_id', 'respondent', 'respondent_id'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | } |
29 | 29 | |
30 | 30 | public function safeDown() |
31 | 31 | { |
32 | - $this->dropForeignKey('fk_rejection_survey_id',$this->tableName); |
|
33 | - $this->dropForeignKey('fk_rejection_email_id',$this->tableName); |
|
34 | - $this->dropForeignKey('fk_rejection_respondent_id',$this->tableName); |
|
32 | + $this->dropForeignKey('fk_rejection_survey_id', $this->tableName); |
|
33 | + $this->dropForeignKey('fk_rejection_email_id', $this->tableName); |
|
34 | + $this->dropForeignKey('fk_rejection_respondent_id', $this->tableName); |
|
35 | 35 | $this->dropTable($this->tableName); |
36 | 36 | } |
37 | 37 | } |
@@ -6,12 +6,12 @@ |
||
6 | 6 | { |
7 | 7 | public function safeUp() |
8 | 8 | { |
9 | - $this->dropColumn('rejection','response_code'); |
|
9 | + $this->dropColumn('rejection', 'response_code'); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public function safeDown() |
13 | 13 | { |
14 | - $this->addColumn('rejection','response_code',$this->integer(4)->after('type') |
|
14 | + $this->addColumn('rejection', 'response_code', $this->integer(4)->after('type') |
|
15 | 15 | ->comment('Email response code in case of bounce')); |
16 | 16 | } |
17 | 17 | } |
@@ -6,11 +6,11 @@ |
||
6 | 6 | { |
7 | 7 | public function safeUp() |
8 | 8 | { |
9 | - $this->renameColumn('rejection','bounce_type','type'); |
|
9 | + $this->renameColumn('rejection', 'bounce_type', 'type'); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | public function safeDown() |
13 | 13 | { |
14 | - $this->renameColumn('rejection','type','bounce_type'); |
|
14 | + $this->renameColumn('rejection', 'type', 'bounce_type'); |
|
15 | 15 | } |
16 | 16 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | { |
42 | 42 | return array_merge([ |
43 | 43 | [['survey_id', 'respondent_id'], 'integer'], |
44 | - [['email_address','time_rejected'], 'required'], |
|
44 | + [['email_address', 'time_rejected'], 'required'], |
|
45 | 45 | [['bounce'], 'string'], |
46 | 46 | [['time_rejected'], 'safe'], |
47 | 47 | [['email_address'], 'string', 'max' => 255], |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | [['type'], 'string', 'max' => 45], |
50 | 50 | [['respondent_id'], 'exist', 'skipOnError' => true, 'targetClass' => Respondent::class, 'targetAttribute' => ['respondent_id' => 'respondent_id']], |
51 | 51 | [['survey_id'], 'exist', 'skipOnError' => true, 'targetClass' => Survey::class, 'targetAttribute' => ['survey_id' => 'survey_id']], |
52 | - ], parent::rules()); |
|
52 | + ], parent::rules()); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @param string $email_address |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | - public static function hasBouncedHard($email_address){ |
|
60 | + public static function hasBouncedHard($email_address) { |
|
61 | 61 | $rejection = Rejection::findByEmail($email_address); |
62 | - if($rejection){ |
|
62 | + if ($rejection) { |
|
63 | 63 | return true; |
64 | 64 | } |
65 | 65 | return false; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string $email_address |
72 | 72 | * @return Rejection[] |
73 | 73 | */ |
74 | - public static function findHardBounces($email_address){ |
|
74 | + public static function findHardBounces($email_address) { |
|
75 | 75 | return Rejection::find() |
76 | 76 | ->andWhere(['email_address'=>$email_address]) |
77 | 77 | |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * @param string $code |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | - public static function rejectedByCode($code){ |
|
87 | + public static function rejectedByCode($code) { |
|
88 | 88 | $respondent = Respondent::findByToken($code); |
89 | - if($respondent){ |
|
89 | + if ($respondent) { |
|
90 | 90 | $rejections = self::find() |
91 | 91 | ->andWhere(['respondent_id'=>$respondent->primaryKey]) |
92 | 92 | ->all(); |
93 | - if($rejections){ |
|
93 | + if ($rejections) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | 96 | } |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | * @param string $type |
104 | 104 | * @return bool |
105 | 105 | */ |
106 | - public static function bouncedByEmailAddress($email_address,$type = self::BOUNCE_TYPE_HARD){ |
|
106 | + public static function bouncedByEmailAddress($email_address, $type = self::BOUNCE_TYPE_HARD) { |
|
107 | 107 | $rejections = self::find() |
108 | 108 | ->andWhere('email_address=:email_address', [':email_address' => $email_address]) |
109 | 109 | ->andWhere('type=:type', [':type' => $type]) |
110 | 110 | ->all(); |
111 | - if($rejections){ |
|
111 | + if ($rejections) { |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | return false; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $email_address |
119 | 119 | * @return Rejection |
120 | 120 | */ |
121 | - public static function findByEmail($email_address){ |
|
121 | + public static function findByEmail($email_address) { |
|
122 | 122 | return Rejection::findOne(['email_address'=>$email_address]); |
123 | 123 | } |
124 | 124 | |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | return $this->hasOne(Respondent::class, ['respondent_id' => 'respondent_id']); |
139 | 139 | } |
140 | 140 | |
141 | - public static function getBounceTypes(){ |
|
141 | + public static function getBounceTypes() { |
|
142 | 142 | return [ |
143 | - self::BOUNCE_TYPE_COMPLAINT => Yii::t('app','Complaint'), |
|
144 | - self::BOUNCE_TYPE_SOFT => Yii::t('app','Soft bounce'), |
|
145 | - self::BOUNCE_TYPE_HARD => Yii::t('app','Hard bounce'), |
|
146 | - self::BOUNCE_TYPE_ANSWERED => Yii::t('app','Respondent has answered already'), |
|
147 | - self::BOUNCE_TYPE_OTHER => Yii::t('app','Other'), |
|
143 | + self::BOUNCE_TYPE_COMPLAINT => Yii::t('app', 'Complaint'), |
|
144 | + self::BOUNCE_TYPE_SOFT => Yii::t('app', 'Soft bounce'), |
|
145 | + self::BOUNCE_TYPE_HARD => Yii::t('app', 'Hard bounce'), |
|
146 | + self::BOUNCE_TYPE_ANSWERED => Yii::t('app', 'Respondent has answered already'), |
|
147 | + self::BOUNCE_TYPE_OTHER => Yii::t('app', 'Other'), |
|
148 | 148 | ]; |
149 | 149 | } |
150 | 150 | } |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | * @param string $status if not set Status will be taken from Email |
39 | 39 | * @return boolean |
40 | 40 | */ |
41 | - public static function create($survey,$status = null){ |
|
41 | + public static function create($survey, $status = null) { |
|
42 | 42 | $model = new static(); |
43 | 43 | $model->survey_id = $survey->primaryKey; |
44 | - $model->status =$survey->status; |
|
45 | - if($status){ |
|
46 | - $model->status =$status; |
|
44 | + $model->status = $survey->status; |
|
45 | + if ($status) { |
|
46 | + $model->status = $status; |
|
47 | 47 | } |
48 | 48 | return $model->save(); |
49 | 49 | } |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | public function rules() |
55 | 55 | { |
56 | 56 | return array_merge([ |
57 | - [['survey_id','status'], 'required'], |
|
57 | + [['survey_id', 'status'], 'required'], |
|
58 | 58 | [['status'], 'string', 'max' => 32], |
59 | 59 | [['survey_id'], 'integer'], |
60 | - ], parent::rules()); |
|
60 | + ], parent::rules()); |
|
61 | 61 | } |
62 | 62 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var array $surveyIdentifyingColumns names of the columns that identify a respondent as unique inside a survey |
33 | 33 | */ |
34 | - public static $surveyIdentifyingColumns = ['phone_number','email_address']; |
|
34 | + public static $surveyIdentifyingColumns = ['phone_number', 'email_address']; |
|
35 | 35 | |
36 | 36 | public function init() |
37 | 37 | { |
@@ -45,31 +45,31 @@ discard block |
||
45 | 45 | public function rules() |
46 | 46 | { |
47 | 47 | return array_merge([ |
48 | - [['survey_id','token'], 'required'], |
|
48 | + [['survey_id', 'token'], 'required'], |
|
49 | 49 | [['survey_id'], 'integer'], |
50 | 50 | [['email_address'], 'validateEmail'], |
51 | 51 | // email addresses always lowercase |
52 | - [['email_address','email_address'],'trim'], |
|
53 | - ['email_address','filter', 'filter' => 'strtolower'], |
|
52 | + [['email_address', 'email_address'], 'trim'], |
|
53 | + ['email_address', 'filter', 'filter' => 'strtolower'], |
|
54 | 54 | [['alternative_email_addresses'], 'string'], |
55 | 55 | [['alternative_email_addresses'], 'validateMultipleEmails'], |
56 | - [['phone_number','email_address'],'trim'], |
|
57 | - ['phone_number','filter', 'filter' => 'strtolower'], |
|
58 | - [['phone_number'],'string'], |
|
59 | - [['phone_number'],'validatePhoneNumber'], |
|
56 | + [['phone_number', 'email_address'], 'trim'], |
|
57 | + ['phone_number', 'filter', 'filter' => 'strtolower'], |
|
58 | + [['phone_number'], 'string'], |
|
59 | + [['phone_number'], 'validatePhoneNumber'], |
|
60 | 60 | [['alternative_phone_numbers'], 'string'], |
61 | - [['alternative_phone_numbers'],'validateMultiplePhoneNumbers'], |
|
61 | + [['alternative_phone_numbers'], 'validateMultiplePhoneNumbers'], |
|
62 | 62 | [['token'], 'unique'], |
63 | 63 | ], parent::rules()); |
64 | 64 | } |
65 | 65 | |
66 | 66 | |
67 | - public function validateEmail($attribute,$address = null){ |
|
68 | - if(!$address or empty($address)){ |
|
67 | + public function validateEmail($attribute, $address = null) { |
|
68 | + if (!$address or empty($address)) { |
|
69 | 69 | $address = $this->email_address; |
70 | 70 | $isSameAsMainAddress = false; |
71 | - }else{ |
|
72 | - $isSameAsMainAddress = ($attribute=='email_address' ? false : $address == $this->email_address); |
|
71 | + } else { |
|
72 | + $isSameAsMainAddress = ($attribute == 'email_address' ? false : $address == $this->email_address); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $validator = new yii\validators\EmailValidator(); |
@@ -78,55 +78,55 @@ discard block |
||
78 | 78 | |
79 | 79 | $isDuplicate = $this->isEmailSurveyDuplicate($address); |
80 | 80 | |
81 | - if($isValidFormat && !$isSameAsMainAddress && !$isDuplicate){ |
|
81 | + if ($isValidFormat && !$isSameAsMainAddress && !$isDuplicate) { |
|
82 | 82 | return true; |
83 | - }else{ |
|
83 | + } else { |
|
84 | 84 | $reason = ''; |
85 | - if(!$isValidFormat){ |
|
86 | - $reason = Yii::t('app','Invalid email format'); |
|
87 | - } else if($isSameAsMainAddress){ |
|
88 | - $reason = Yii::t('app',$attribute. ' duplicates main address'); |
|
89 | - } else if($isDuplicate) { |
|
90 | - $reason = Yii::t('app','Duplicates some other address'); |
|
85 | + if (!$isValidFormat) { |
|
86 | + $reason = Yii::t('app', 'Invalid email format'); |
|
87 | + } else if ($isSameAsMainAddress) { |
|
88 | + $reason = Yii::t('app', $attribute.' duplicates main address'); |
|
89 | + } else if ($isDuplicate) { |
|
90 | + $reason = Yii::t('app', 'Duplicates some other address'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->addError($attribute, |
94 | 94 | Yii::t('app', |
95 | - 'Invalid email address "{0}"',[$address] |
|
96 | - ).' '.Yii::t('app','Reason: {0}',[$reason]) |
|
95 | + 'Invalid email address "{0}"', [$address] |
|
96 | + ).' '.Yii::t('app', 'Reason: {0}', [$reason]) |
|
97 | 97 | ); |
98 | 98 | } |
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | |
102 | 102 | |
103 | - public function validateMultipleEmails($attribute){ |
|
103 | + public function validateMultipleEmails($attribute) { |
|
104 | 104 | $addresses = yii\helpers\Json::decode($this->alternative_email_addresses); |
105 | - if($this->alternative_email_addresses && !empty($addresses)){ |
|
105 | + if ($this->alternative_email_addresses && !empty($addresses)) { |
|
106 | 106 | $cleanAddresses = []; |
107 | - if(!empty($addresses)){ |
|
108 | - $i=0; |
|
109 | - foreach ($addresses as $key => $address){ |
|
110 | - if($address <> ""){ |
|
107 | + if (!empty($addresses)) { |
|
108 | + $i = 0; |
|
109 | + foreach ($addresses as $key => $address) { |
|
110 | + if ($address <> "") { |
|
111 | 111 | // check the alternative numbers of that model for duplicates |
112 | 112 | $checkItems = $addresses; |
113 | 113 | unset($checkItems[$key]); |
114 | - if(in_array($address,$checkItems)){ |
|
115 | - $this->addError($attribute,Yii::t('app','Duplicate email in alternative email addresses')); |
|
114 | + if (in_array($address, $checkItems)) { |
|
115 | + $this->addError($attribute, Yii::t('app', 'Duplicate email in alternative email addresses')); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $i++; |
119 | - if($i>=static::MAX_ALTERNATIVE_CONTACTS){ |
|
120 | - $this->addError($attribute,Yii::t('app','Maximum alternative addresses limit ({0}) reached for {1}',[static::MAX_ALTERNATIVE_CONTACTS,$this->email_address])); |
|
119 | + if ($i >= static::MAX_ALTERNATIVE_CONTACTS) { |
|
120 | + $this->addError($attribute, Yii::t('app', 'Maximum alternative addresses limit ({0}) reached for {1}', [static::MAX_ALTERNATIVE_CONTACTS, $this->email_address])); |
|
121 | 121 | } |
122 | 122 | $address = strtolower(trim($address)); |
123 | - if($this->validateEmail($attribute,$address)){ |
|
124 | - $cleanAddresses[]=$address; |
|
123 | + if ($this->validateEmail($attribute, $address)) { |
|
124 | + $cleanAddresses[] = $address; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | 128 | } |
129 | - if(!empty($cleanAddresses)){ |
|
129 | + if (!empty($cleanAddresses)) { |
|
130 | 130 | $this->alternative_email_addresses = yii\helpers\Json::encode($cleanAddresses); |
131 | 131 | } else { |
132 | 132 | $this->alternative_email_addresses = null; |
@@ -136,68 +136,68 @@ discard block |
||
136 | 136 | } |
137 | 137 | |
138 | 138 | |
139 | - public function validatePhoneNumber($attribute, $phone_number = null){ |
|
140 | - if(!$phone_number or empty($phone_number)){ |
|
139 | + public function validatePhoneNumber($attribute, $phone_number = null) { |
|
140 | + if (!$phone_number or empty($phone_number)) { |
|
141 | 141 | $phone_number = $this->phone_number; |
142 | 142 | $isSameAsMain = false; |
143 | - }else{ |
|
144 | - $isSameAsMain = ($attribute=='phone_number' ? false : $phone_number == $this->phone_number); |
|
143 | + } else { |
|
144 | + $isSameAsMain = ($attribute == 'phone_number' ? false : $phone_number == $this->phone_number); |
|
145 | 145 | } |
146 | 146 | // TODO |
147 | 147 | $isValidFormat = true; |
148 | 148 | |
149 | 149 | $isDuplicate = $this->isPhoneSurveyDuplicate($phone_number); |
150 | 150 | |
151 | - if($isValidFormat && !$isSameAsMain && !$isDuplicate){ |
|
151 | + if ($isValidFormat && !$isSameAsMain && !$isDuplicate) { |
|
152 | 152 | return true; |
153 | - }else{ |
|
153 | + } else { |
|
154 | 154 | $reason = ''; |
155 | - if(!$isValidFormat){ |
|
156 | - $reason = Yii::t('app','Invalid phone number format'); |
|
157 | - } else if($isSameAsMain){ |
|
158 | - $reason = Yii::t('app',$attribute. ' duplicates main phone number'); |
|
159 | - } else if($isDuplicate) { |
|
160 | - $reason = Yii::t('app','Duplicate phone number'); |
|
155 | + if (!$isValidFormat) { |
|
156 | + $reason = Yii::t('app', 'Invalid phone number format'); |
|
157 | + } else if ($isSameAsMain) { |
|
158 | + $reason = Yii::t('app', $attribute.' duplicates main phone number'); |
|
159 | + } else if ($isDuplicate) { |
|
160 | + $reason = Yii::t('app', 'Duplicate phone number'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $this->addError($attribute, |
164 | 164 | Yii::t('app', |
165 | - 'Invalid phone number "{0}"',[$phone_number] |
|
166 | - ).' '.Yii::t('app','Reason: {0}',[$reason]) |
|
165 | + 'Invalid phone number "{0}"', [$phone_number] |
|
166 | + ).' '.Yii::t('app', 'Reason: {0}', [$reason]) |
|
167 | 167 | ); |
168 | 168 | } |
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | |
172 | - public function validateMultiplePhoneNumbers($attribute){ |
|
173 | - if($this->alternative_phone_numbers){ |
|
172 | + public function validateMultiplePhoneNumbers($attribute) { |
|
173 | + if ($this->alternative_phone_numbers) { |
|
174 | 174 | $cleanItems = []; |
175 | 175 | $items = yii\helpers\Json::decode($this->alternative_phone_numbers); |
176 | 176 | |
177 | - if(!empty($items)){ |
|
178 | - $i=0; |
|
179 | - foreach ($items as $key=> $item){ |
|
177 | + if (!empty($items)) { |
|
178 | + $i = 0; |
|
179 | + foreach ($items as $key=> $item) { |
|
180 | 180 | $item = strtolower(trim($item)); |
181 | - if($item <> ''){ |
|
181 | + if ($item <> '') { |
|
182 | 182 | $i++; |
183 | 183 | // check the alternative numbers of that model for duplicates |
184 | 184 | $checkItems = $items; |
185 | 185 | unset($checkItems[$key]); |
186 | - if(in_array($item,$checkItems)){ |
|
187 | - $this->addError($attribute,Yii::t('app','Duplicate number in alternative phone numbers')); |
|
186 | + if (in_array($item, $checkItems)) { |
|
187 | + $this->addError($attribute, Yii::t('app', 'Duplicate number in alternative phone numbers')); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | |
191 | - if($i>=static::MAX_ALTERNATIVE_CONTACTS){ |
|
192 | - $this->addError($attribute,Yii::t('app','Maximum alternative phone numbers limit ({0}) reached for {1}',[static::MAX_ALTERNATIVE_CONTACTS,$this->phone_number])); |
|
191 | + if ($i >= static::MAX_ALTERNATIVE_CONTACTS) { |
|
192 | + $this->addError($attribute, Yii::t('app', 'Maximum alternative phone numbers limit ({0}) reached for {1}', [static::MAX_ALTERNATIVE_CONTACTS, $this->phone_number])); |
|
193 | 193 | } |
194 | - if($this->validatePhoneNumber($attribute,$item)){ |
|
195 | - $cleanItems[]=$item; |
|
194 | + if ($this->validatePhoneNumber($attribute, $item)) { |
|
195 | + $cleanItems[] = $item; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | } |
199 | 199 | } |
200 | - if(!empty($cleanItems)){ |
|
200 | + if (!empty($cleanItems)) { |
|
201 | 201 | $this->alternative_phone_numbers = yii\helpers\Json::encode($cleanItems); |
202 | 202 | } else { |
203 | 203 | $this->alternative_phone_numbers = null; |
@@ -212,22 +212,22 @@ discard block |
||
212 | 212 | * @param string $phone_number Phone number to check duplicates for |
213 | 213 | * @return bool |
214 | 214 | */ |
215 | - public function isPhoneSurveyDuplicate($phone_number){ |
|
215 | + public function isPhoneSurveyDuplicate($phone_number) { |
|
216 | 216 | $query = static::find(); |
217 | 217 | // check only this survey |
218 | 218 | $query->andWhere(['survey_id'=>$this->survey_id]); |
219 | 219 | |
220 | - if($this->respondent_id){ |
|
220 | + if ($this->respondent_id) { |
|
221 | 221 | // not itself |
222 | - $query->andWhere(['!=','respondent_id',$this->respondent_id]); |
|
222 | + $query->andWhere(['!=', 'respondent_id', $this->respondent_id]); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | $condition = ['or', |
226 | 226 | '`phone_number`=:phone_number', |
227 | 227 | '`alternative_phone_numbers` LIKE :phone_number2', |
228 | 228 | ]; |
229 | - $query->andWhere($condition,[':phone_number'=>$phone_number,':phone_number2'=>'%\"'.$phone_number.'\"%']); |
|
230 | - if($query->count() > 0){ |
|
229 | + $query->andWhere($condition, [':phone_number'=>$phone_number, ':phone_number2'=>'%\"'.$phone_number.'\"%']); |
|
230 | + if ($query->count() > 0) { |
|
231 | 231 | return true; |
232 | 232 | } |
233 | 233 | return false; |
@@ -238,22 +238,22 @@ discard block |
||
238 | 238 | * @param string $email_address Email address to check duplicates for |
239 | 239 | * @return bool |
240 | 240 | */ |
241 | - public function isEmailSurveyDuplicate($email_address){ |
|
241 | + public function isEmailSurveyDuplicate($email_address) { |
|
242 | 242 | $query = static::find(); |
243 | 243 | // check only this survey |
244 | 244 | $query->andWhere(['survey_id'=>$this->survey_id]); |
245 | 245 | // not itself |
246 | - if($this->respondent_id){ |
|
246 | + if ($this->respondent_id) { |
|
247 | 247 | // not itself |
248 | - $query->andWhere(['!=','respondent_id',$this->respondent_id]); |
|
248 | + $query->andWhere(['!=', 'respondent_id', $this->respondent_id]); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | $email_condition = ['or', |
252 | 252 | '`email_address`=:email_address', |
253 | 253 | '`alternative_email_addresses` LIKE :email_address2', |
254 | 254 | ]; |
255 | - $query->andWhere($email_condition,[':email_address'=>$email_address,':email_address2'=>'%\"'.$email_address.'\"%']); |
|
256 | - if($query->count() > 0){ |
|
255 | + $query->andWhere($email_condition, [':email_address'=>$email_address, ':email_address2'=>'%\"'.$email_address.'\"%']); |
|
256 | + if ($query->count() > 0) { |
|
257 | 257 | return true; |
258 | 258 | } |
259 | 259 | return false; |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * @param string $token Respondents token |
274 | 274 | * @return static |
275 | 275 | */ |
276 | - public static function findByToken($token = null){ |
|
277 | - if($token){ |
|
276 | + public static function findByToken($token = null) { |
|
277 | + if ($token) { |
|
278 | 278 | $models = self::findByTokens([$token]); |
279 | - if (!empty($models)){ |
|
279 | + if (!empty($models)) { |
|
280 | 280 | return $models[0]; |
281 | 281 | } |
282 | 282 | } |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | * @param string[] $tokens Respondents tokens |
288 | 288 | * @return static[] |
289 | 289 | */ |
290 | - public static function findByTokens($tokens){ |
|
290 | + public static function findByTokens($tokens) { |
|
291 | 291 | /** @var static[] $model */ |
292 | 292 | $models = static::find() |
293 | - ->andWhere(['in','token', $tokens]) |
|
293 | + ->andWhere(['in', 'token', $tokens]) |
|
294 | 294 | ->all(); |
295 | 295 | return $models; |
296 | 296 | } |
@@ -299,11 +299,11 @@ discard block |
||
299 | 299 | * Check whether respondent has rejected this specific survey or has a hard bounce on e_mail address |
300 | 300 | * @return bool |
301 | 301 | */ |
302 | - public function getIsRejected(){ |
|
303 | - if(Rejection::rejectedByCode($this->token)){ |
|
302 | + public function getIsRejected() { |
|
303 | + if (Rejection::rejectedByCode($this->token)) { |
|
304 | 304 | return true; |
305 | 305 | } |
306 | - if(Rejection::bouncedByEmailAddress($this->email_address)){ |
|
306 | + if (Rejection::bouncedByEmailAddress($this->email_address)) { |
|
307 | 307 | return true; |
308 | 308 | } |
309 | 309 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param string $email_address |
316 | 316 | * @return static |
317 | 317 | */ |
318 | - public static function getLatestByEmail($email_address){ |
|
318 | + public static function getLatestByEmail($email_address) { |
|
319 | 319 | /** @var static $model */ |
320 | 320 | $model = static::find() |
321 | 321 | ->andWhere(['email_address'=>$email_address]) |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | /** |
328 | 328 | * @return string |
329 | 329 | */ |
330 | - public function getShortToken(){ |
|
331 | - if(Uuid::isValid($this->token)){ |
|
330 | + public function getShortToken() { |
|
331 | + if (Uuid::isValid($this->token)) { |
|
332 | 332 | $uuid = Uuid::fromString($this->token); |
333 | 333 | $shotUuid = new ShortUuid(); |
334 | 334 | return $shotUuid->encode($uuid); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | if(!$address or empty($address)){ |
69 | 69 | $address = $this->email_address; |
70 | 70 | $isSameAsMainAddress = false; |
71 | - }else{ |
|
71 | + } else{ |
|
72 | 72 | $isSameAsMainAddress = ($attribute=='email_address' ? false : $address == $this->email_address); |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | if($isValidFormat && !$isSameAsMainAddress && !$isDuplicate){ |
82 | 82 | return true; |
83 | - }else{ |
|
83 | + } else{ |
|
84 | 84 | $reason = ''; |
85 | 85 | if(!$isValidFormat){ |
86 | 86 | $reason = Yii::t('app','Invalid email format'); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | if(!$phone_number or empty($phone_number)){ |
141 | 141 | $phone_number = $this->phone_number; |
142 | 142 | $isSameAsMain = false; |
143 | - }else{ |
|
143 | + } else{ |
|
144 | 144 | $isSameAsMain = ($attribute=='phone_number' ? false : $phone_number == $this->phone_number); |
145 | 145 | } |
146 | 146 | // TODO |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | if($isValidFormat && !$isSameAsMain && !$isDuplicate){ |
152 | 152 | return true; |
153 | - }else{ |
|
153 | + } else{ |
|
154 | 154 | $reason = ''; |
155 | 155 | if(!$isValidFormat){ |
156 | 156 | $reason = Yii::t('app','Invalid phone number format'); |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | public function rules() |
31 | 31 | { |
32 | 32 | return array_merge([ |
33 | - [['name','status'], 'required'], |
|
33 | + [['name', 'status'], 'required'], |
|
34 | 34 | [['name', 'status'], 'string', 'max' => 255], |
35 | - [['name'], 'string','max' => 500], |
|
36 | - [['options'], 'string','max' => 1024 * 10], |
|
35 | + [['name'], 'string', 'max' => 500], |
|
36 | + [['options'], 'string', 'max' => 1024 * 10], |
|
37 | 37 | ], parent::rules()); |
38 | 38 | } |
39 | 39 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | ]; |
57 | 57 | } |
58 | 58 | |
59 | - public function getOptionsDecoded(){ |
|
59 | + public function getOptionsDecoded() { |
|
60 | 60 | return json_decode($this->options); |
61 | 61 | } |
62 | 62 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public static function modelName() |
36 | 36 | { |
37 | - return Yii::t('app','Rating'); |
|
37 | + return Yii::t('app', 'Rating'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | [['respondent_id', 'survey_id', 'sample_id', 'value'], 'integer'], |
50 | 50 | [['comment'], 'string'], |
51 | 51 | [['respondent_id'], 'exist', 'skipOnError' => true, 'targetClass' => Respondent::class, 'targetAttribute' => ['respondent_id' => 'respondent_id']], |
52 | - ], parent::rules()); |
|
52 | + ], parent::rules()); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |