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

1632: Users and channels in BPI #14

Open
wants to merge 9 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
361 changes: 347 additions & 14 deletions Bpi/Sdk/Bpi.php

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions Bpi/Sdk/ChannelList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Bpi\Sdk;

use Bpi\Sdk\Item\Channel;

/**
* A list of channels.
*/
class ChannelList extends ItemList
{
/**
* {@inheritdoc}
*/
protected function buildItems()
{
$items = [];
foreach ($this->element->xpath('/channels/channel') as $el) {
$items[] = new Channel($el);
}

return $items;
}
}
70 changes: 70 additions & 0 deletions Bpi/Sdk/GroupOperationResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
namespace Bpi\Sdk;

/**
* TODO please add a documentation for this class.
*/
class GroupOperationResult
{
/**
* @var \SimpleXMLElement
*/
protected $element;

/**
* @var int
*/
protected $code;

/**
* @var int
*/
protected $skipped;

/**
* @var int
*/
protected $success;

/**
* @var array
*/
protected $successIds;

public function __construct(\SimpleXMLElement $element)
{
$this->element = $element;

if (isset($element)) {
$this->code = (int)$element->code;
$this->skipped = (int)$element->skipped;
$this->success = (int)$element->success;
if (isset($element->success_list)) {
$this->successIds = [];
foreach ($element->success_list->item as $item) {
$this->successIds[] = (string)$item;
}
}
}
}

public function getCode()
{
return $this->code;
}

public function getSkipped()
{
return $this->skipped;
}

public function getSuccess()
{
return $this->success;
}

public function getSuccessIds()
{
return $this->successIds;
}
}
58 changes: 58 additions & 0 deletions Bpi/Sdk/Item/Agency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Bpi\Sdk\Item;

use Bpi\Sdk\GenericDocument;

class Agency
{
/**
* @var string
*/
private $id;

/**
* @var string
*/
private $name;

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @return string
*/
private function setId($id)
{
$this->id = $id;
return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $name
* @return Channel
*/
public function setName($name)
{
$this->name = $name;
return $this;
}

public function __construct(\SimpleXMLElement $el)
{
$this->setId((string)$el->id);
$this->setName((string)$el->name);
}
}
187 changes: 187 additions & 0 deletions Bpi/Sdk/Item/Channel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?php
namespace Bpi\Sdk\Item;

class Channel
{
/**
* @var string
*/
private $id;

/**
* @var string
*/
private $name;

/**
* @var string
*/
private $description;

/**
* @var string
*/
private $adminId;

/**
* @var User
*/
private $admin;

/**
* @var array
*/
private $editors;

/**
* @var array
*/
private $nodes;

/**
* @var DateTime
*/
private $nodeLastAddedAt;

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @return string
*/
private function setId($id)
{
$this->id = $id;
return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $name
* @return Channel
*/
public function setName($name)
{
$this->name = $name;
return $this;
}

/**
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* @param string $description
* @return Channel
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}

/**
* @return string
*/
public function getAdminId()
{
return $this->adminId;
}

/**
* @param string $adminId
* @return Channel
*/
public function setAdminId($adminId)
{
$this->adminId = $adminId;
return $this;
}

/**
* @return User
*/
public function getAdmin()
{
return $this->admin;
}

/**
* @param User $admin
* @return Channel
*/
public function setAdmin($admin)
{
$this->admin = $admin;
return $this;
}

/**
* @return array
*/
public function getEditors()
{
return $this->editors;
}

/**
* @return array
*/
public function getNodes()
{
return $this->nodes;
}

/**
* @return DateTime
*/
public function getNodeLastAddedAt()
{
return $this->nodeLastAddedAt;
}

public function __construct(\SimpleXMLElement $el)
{
$this->setId((string)$el->id);
$this->setName((string)$el->channel_name);
$this->setDescription((string)$el->channel_description);

$admin = new User($el->channel_admin);
$this->setAdminId($admin->getId());
$this->setAdmin($admin);

if (isset($el->users)) {
$users = [];
foreach ($el->users->user as $user) {
$users[] = new User($user);
}
$this->editors = $users;
}

if (isset($el->nodes)) {
$nodes = [];
foreach ($el->nodes->node as $node) {
$nodes[] = (string)$node;
}
$this->nodes = $nodes;
}

$this->nodeLastAddedAt = (string)$el->node_last_added_at ? new \DateTime((string)$el->node_last_added_at) : null;
}
}
1 change: 0 additions & 1 deletion Bpi/Sdk/Item/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function getAssets()
}
$assets[$type][] = $properties;
}

$this->assets = $assets;
}

Expand Down
Loading