-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,20 @@ | ||
<?php | ||
namespace Fident\Web\Notifications; | ||
|
||
use Fident\Web\UserData\UserAttribute; | ||
use Packaged\Helpers\Objects; | ||
|
||
class FidentNotification | ||
{ | ||
protected $_id; | ||
protected $_created; | ||
protected $_username; | ||
protected $_attributes; | ||
protected $_type; | ||
|
||
const SUCCESS_RESPONSE = 'con'; | ||
|
||
public static function fromString($rawNotificationData) | ||
const DT_USER_UPDATE = 1; | ||
|
||
public static function generate($dataType, $jsonString) | ||
{ | ||
$notification = new static(); | ||
$notificationData = json_decode($rawNotificationData); | ||
$notification->_id = Objects::property($notificationData, 'ID'); | ||
$notification->_created = Objects::property($notificationData, 'Created'); | ||
$notification->_username = Objects::property($notificationData, 'Username'); | ||
$notification->_type = Objects::property($notificationData, 'Type'); | ||
$notification->_attributes = []; | ||
foreach(Objects::property($notificationData, 'Attributes', []) as $attr) | ||
switch($dataType) | ||
{ | ||
$notification->addAttribute(Objects::property($attr, 'Key'), Objects::property($attr, 'Value')); | ||
case self::DT_USER_UPDATE: | ||
return UserUpdateNotification::fromString($jsonString); | ||
} | ||
return $notification; | ||
} | ||
|
||
public function addAttribute($key, $value) | ||
{ | ||
$this->_attributes[$key] = new UserAttribute($key, $value); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->_id; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getCreated() | ||
{ | ||
return $this->_created; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getUsername() | ||
{ | ||
return $this->_username; | ||
} | ||
|
||
/** | ||
* @return UserAttribute[] | ||
*/ | ||
public function getAttributes() | ||
{ | ||
return $this->_attributes; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->_type; | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
namespace Fident\Web\Notifications; | ||
|
||
use Fident\Web\UserData\UserAttribute; | ||
use Packaged\Helpers\Objects; | ||
|
||
class UserUpdateNotification extends FidentNotification | ||
{ | ||
protected $_id; | ||
protected $_created; | ||
protected $_username; | ||
protected $_attributes; | ||
|
||
const SUCCESS_RESPONSE = 'con'; | ||
|
||
public static function fromString($rawNotificationData) | ||
{ | ||
$notification = new static(); | ||
$notificationData = json_decode($rawNotificationData); | ||
$notification->_id = Objects::property($notificationData, 'ID'); | ||
$notification->_created = Objects::property($notificationData, 'Created'); | ||
$notification->_username = Objects::property($notificationData, 'Username'); | ||
$notification->_attributes = []; | ||
foreach(Objects::property($notificationData, 'Attributes', []) as $attr) | ||
{ | ||
$notification->addAttribute(Objects::property($attr, 'Key'), Objects::property($attr, 'Value')); | ||
} | ||
return $notification; | ||
} | ||
|
||
public function addAttribute($key, $value) | ||
{ | ||
$this->_attributes[$key] = new UserAttribute($key, $value); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->_id; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getCreated() | ||
{ | ||
return $this->_created; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getUsername() | ||
{ | ||
return $this->_username; | ||
} | ||
|
||
/** | ||
* @return UserAttribute[] | ||
*/ | ||
public function getAttributes() | ||
{ | ||
return $this->_attributes; | ||
} | ||
} |