@@ -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 | } |
@@ -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 | /** |
@@ -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 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * @return mixed |
| 66 | 66 | */ |
| 67 | - public function getOptionsDecoded(){ |
|
| 67 | + public function getOptionsDecoded() { |
|
| 68 | 68 | return json_decode($this->options); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -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,20 +45,20 @@ 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 | } |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | * @param string $address |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | - public function validateEmail($attribute,$address = null){ |
|
| 73 | + public function validateEmail($attribute, $address = null) { |
|
| 74 | 74 | |
| 75 | - if($this->validateEmailFormat($attribute, $address) |
|
| 75 | + if ($this->validateEmailFormat($attribute, $address) |
|
| 76 | 76 | && !$this->isSameAsMainAddress($attribute, $address) |
| 77 | - && !$this->isEmailSurveyDuplicate($attribute, $address)){ |
|
| 77 | + && !$this->isEmailSurveyDuplicate($attribute, $address)) { |
|
| 78 | 78 | return true; |
| 79 | 79 | } |
| 80 | 80 | return false; |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | if (!$validator->validate($address)) { |
| 93 | 93 | $this->addError($attribute, |
| 94 | 94 | Yii::t('app', |
| 95 | - 'Invalid email address "{0}"',[$address] |
|
| 96 | - ).' '.Yii::t('app','Reason: {0}',[Yii::t('app','Invalid email format')]) |
|
| 95 | + 'Invalid email address "{0}"', [$address] |
|
| 96 | + ).' '.Yii::t('app', 'Reason: {0}', [Yii::t('app', 'Invalid email format')]) |
|
| 97 | 97 | ); |
| 98 | 98 | return false; |
| 99 | 99 | } |
@@ -107,48 +107,48 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | private function isSameAsMainAddress($attribute, $address = null) |
| 109 | 109 | { |
| 110 | - if(!$address or empty($address)){ |
|
| 110 | + if (!$address or empty($address)) { |
|
| 111 | 111 | return false; |
| 112 | 112 | } |
| 113 | - $isSame = ($attribute=='email_address' ? false : $address == $this->email_address); |
|
| 113 | + $isSame = ($attribute == 'email_address' ? false : $address == $this->email_address); |
|
| 114 | 114 | if ($isSame) { |
| 115 | 115 | $this->addError($attribute, |
| 116 | 116 | Yii::t('app', |
| 117 | - 'Invalid email address "{0}"',[$address] |
|
| 118 | - ).' '.Yii::t('app','Reason: {0}',[Yii::t('app',$attribute. ' duplicates main address')]) |
|
| 117 | + 'Invalid email address "{0}"', [$address] |
|
| 118 | + ).' '.Yii::t('app', 'Reason: {0}', [Yii::t('app', $attribute.' duplicates main address')]) |
|
| 119 | 119 | ); |
| 120 | 120 | } |
| 121 | 121 | return $isSame; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
| 125 | - public function validateMultipleEmails($attribute){ |
|
| 125 | + public function validateMultipleEmails($attribute) { |
|
| 126 | 126 | $addresses = yii\helpers\Json::decode($this->alternative_email_addresses); |
| 127 | - if($this->alternative_email_addresses && !empty($addresses)){ |
|
| 127 | + if ($this->alternative_email_addresses && !empty($addresses)) { |
|
| 128 | 128 | $cleanAddresses = []; |
| 129 | - if(!empty($addresses)){ |
|
| 130 | - $i=0; |
|
| 131 | - foreach ($addresses as $key => $address){ |
|
| 132 | - if($address <> ""){ |
|
| 129 | + if (!empty($addresses)) { |
|
| 130 | + $i = 0; |
|
| 131 | + foreach ($addresses as $key => $address) { |
|
| 132 | + if ($address <> "") { |
|
| 133 | 133 | // check the alternative numbers of that model for duplicates |
| 134 | 134 | $checkItems = $addresses; |
| 135 | 135 | unset($checkItems[$key]); |
| 136 | - if(in_array($address,$checkItems)){ |
|
| 137 | - $this->addError($attribute,Yii::t('app','Duplicate email in alternative email addresses')); |
|
| 136 | + if (in_array($address, $checkItems)) { |
|
| 137 | + $this->addError($attribute, Yii::t('app', 'Duplicate email in alternative email addresses')); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $i++; |
| 141 | - if($i>=static::MAX_ALTERNATIVE_CONTACTS){ |
|
| 142 | - $this->addError($attribute,Yii::t('app','Maximum alternative addresses limit ({0}) reached for {1}',[static::MAX_ALTERNATIVE_CONTACTS,$this->email_address])); |
|
| 141 | + if ($i >= static::MAX_ALTERNATIVE_CONTACTS) { |
|
| 142 | + $this->addError($attribute, Yii::t('app', 'Maximum alternative addresses limit ({0}) reached for {1}', [static::MAX_ALTERNATIVE_CONTACTS, $this->email_address])); |
|
| 143 | 143 | } |
| 144 | 144 | $address = strtolower(trim($address)); |
| 145 | - if($this->validateEmail($attribute,$address)){ |
|
| 146 | - $cleanAddresses[]=$address; |
|
| 145 | + if ($this->validateEmail($attribute, $address)) { |
|
| 146 | + $cleanAddresses[] = $address; |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | } |
| 151 | - if(!empty($cleanAddresses)){ |
|
| 151 | + if (!empty($cleanAddresses)) { |
|
| 152 | 152 | $this->alternative_email_addresses = yii\helpers\Json::encode($cleanAddresses); |
| 153 | 153 | } else { |
| 154 | 154 | $this->alternative_email_addresses = null; |
@@ -158,42 +158,42 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
| 161 | - public function validatePhoneNumber($attribute, $phone_number = null){ |
|
| 161 | + public function validatePhoneNumber($attribute, $phone_number = null) { |
|
| 162 | 162 | $this->validateSameAsMainNumber($attribute, $phone_number); |
| 163 | 163 | // TODO |
| 164 | 164 | $isValidFormat = true; |
| 165 | 165 | $this->validatePhoneSurveyDuplicate($attribute, $phone_number); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - public function validateMultiplePhoneNumbers($attribute){ |
|
| 169 | - if($this->alternative_phone_numbers){ |
|
| 168 | + public function validateMultiplePhoneNumbers($attribute) { |
|
| 169 | + if ($this->alternative_phone_numbers) { |
|
| 170 | 170 | $cleanItems = []; |
| 171 | 171 | $items = yii\helpers\Json::decode($this->alternative_phone_numbers); |
| 172 | 172 | |
| 173 | - if(!empty($items)){ |
|
| 174 | - $i=0; |
|
| 175 | - foreach ($items as $key=> $item){ |
|
| 173 | + if (!empty($items)) { |
|
| 174 | + $i = 0; |
|
| 175 | + foreach ($items as $key=> $item) { |
|
| 176 | 176 | $item = strtolower(trim($item)); |
| 177 | - if($item <> ''){ |
|
| 177 | + if ($item <> '') { |
|
| 178 | 178 | $i++; |
| 179 | 179 | // check the alternative numbers of that model for duplicates |
| 180 | 180 | $checkItems = $items; |
| 181 | 181 | unset($checkItems[$key]); |
| 182 | - if(in_array($item,$checkItems)){ |
|
| 183 | - $this->addError($attribute,Yii::t('app','Duplicate number in alternative phone numbers')); |
|
| 182 | + if (in_array($item, $checkItems)) { |
|
| 183 | + $this->addError($attribute, Yii::t('app', 'Duplicate number in alternative phone numbers')); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
| 187 | - if($i>=static::MAX_ALTERNATIVE_CONTACTS){ |
|
| 188 | - $this->addError($attribute,Yii::t('app','Maximum alternative phone numbers limit ({0}) reached for {1}',[static::MAX_ALTERNATIVE_CONTACTS,$this->phone_number])); |
|
| 187 | + if ($i >= static::MAX_ALTERNATIVE_CONTACTS) { |
|
| 188 | + $this->addError($attribute, Yii::t('app', 'Maximum alternative phone numbers limit ({0}) reached for {1}', [static::MAX_ALTERNATIVE_CONTACTS, $this->phone_number])); |
|
| 189 | 189 | } |
| 190 | - if($this->validatePhoneNumber($attribute,$item)){ |
|
| 191 | - $cleanItems[]=$item; |
|
| 190 | + if ($this->validatePhoneNumber($attribute, $item)) { |
|
| 191 | + $cleanItems[] = $item; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | - if(!empty($cleanItems)){ |
|
| 196 | + if (!empty($cleanItems)) { |
|
| 197 | 197 | $this->alternative_phone_numbers = yii\helpers\Json::encode($cleanItems); |
| 198 | 198 | } else { |
| 199 | 199 | $this->alternative_phone_numbers = null; |
@@ -214,13 +214,13 @@ discard block |
||
| 214 | 214 | return null; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - $isSame = ($attribute=='phone_number' ? false : $number == $this->phone_number); |
|
| 217 | + $isSame = ($attribute == 'phone_number' ? false : $number == $this->phone_number); |
|
| 218 | 218 | |
| 219 | 219 | if ($isSame) { |
| 220 | 220 | $this->addError($attribute, |
| 221 | 221 | Yii::t('app', |
| 222 | - 'Invalid phone number "{0}"',[$number] |
|
| 223 | - ).' '.Yii::t('app','Reason: {0}',[Yii::t('app',$attribute. ' duplicates main phone number')]) |
|
| 222 | + 'Invalid phone number "{0}"', [$number] |
|
| 223 | + ).' '.Yii::t('app', 'Reason: {0}', [Yii::t('app', $attribute.' duplicates main phone number')]) |
|
| 224 | 224 | ); |
| 225 | 225 | } |
| 226 | 226 | return null; |
@@ -231,27 +231,27 @@ discard block |
||
| 231 | 231 | * @param string $attribute |
| 232 | 232 | * @param string $phone_number Phone number to check duplicates for |
| 233 | 233 | */ |
| 234 | - private function validatePhoneSurveyDuplicate($attribute, $phone_number){ |
|
| 234 | + private function validatePhoneSurveyDuplicate($attribute, $phone_number) { |
|
| 235 | 235 | $query = static::find(); |
| 236 | 236 | // check only this survey |
| 237 | 237 | $query->andWhere(['survey_id'=>$this->survey_id]); |
| 238 | 238 | |
| 239 | - if($this->respondent_id){ |
|
| 239 | + if ($this->respondent_id) { |
|
| 240 | 240 | // not itself |
| 241 | - $query->andWhere(['!=','respondent_id',$this->respondent_id]); |
|
| 241 | + $query->andWhere(['!=', 'respondent_id', $this->respondent_id]); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | $condition = ['or', |
| 245 | 245 | '`phone_number`=:phone_number', |
| 246 | 246 | '`alternative_phone_numbers` LIKE :phone_number2', |
| 247 | 247 | ]; |
| 248 | - $query->andWhere($condition,[':phone_number'=>$phone_number,':phone_number2'=>'%\"'.$phone_number.'\"%']); |
|
| 248 | + $query->andWhere($condition, [':phone_number'=>$phone_number, ':phone_number2'=>'%\"'.$phone_number.'\"%']); |
|
| 249 | 249 | |
| 250 | - if($query->count() > 0) { |
|
| 250 | + if ($query->count() > 0) { |
|
| 251 | 251 | $this->addError($attribute, |
| 252 | 252 | Yii::t('app', |
| 253 | - 'Invalid phone number "{0}"',[$phone_number] |
|
| 254 | - ).' '.Yii::t('app','Reason: {0}',[Yii::t('app','Duplicate phone number')]) |
|
| 253 | + 'Invalid phone number "{0}"', [$phone_number] |
|
| 254 | + ).' '.Yii::t('app', 'Reason: {0}', [Yii::t('app', 'Duplicate phone number')]) |
|
| 255 | 255 | ); |
| 256 | 256 | } |
| 257 | 257 | } |
@@ -261,29 +261,29 @@ discard block |
||
| 261 | 261 | * @param string $email_address Email address to check duplicates for |
| 262 | 262 | * @return bool |
| 263 | 263 | */ |
| 264 | - public function isEmailSurveyDuplicate($attribute, $email_address){ |
|
| 264 | + public function isEmailSurveyDuplicate($attribute, $email_address) { |
|
| 265 | 265 | $query = static::find(); |
| 266 | 266 | // check only this survey |
| 267 | 267 | $query->andWhere(['survey_id'=>$this->survey_id]); |
| 268 | 268 | // not itself |
| 269 | - if($this->respondent_id){ |
|
| 269 | + if ($this->respondent_id) { |
|
| 270 | 270 | // not itself |
| 271 | - $query->andWhere(['!=','respondent_id',$this->respondent_id]); |
|
| 271 | + $query->andWhere(['!=', 'respondent_id', $this->respondent_id]); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | $email_condition = ['or', |
| 275 | 275 | '`email_address`=:email_address', |
| 276 | 276 | '`alternative_email_addresses` LIKE :email_address2', |
| 277 | 277 | ]; |
| 278 | - $query->andWhere($email_condition,[':email_address'=>$email_address,':email_address2'=>'%\"'.$email_address.'\"%']); |
|
| 279 | - if($query->count() > 0){ |
|
| 278 | + $query->andWhere($email_condition, [':email_address'=>$email_address, ':email_address2'=>'%\"'.$email_address.'\"%']); |
|
| 279 | + if ($query->count() > 0) { |
|
| 280 | 280 | return true; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | $this->addError($attribute, |
| 284 | 284 | Yii::t('app', |
| 285 | - 'Invalid email address "{0}"',[$email_address] |
|
| 286 | - ).' '.Yii::t('app','Reason: {0}',[Yii::t('app','Duplicates some other address')]) |
|
| 285 | + 'Invalid email address "{0}"', [$email_address] |
|
| 286 | + ).' '.Yii::t('app', 'Reason: {0}', [Yii::t('app', 'Duplicates some other address')]) |
|
| 287 | 287 | ); |
| 288 | 288 | |
| 289 | 289 | return false; |
@@ -303,10 +303,10 @@ discard block |
||
| 303 | 303 | * @param string $token Respondents token |
| 304 | 304 | * @return static |
| 305 | 305 | */ |
| 306 | - public static function findByToken($token = null){ |
|
| 307 | - if($token){ |
|
| 306 | + public static function findByToken($token = null) { |
|
| 307 | + if ($token) { |
|
| 308 | 308 | $models = self::findByTokens([$token]); |
| 309 | - if (!empty($models)){ |
|
| 309 | + if (!empty($models)) { |
|
| 310 | 310 | return $models[0]; |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -317,10 +317,10 @@ discard block |
||
| 317 | 317 | * @param string[] $tokens Respondents tokens |
| 318 | 318 | * @return static[] |
| 319 | 319 | */ |
| 320 | - public static function findByTokens($tokens){ |
|
| 320 | + public static function findByTokens($tokens) { |
|
| 321 | 321 | /** @var static[] $model */ |
| 322 | 322 | $models = static::find() |
| 323 | - ->andWhere(['in','token', $tokens]) |
|
| 323 | + ->andWhere(['in', 'token', $tokens]) |
|
| 324 | 324 | ->all(); |
| 325 | 325 | return $models; |
| 326 | 326 | } |
@@ -329,11 +329,11 @@ discard block |
||
| 329 | 329 | * Check whether respondent has rejected this specific survey or has a hard bounce on e_mail address |
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | - public function getIsRejected(){ |
|
| 333 | - if(Rejection::rejectedByCode($this->token)){ |
|
| 332 | + public function getIsRejected() { |
|
| 333 | + if (Rejection::rejectedByCode($this->token)) { |
|
| 334 | 334 | return true; |
| 335 | 335 | } |
| 336 | - if(Rejection::bouncedByEmailAddress($this->email_address)){ |
|
| 336 | + if (Rejection::bouncedByEmailAddress($this->email_address)) { |
|
| 337 | 337 | return true; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @param string $email_address |
| 346 | 346 | * @return static |
| 347 | 347 | */ |
| 348 | - public static function getLatestByEmail($email_address){ |
|
| 348 | + public static function getLatestByEmail($email_address) { |
|
| 349 | 349 | /** @var static $model */ |
| 350 | 350 | $model = static::find() |
| 351 | 351 | ->andWhere(['email_address'=>$email_address]) |
@@ -357,8 +357,8 @@ discard block |
||
| 357 | 357 | /** |
| 358 | 358 | * @return string |
| 359 | 359 | */ |
| 360 | - public function getShortToken(){ |
|
| 361 | - if(Uuid::isValid($this->token)){ |
|
| 360 | + public function getShortToken() { |
|
| 361 | + if (Uuid::isValid($this->token)) { |
|
| 362 | 362 | $uuid = Uuid::fromString($this->token); |
| 363 | 363 | $shotUuid = new ShortUuid(); |
| 364 | 364 | return $shotUuid->encode($uuid); |