Add Issue Tracker model to API

This commit is contained in:
kiswa 2016-08-25 10:28:01 +00:00
parent af3d281bb4
commit 8993fbb26b
3 changed files with 84 additions and 1 deletions

View File

@ -6,6 +6,7 @@ class Board extends BaseModel {
public $columns = [];
public $categories = [];
public $auto_actions = [];
public $issue_trackers = [];
public $users = [];
public function __construct($container, $id = 0) {
@ -23,6 +24,7 @@ class Board extends BaseModel {
$bean->xownColumnList = [];
$bean->xownCategoryList = [];
$bean->xownAutoActionList = [];
$bean->xownIssueTrackerList = [];
$bean->sharedUserList = [];
foreach($this->columns as $col) {
@ -40,6 +42,11 @@ class Board extends BaseModel {
$this->bean->xownAutoActionList[] = $act->bean;
}
foreach($this->issue_trackers as $ist) {
$ist->updateBean();
$this->bean->xownIssueTrackerList[] = $ist->bean;
}
foreach($this->users as $user) {
$user->updateBean();
$this->bean->sharedUserList[] = $user->bean;
@ -53,7 +60,7 @@ class Board extends BaseModel {
return;
}
if($bean->id === 0) {
if ($bean->id === 0) {
return;
}
@ -76,6 +83,11 @@ class Board extends BaseModel {
new AutoAction($this->container, $item->id);
}
foreach($bean->xownIssueTrackerList as $item) {
$this->issue_trackers[] =
new IssueTracker($this->container, $item->id);
}
foreach($bean->sharedUserList as $item) {
$this->users[] = new User($this->container, $item->id);
}
@ -115,6 +127,13 @@ class Board extends BaseModel {
}
}
if (isset($obj->issue_trackers)) {
foreach($obj->issue_trackers as $item) {
$this->issue_trackers[] =
new IssueTracker($this->container, $item->id);
}
}
if (isset($obj->users)) {
foreach($obj->users as $item) {
$this->users[] = new User($this->container, $item->id);
@ -136,6 +155,7 @@ class Board extends BaseModel {
$this->columns = [];
$this->categories = [];
$this->auto_actions = [];
$this->issue_trackers = [];
$this->users = [];
}
}

View File

@ -2,6 +2,7 @@
class Category extends BaseModel {
public $id = 0;
public $name = '';
public $default_task_color = '';
public $board_id = 0;
public function __construct($container, $id = 0) {
@ -15,6 +16,7 @@ class Category extends BaseModel {
$bean->id = $this->id;
$bean->name = $this->name;
$bean->default_task_color = $this->default_task_color;
$bean->board_id = $this->board_id;
}
@ -50,6 +52,7 @@ class Category extends BaseModel {
try {
$this->id = (int) $obj->id;
$this->name = $obj->name;
$this->default_task_color = $obj->default_task_color;
$this->board_id = $obj->board_id;
} catch (Exception $ex) {
$this->is_valid = false;

View File

@ -0,0 +1,60 @@
<?php
class IssueTracker extends BaseModel {
public $id = 0;
public $url = '';
public $regex = '';
public function __construct($container, $id = 0) {
parent::__construct('issue_tracker', $id, $container);
$this->loadFromBean($this->bean);
}
public function updateBean() {
$bean = $this->bean;
$bean->url = $this->url;
$bean->regex = $this->regex;
}
public function loadFromBean($bean) {
if (!isset($bean->id)) {
$this->is_valid = false;
return;
}
if ($bean->id === 0) {
return;
}
$this->is_valid = true;
$this->loadPropertiesFrom($bean);
}
public function loadFromJson($json) {
$obj = json_decode($json);
if (!isset($obj->id)) {
$this->is_valid = false;
return;
}
$this->is_valid = true;
$this->loadPropertiesFrom($obj);
}
private function loadPropertiesFrom($obj) {
try {
$this->id = (int) $obj->id;
$this->url = $obj->url;
$this->regex = $obj->regex;
} catch (Exception $ex) {
$this->is_valid = false;
}
}
}