Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to filter notification target(s) by user(s) #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ class Notification implements \JsonSerializable
*/
private $wP;

/**
* List of strings that contains the users' identifiers responsible to filter who will receive the notification.
*
* @var array
*/
private $users;

/**
* Utility function used to create a new notification.
*
Expand Down Expand Up @@ -647,7 +654,17 @@ public function getWP()
{
return $this->wP;
}


/**
* Gets the list of strings that contains the users' identifiers responsible to filter who will receive the notification.
*
* @return string[] string list of users identifiers
*/
public function getUsers()
{
return $this->users;
}

/**
* Creates a JSON representation of this request.
*
Expand All @@ -674,6 +691,7 @@ public function jsonSerialize()
isset($this->richPageId) ? $json['rich_page_id'] = $this->richPageId : false;
isset($this->sendRate)? $json['send_rate'] = $this->sendRate : false;
isset($this->timezone)? $json['timezone'] = $this->timezone : false;
isset($this->users)? $json['users'] = $this->users : false;

if (isset($this->conditions)) {
$conditionsArray = [];
Expand Down Expand Up @@ -1162,4 +1180,18 @@ public function setWP(WP $wP)

return $this;
}

/**
* Sets the list of users identifiers
*
* @param array $users
*
* @return \Gomoob\Pushwoosh\Model\Notification\Notification this instance.
*/
public function setUsers($users)
{
$this->users = $users;

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ public function testIsSetIgnoreUserTimezone()
$this->assertFalse($notification->isIgnoreUserTimezone());
}

/**
* Test method for the `getUsers()` and `setUsers($users)` functions.
*/
public function testGetSetUsers()
{
$notification = new Notification();
$this->assertEmpty($notification->getUsers());
$users = ['1', '2', '3', '4'];
$this->assertSame($notification, $notification->setUsers($users));
$this->assertSame($users, $notification->getUsers());
}

/**
* Test method for the `jsonSerialize()` function.
*/
Expand Down Expand Up @@ -587,10 +599,11 @@ public function testJsonSerialize()
->setCount(3)
->setType('Tile')
)
->setUsers(['1', '2', '3'])
->jsonSerialize();

// Test the generic properties
$this->assertCount(65, $array);
$this->assertCount(66, $array);
$this->assertSame('now', $array['send_date']);
$this->assertSame('America/New_York', $array['timezone']);
$this->assertTrue($array['ignore_user_timezone']);
Expand Down Expand Up @@ -635,6 +648,7 @@ public function testJsonSerialize()
$this->assertSame('value1', $array['conditions'][2][2][1]);
$this->assertSame('value2', $array['conditions'][2][2][2]);
$this->assertSame('CAMPAIGN', $array['campaign']);
$this->assertSame(['1', '2', '3'], $array['users']);

// Test the ADM parameters
$this->assertSame('http://example.com/banner.png', $array['adm_banner']);
Expand Down