Skip to content

Commit

Permalink
Merge pull request #200 from ioigoume/Rest_API_inlcude_extra_info_to_…
Browse files Browse the repository at this point in the history
…roles

Rest_API_inlcude_extra_info_to_roles
  • Loading branch information
NicolasLiampotis authored Feb 10, 2023
2 parents 7d5319f + ff51920 commit cf19a33
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/Controller/CoPersonRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,16 @@ function retrieve($coid) {
);
}

// XXX convertRestResponse will only care about the actual model and will
// remove all related data. I do not want that since i might need
// additional metadata. As a result we will copy the extra data inside
// the basic model
foreach ($records as $idx => $rec) {
if(!empty($rec['CoPerson'])) {
$records[$idx]['CoPersonRole']['CoPerson'] = $rec['CoPerson'];
}
}


$this->set('co_person_roles', $this->Api->convertRestResponse($records));
$this->Api->restResultHeader(200, "OK");
Expand Down
23 changes: 22 additions & 1 deletion app/Model/CoPersonRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,28 @@ public function findAllMembers($coid, $cou_name) {
$args['conditions']['Cou.name'] = $cou_name;
$args['conditions']['Cou.co_id'] = $coid;
$args['conditions'][] = 'CoPersonRole.deleted IS NOT TRUE';
$args['contain'] = false;
$args['contain'] = array(
'CoPerson' => array(
'Identifier' => array(
'conditions' => array(
'Identifier.deleted != true',
'Identifier.identifier_id is NULL'
)
),
'EmailAddress' => array(
'conditions' => array(
'EmailAddress.deleted != true',
'EmailAddress.email_address_id is NULL'
)
),
'Name' => array(
'conditions' => array(
'Name.deleted != true',
'Name.name_id is NULL'
)
),
),
);

return $this->find('all', $args);
}
Expand Down
27 changes: 26 additions & 1 deletion app/View/CoPersonRoles/json/retrieve.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(isset($$modelpl)) {
"Id" => $m[$req]['Id']);

foreach(array_keys($m[$req]) as $k) {
if($m[$req][$k] !== null) {
if($m[$req][$k] !== null && !is_array($m[$req][$k])) {
// Some attributes are treated specially

if($req == 'CoOrgIdentityLink') {
Expand Down Expand Up @@ -96,6 +96,31 @@ if(isset($$modelpl)) {
break;
}
}

if(!empty($m[$req]["CoPerson"])) {
foreach ($m[$req]['CoPerson'] as $key => $value) {
// We are only interested in the linked Models
// The value is my Model name
if(is_array($value)) {
$a['Person'][$key] = array();
foreach ($value as $idx => $data) {
if($key == 'Identifier') {
$a['Person'][$key][$idx]['type'] = $data['type'];
$a['Person'][$key][$idx]['identifier'] = $data['identifier'];
} elseif ($key == 'EmailAddress') {
$a['Person'][$key][$idx]['type'] = $data['type'];
$a['Person'][$key][$idx]['mail'] = $data['mail'];
$a['Person'][$key][$idx]['verified'] = $data['verified'];
} elseif ($key == 'Name') {
$a['Person'][$key][$idx]['type'] = $data['type'];
$a['Person'][$key][$idx]['given'] = $data['given'];
$a['Person'][$key][$idx]['family'] = $data['family'];
$a['Person'][$key][$idx]['middle'] = $data['middle'];
}
}
}
}
}
}

$ms[] = $a;
Expand Down

0 comments on commit cf19a33

Please sign in to comment.