@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @author Zilvinas Vaira |
| 7 | 7 | * |
| 8 | 8 | */ |
| 9 | -class SilverbulletUser extends PersistentEntity{ |
|
| 9 | +class SilverbulletUser extends PersistentEntity { |
|
| 10 | 10 | |
| 11 | 11 | const LEVEL_GREEN = 0; |
| 12 | 12 | const LEVEL_YELLOW = 1; |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | * @param int $profileId |
| 90 | 90 | * @param string $username |
| 91 | 91 | */ |
| 92 | - public function __construct($profileId, $username){ |
|
| 92 | + public function __construct($profileId, $username) { |
|
| 93 | 93 | parent::__construct(self::TABLE, self::TYPE_INST); |
| 94 | 94 | $this->setAttributeType(self::PROFILEID, Attribute::TYPE_INTEGER); |
| 95 | 95 | |
| 96 | 96 | $this->set(self::PROFILEID, $profileId); |
| 97 | 97 | $this->set(self::USERNAME, $username); |
| 98 | 98 | //$this->set(self::EXPIRY, 'NOW() + INTERVAL 1 WEEK'); |
| 99 | - $this->defaultUserExpiry = date('Y-m-d H:i:s',strtotime("today")); |
|
| 99 | + $this->defaultUserExpiry = date('Y-m-d H:i:s', strtotime("today")); |
|
| 100 | 100 | //$this->set(self::EXPIRY, $this->defaultUserExpiry); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * {@inheritDoc} |
| 106 | 106 | * @see \web\lib\admin\domain\PersistentInterface::validate() |
| 107 | 107 | */ |
| 108 | - public function validate(){ |
|
| 108 | + public function validate() { |
|
| 109 | 109 | return ( |
| 110 | 110 | !empty($this->get(self::PROFILEID)) |
| 111 | 111 | ); |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param string $date Takes any string value that can passed to strtotime() function. |
| 118 | 118 | */ |
| 119 | - public function setExpiry($date){ |
|
| 119 | + public function setExpiry($date) { |
|
| 120 | 120 | $tokenExpiry = date('Y-m-d H:i:s', strtotime($date)); |
| 121 | - if($tokenExpiry > $this->defaultUserExpiry){ |
|
| 121 | + if ($tokenExpiry > $this->defaultUserExpiry) { |
|
| 122 | 122 | $this->set(self::EXPIRY, $tokenExpiry); |
| 123 | - }else{ |
|
| 123 | + } else { |
|
| 124 | 124 | $this->clear(); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | /** |
| 129 | 129 | * |
| 130 | 130 | */ |
| 131 | - public function makeAcknowledged(){ |
|
| 132 | - $this->set(self::LAST_ACKNOWLEDGE, date('Y-m-d H:i:s',strtotime("now"))); |
|
| 131 | + public function makeAcknowledged() { |
|
| 132 | + $this->set(self::LAST_ACKNOWLEDGE, date('Y-m-d H:i:s', strtotime("now"))); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return int One of the following constants LEVEL_GREEN, LEVEL_YELLOW, LEVEL_RED. |
| 139 | 139 | */ |
| 140 | - public function getAcknowledgeLevel(){ |
|
| 140 | + public function getAcknowledgeLevel() { |
|
| 141 | 141 | $max = CONFIG_CONFASSISTANT['SILVERBULLET']['gracetime'] ?? SilverbulletUser::MAX_ACKNOWLEDGE; |
| 142 | 142 | $days = $this->getAcknowledgeDays(); |
| 143 | - if($days <= $max * 0.2 && $days > $max * 0.1){ |
|
| 143 | + if ($days <= $max * 0.2 && $days > $max * 0.1) { |
|
| 144 | 144 | return self::LEVEL_YELLOW; |
| 145 | - }elseif ($days <= $max * 0.1){ |
|
| 145 | + }elseif ($days <= $max * 0.1) { |
|
| 146 | 146 | return self::LEVEL_RED; |
| 147 | - }else{ |
|
| 147 | + } else { |
|
| 148 | 148 | return self::LEVEL_GREEN; |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * |
| 155 | 155 | * @return number Number of days from 0 to maximum period. |
| 156 | 156 | */ |
| 157 | - public function getAcknowledgeDays(){ |
|
| 157 | + public function getAcknowledgeDays() { |
|
| 158 | 158 | $max = CONFIG_CONFASSISTANT['SILVERBULLET']['gracetime'] ?? SilverbulletUser::MAX_ACKNOWLEDGE; |
| 159 | 159 | $lastAcknowledge = strtotime($this->get(self::LAST_ACKNOWLEDGE)); |
| 160 | 160 | $now = strtotime('now'); |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | return $days > 0 ? $days : 0; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public function getProfileId(){ |
|
| 165 | + public function getProfileId() { |
|
| 166 | 166 | return $this->get(self::PROFILEID); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public function getUsername(){ |
|
| 169 | + public function getUsername() { |
|
| 170 | 170 | return $this->get(self::USERNAME); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return boolean |
| 176 | 176 | */ |
| 177 | - public function isExpired(){ |
|
| 177 | + public function isExpired() { |
|
| 178 | 178 | $expiryTime = strtotime($this->get(self::EXPIRY)); |
| 179 | 179 | $currentTime = time(); |
| 180 | 180 | return $currentTime > $expiryTime; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | - public function getExpiry(){ |
|
| 187 | + public function getExpiry() { |
|
| 188 | 188 | return date('Y-m-d', strtotime($this->get(self::EXPIRY))); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return \web\lib\admin\domain\SilverbulletCertificate |
| 194 | 194 | */ |
| 195 | - public function getCertificates(){ |
|
| 195 | + public function getCertificates() { |
|
| 196 | 196 | return $this->certificates; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * |
| 201 | 201 | * @return \web\lib\admin\domain\SilverbulletInvitation |
| 202 | 202 | */ |
| 203 | - public function getInvitations(){ |
|
| 203 | + public function getInvitations() { |
|
| 204 | 204 | return $this->invitations; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @return boolean |
| 210 | 210 | */ |
| 211 | - public function hasCertificates(){ |
|
| 211 | + public function hasCertificates() { |
|
| 212 | 212 | return count($this->certificates) > 0; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | * |
| 217 | 217 | * @return boolean |
| 218 | 218 | */ |
| 219 | - public function hasActiveCertificates(){ |
|
| 219 | + public function hasActiveCertificates() { |
|
| 220 | 220 | $count = 0; |
| 221 | 221 | foreach ($this->certificates as $certificate) { |
| 222 | - if(!$certificate->isExpired() && !$certificate->isRevoked()){ |
|
| 222 | + if (!$certificate->isExpired() && !$certificate->isRevoked()) { |
|
| 223 | 223 | $count++; |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @param boolean $isDeactivated |
| 233 | 233 | */ |
| 234 | - public function setDeactivated($isDeactivated, $profile){ |
|
| 234 | + public function setDeactivated($isDeactivated, $profile) { |
|
| 235 | 235 | $this->set(self::DEACTIVATION_STATUS, $isDeactivated ? self::INACTIVE : self::ACTIVE); |
| 236 | - if($isDeactivated){ |
|
| 236 | + if ($isDeactivated) { |
|
| 237 | 237 | $this->set(self::DEACTIVATION_TIME, date('Y-m-d H:i:s', strtotime("now"))); |
| 238 | 238 | foreach ($this->certificates as $certificate) { |
| 239 | 239 | $certificate->revoke($profile); |
| 240 | 240 | } |
| 241 | - }else{ |
|
| 241 | + } else { |
|
| 242 | 242 | $this->set(self::DEACTIVATION_TIME, '2000-01-01 00:00:00'); |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @return boolean |
| 249 | 249 | */ |
| 250 | - public function isDeactivated(){ |
|
| 250 | + public function isDeactivated() { |
|
| 251 | 251 | return $this->get(self::DEACTIVATION_STATUS) == self::INACTIVE; |
| 252 | 252 | } |
| 253 | 253 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * {@inheritDoc} |
| 257 | 257 | * @see \web\lib\admin\domain\PersistentInterface::load() |
| 258 | 258 | */ |
| 259 | - public function load($searchAttribute = null){ |
|
| 259 | + public function load($searchAttribute = null) { |
|
| 260 | 260 | $state = parent::load(); |
| 261 | 261 | $this->certificates = SilverbulletCertificate::getList($this, $searchAttribute); |
| 262 | 262 | $this->invitations = SilverbulletInvitation::getList($this); |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * {@inheritDoc} |
| 269 | 269 | * @see \web\lib\admin\domain\PersistentInterface::delete() |
| 270 | 270 | */ |
| 271 | - public function delete(){ |
|
| 271 | + public function delete() { |
|
| 272 | 272 | $state = parent::delete(); |
| 273 | 273 | foreach ($this->certificates as $certificate) { |
| 274 | 274 | $certificate->delete(); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @param integer $userId |
| 285 | 285 | * @return \web\lib\admin\domain\SilverbulletUser |
| 286 | 286 | */ |
| 287 | - public static function prepare($userId){ |
|
| 287 | + public static function prepare($userId) { |
|
| 288 | 288 | $instance = new SilverbulletUser(null, ''); |
| 289 | 289 | $instance->set(self::ID, $userId); |
| 290 | 290 | return $instance; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $tokenExpiry = date('Y-m-d H:i:s', strtotime($date)); |
| 121 | 121 | if($tokenExpiry > $this->defaultUserExpiry){ |
| 122 | 122 | $this->set(self::EXPIRY, $tokenExpiry); |
| 123 | - }else{ |
|
| 123 | + } else{ |
|
| 124 | 124 | $this->clear(); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | $days = $this->getAcknowledgeDays(); |
| 143 | 143 | if($days <= $max * 0.2 && $days > $max * 0.1){ |
| 144 | 144 | return self::LEVEL_YELLOW; |
| 145 | - }elseif ($days <= $max * 0.1){ |
|
| 145 | + } elseif ($days <= $max * 0.1){ |
|
| 146 | 146 | return self::LEVEL_RED; |
| 147 | - }else{ |
|
| 147 | + } else{ |
|
| 148 | 148 | return self::LEVEL_GREEN; |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | foreach ($this->certificates as $certificate) { |
| 239 | 239 | $certificate->revoke($profile); |
| 240 | 240 | } |
| 241 | - }else{ |
|
| 241 | + } else{ |
|
| 242 | 242 | $this->set(self::DEACTIVATION_TIME, '2000-01-01 00:00:00'); |
| 243 | 243 | } |
| 244 | 244 | } |