Skip to content
Merged
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
89 changes: 80 additions & 9 deletions src/Clearvox/Asterisk/Queue/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,32 @@ class Member
*/
protected $ringInUse;

/**
* @var int|null
*/
protected $wrapupTime;
Comment thread
filip3oliveira marked this conversation as resolved.

/**
* @var bool|null
*/
protected $paused;
Comment thread
filip3oliveira marked this conversation as resolved.

public function __construct(
$interface,
$penalty = null,
$memberName = null,
$stateInterface = null,
$ringInUse = null
$ringInUse = null,
$wrapupTime = null,
$paused = null
) {
$this->interface = $interface;
$this->penalty = $penalty;
$this->memberName = $memberName;
$this->stateInterface = $stateInterface;
$this->ringInUse = $ringInUse;
$this->wrapupTime = is_null($wrapupTime) ? null : (int)$wrapupTime;
$this->paused = is_null($paused) ? null : (boolean)$paused;
}

public function getInterface()
Expand Down Expand Up @@ -119,31 +133,88 @@ public function setRingInUse($ringInUse)
return $this;
}

/**
* @return int|null
*/
Comment thread
filip3oliveira marked this conversation as resolved.
public function getWrapupTime()
{
return $this->wrapupTime;
}

/**
* @param int|null $wrapupTime
* @return Member
*/
Comment thread
filip3oliveira marked this conversation as resolved.
public function setWrapupTime($wrapupTime)
{
$this->wrapupTime = $wrapupTime;
return $this;
}

/**
* @return bool|null
*/
Comment thread
filip3oliveira marked this conversation as resolved.
public function getPaused()
{
return $this->paused;
}

/**
* @param boolean|null $paused Null unsets (omits the field), matching the constructor.
* @return Member
*/
public function setPaused($paused)
{
$this->paused = is_null($paused) ? null : (boolean)$paused;
return $this;
}

public function toString()
{
if(!is_null($this->ringInUse)) {
$line[0] = ($this->ringInUse ? 'yes' : 'no');
// Asterisk's static member fields, in positional order, are:
// interface,penalty,membername,state_interface,ringinuse,wrapuptime,paused
// Fields below the highest one actually set must be emitted (even if empty)
// to keep every later field in its correct position.
if (!is_null($this->paused)) {
$line[0] = ($this->paused ? '1' : '0');
$line[1] = null;
$line[2] = null;
$line[3] = null;
$line[4] = null;
$line[5] = null;
}

if (!is_null($this->stateInterface)) {
$line[1] = $this->stateInterface;
if (!is_null($this->wrapupTime)) {
$line[1] = $this->wrapupTime;
$line[2] = null;
$line[3] = null;
$line[4] = null;
$line[5] = null;
}

if (!is_null($this->memberName)) {
$line[2] = $this->memberName;
if(!is_null($this->ringInUse)) {
$line[2] = ($this->ringInUse ? 'yes' : 'no');
$line[3] = null;
$line[4] = null;
$line[5] = null;
}

if (!is_null($this->stateInterface)) {
$line[3] = $this->stateInterface;
$line[4] = null;
$line[5] = null;
}

if (!is_null($this->memberName)) {
$line[4] = $this->memberName;
$line[5] = null;
}

if (!is_null($this->penalty)) {
$line[3] = $this->penalty;
$line[5] = $this->penalty;
}

$line[4] = $this->interface;
$line[6] = $this->interface;

return 'member => ' . implode(',', array_reverse($line));
}
Expand Down
55 changes: 55 additions & 0 deletions tests/Clearvox/Asterisk/Queue/MemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,59 @@ public function testToString()
$this->member->toString()
);
}

public function testToStringWithPausedOnly()
{
$this->member->setPaused(true);

$this->assertEquals(
'member => Local/1000,,,,,,1',
$this->member->toString()
);
}

public function testToStringWithPausedFalse()
{
$this->member->setPaused(false);

$this->assertEquals(
'member => Local/1000,,,,,,0',
$this->member->toString()
);
}

public function testToStringWithAllFields()
{
$this->member
->setMemberName('John Smith')
->setPenalty(10)
->setRingInUse(true)
->setStateInterface('SIP/2000')
->setWrapupTime(30)
->setPaused(true);

$this->assertEquals(
'member => Local/1000,10,John Smith,SIP/2000,yes,30,1',
$this->member->toString()
);
}

public function testToStringWithWrapupTimeOnly()
{
$this->member->setWrapupTime(30);

$this->assertEquals(
'member => Local/1000,,,,,30',
$this->member->toString()
);
}

public function testSetPausedNullUnsetsTheField()
{
$this->member->setPaused(true);
$this->member->setPaused(null);

$this->assertNull($this->member->getPaused());
$this->assertEquals('member => Local/1000', $this->member->toString());
}
}