Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
B
bat_api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
bat_api
Commits
7b22e8a7
Commit
7b22e8a7
authored
Feb 04, 2016
by
Ronald Ashri
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request
#1
from Roomify/aBatUnitIsNotNecessarilyADrupalBatUnit
A bat unit is not necessarily a drupal bat unit
parents
dd6b0bdf
ce0c69d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
22 deletions
+36
-22
bat_api.module
bat_api.module
+36
-22
No files found.
bat_api.module
View file @
7b22e8a7
...
...
@@ -228,19 +228,26 @@ function bat_api_services_resources() {
'access arguments'
=>
array
(
'access events index service'
),
'args'
=>
array
(
array
(
'name'
=>
'
uni
t_ids'
,
'name'
=>
'
targe
t_ids'
,
'type'
=>
'string'
,
'description'
=>
t
(
'
Unit
IDs'
),
'source'
=>
array
(
'param'
=>
'
uni
t_ids'
),
'description'
=>
t
(
'
Targe Entity
IDs'
),
'source'
=>
array
(
'param'
=>
'
targe
t_ids'
),
'optional'
=>
FALSE
,
),
array
(
'name'
=>
'
uni
t_types'
,
'name'
=>
'
targe
t_types'
,
'type'
=>
'string'
,
'description'
=>
t
(
'
Uni
t Types'
),
'source'
=>
array
(
'param'
=>
'
uni
t_types'
),
'description'
=>
t
(
'
Targe
t Types'
),
'source'
=>
array
(
'param'
=>
'
targe
t_types'
),
'optional'
=>
TRUE
,
),
array
(
'name'
=>
'target_entity_type'
,
'type'
=>
'string'
,
'description'
=>
t
(
'Target Entity Type'
),
'source'
=>
array
(
'param'
=>
'target_entity_type'
),
'optional'
=>
FALSE
,
),
array
(
'name'
=>
'start_date'
,
'type'
=>
'string'
,
...
...
@@ -529,17 +536,18 @@ function bat_api_services_edit_unit($unit_id, $bat_unit_data) {
/**
* Retrieve a list of events.
*
* @param $unit_ids
* @param $unit_types
* @param $target_ids
* @param $target_types
* @param $target_entity_type
* @param $start_date
* @param $end_date
* @param $event_types
*/
function
bat_api_services_events_index
(
$
unit_ids
,
$unit_types
,
$start_date
,
$end_date
,
$event_types
)
{
function
bat_api_services_events_index
(
$
target_ids
,
$target_types
,
$target_entity_type
,
$start_date
,
$end_date
,
$event_types
)
{
$return
=
new
stdClass
();
$return
->
sessid
=
session_id
();
$
unit_types
=
array_filter
(
explode
(
','
,
$uni
t_types
));
$
target_types
=
array_filter
(
explode
(
','
,
$targe
t_types
));
$types
=
array_filter
(
explode
(
','
,
$event_types
));
...
...
@@ -561,12 +569,12 @@ function bat_api_services_events_index($unit_ids, $unit_types, $start_date, $end
$start_date_object
=
$today
;
}
$ids
=
explode
(
','
,
$
uni
t_ids
);
$ids
=
explode
(
','
,
$
targe
t_ids
);
$units
=
array
();
foreach
(
$ids
as
$id
)
{
if
(
$
bat_unit
=
bat_unit_load
(
$id
))
{
if
(
in_array
(
$
bat_unit
->
type
,
$unit_types
)
||
empty
(
$uni
t_types
))
{
if
(
$
target_entity
=
entity_load_single
(
$target_entity_type
,
$id
))
{
if
(
in_array
(
$
target_entity
->
type
,
$target_types
)
||
empty
(
$targe
t_types
))
{
// Setting the default value to 0 since we are dealing with the events array
// so getting event IDs.
$units
[]
=
new
Unit
(
$id
,
0
);
...
...
@@ -592,7 +600,7 @@ function bat_api_services_events_index($unit_ids, $unit_types, $start_date, $end
$events_json
[]
=
array
(
'id'
=>
(
string
)
$key
.
$unit_id
,
'bat_id'
=>
$event
->
getValue
(),
'resourceId'
=>
'S'
.
$
uni
t_id
,
'resourceId'
=>
'S'
.
$
targe
t_id
,
)
+
$event
->
toJson
(
$event_formatter
);
}
}
...
...
@@ -719,12 +727,15 @@ function bat_api_services_edit_event($event_id, $bat_event_data) {
$event
->
data
=
(
isset
(
$bat_event_data
[
'data'
]))
?
$bat_event_data
[
'data'
]
:
$event
->
data
;
$event
->
changed
=
REQUEST_TIME
;
// Set new unit_id if present.
if
(
isset
(
$bat_event_data
[
'unit_id'
]))
{
$event
->
event_unit_reference
=
array
(
// Set new target_id if present.
if
(
isset
(
$bat_event_data
[
'target_id'
]))
{
$event_type
=
bat_event_type_load
(
$event
->
type
);
// Construct target entity reference field name using this event type's target entity type.
$target_field_name
=
'event_'
.
$event_type
->
target_entity_type
.
'_reference'
;
$event
->
{
$target_field_name
}
=
array
(
LANGUAGE_NONE
=>
array
(
0
=>
array
(
'target_id'
=>
$bat_event_data
[
'
uni
t_id'
],
'target_id'
=>
$bat_event_data
[
'
targe
t_id'
],
)
)
);
...
...
@@ -753,12 +764,15 @@ function bat_api_services_edit_event($event_id, $bat_event_data) {
$event
->
data
=
(
isset
(
$bat_event_data
[
'data'
]))
?
$bat_event_data
[
'data'
]
:
NULL
;
$event
->
changed
=
REQUEST_TIME
;
// Set new unit_id if present.
if
(
isset
(
$bat_event_data
[
'unit_id'
]))
{
$event
->
event_unit_reference
=
array
(
// Set new target_id if present.
if
(
isset
(
$bat_event_data
[
'target_id'
]))
{
$event_type
=
bat_event_type_load
(
$event
->
type
);
// Construct target entity reference field name using this event type's target entity type.
$target_field_name
=
'event_'
.
$event_type
->
target_entity_type
.
'_reference'
;
$event
->
{
$target_field_name
}
=
array
(
LANGUAGE_NONE
=>
array
(
0
=>
array
(
'target_id'
=>
$bat_event_data
[
'
uni
t_id'
],
'target_id'
=>
$bat_event_data
[
'
targe
t_id'
],
)
)
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment