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
93ed3190
Commit
93ed3190
authored
Feb 09, 2016
by
Nicolò Caruso
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle generic event target_entity_type
parent
7b22e8a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
68 deletions
+78
-68
bat_api.module
bat_api.module
+78
-68
No files found.
bat_api.module
View file @
93ed3190
...
...
@@ -363,48 +363,54 @@ function bat_api_services_resources() {
* @param $limit
*/
function
bat_api_services_units_index_calendar
(
$unit_types
,
$unit_ids
,
$event_type
,
$offset
,
$limit
)
{
$create_event_access
=
FALSE
;
if
(
bat_event_access
(
'create'
,
bat_event_create
(
array
(
'type'
=>
$event_type
))))
{
$create_event_access
=
TRUE
;
}
$ids
=
array_filter
(
explode
(
','
,
$unit_ids
));
$types
=
(
$unit_types
==
'all'
)
?
array
()
:
array_filter
(
explode
(
','
,
$unit_types
));
$query
=
db_select
(
'bat_units'
,
'n'
)
->
fields
(
'n'
,
array
(
'unit_id'
,
'type_id'
,
'type'
,
'name'
));
if
(
!
empty
(
$ids
))
{
$query
->
condition
(
'unit_id'
,
$ids
,
'IN'
);
if
(
$unit_types
==
'all'
)
{
$types
=
array
();
foreach
(
bat_unit_get_types
()
as
$type
=>
$info
)
{
$types
[]
=
$type
;
}
}
if
(
!
empty
(
$types
))
{
$
query
->
condition
(
'type_id'
,
$types
,
'IN'
);
else
{
$
types
=
array_filter
(
explode
(
','
,
$unit_types
)
);
}
$query
->
orderBy
(
'type'
);
$query
->
range
(
$offset
,
$limit
);
$bat_units
=
$query
->
execute
()
->
fetchAll
();
$
units
=
array
(
);
$
bat_event_type
=
bat_event_type_load
(
$event_type
);
$
childrens
=
array
()
;
$
target_entity_type
=
$bat_event_type
->
target_entity_type
;
$c
reate_event_access
=
FALSE
;
$c
ontroller
=
entity_get_controller
(
$target_entity_type
)
;
if
(
bat_event_access
(
'create'
,
bat_event_create
(
array
(
'type'
=>
$event_type
))))
{
$create_event_access
=
TRUE
;
}
$units
=
array
();
foreach
(
$bat_units
as
$unit
)
{
foreach
(
$types
as
$type
)
{
$entities
=
$controller
->
getReferencedIds
(
$type
,
$unit_ids
);
$childrens
[
$unit
->
type_id
][]
=
array
(
'id'
=>
'S'
.
$unit
->
unit_id
,
'title'
=>
$unit
->
name
,
'create_event'
=>
$create_event_access
,
);
}
$childrens
=
array
();
foreach
(
$childrens
as
$type_id
=>
$children
)
{
$unit_type
=
bat_type_load
(
$type_id
);
foreach
(
$entities
as
$entity
)
{
$childrens
[
$entity
[
'type_id'
]][]
=
array
(
'id'
=>
'S'
.
$entity
[
'id'
],
'title'
=>
$entity
[
'name'
],
'create_event'
=>
$create_event_access
,
);
}
$units
[]
=
array
(
'id'
=>
$unit_type
->
type_id
,
'title'
=>
$unit_type
->
name
,
'children'
=>
$children
,
);
foreach
(
$childrens
as
$type_id
=>
$children
)
{
$unit_type
=
bat_type_load
(
$type_id
);
$units
[]
=
array
(
'id'
=>
$unit_type
->
type_id
,
'title'
=>
$unit_type
->
name
,
'children'
=>
$children
,
);
}
}
return
$units
;
...
...
@@ -622,7 +628,15 @@ function bat_api_services_events_index($target_ids, $target_types, $target_entit
* @param $event_types
*/
function
bat_api_services_events_index_calendar
(
$unit_ids
,
$unit_types
,
$start_date
,
$end_date
,
$event_types
,
$background
)
{
$unit_types
=
(
$unit_types
==
'all'
)
?
array
()
:
array_filter
(
explode
(
','
,
$unit_types
));
if
(
$unit_types
==
'all'
)
{
$unit_types
=
array
();
foreach
(
bat_unit_get_types
()
as
$type
=>
$info
)
{
$unit_types
[]
=
$type
;
}
}
else
{
$unit_types
=
array_filter
(
explode
(
','
,
$unit_types
));
}
if
(
$event_types
==
'all'
)
{
$types
=
array
();
...
...
@@ -640,6 +654,10 @@ function bat_api_services_events_index_calendar($unit_ids, $unit_types, $start_d
// Get the event type definition from Drupal
$bat_event_type
=
bat_event_type_load
(
$type
);
$target_entity_type
=
$bat_event_type
->
target_entity_type
;
$controller
=
entity_get_controller
(
$target_entity_type
);
// For each type of event create a state store and an event store
$event_store
=
new
DrupalDBStore
(
$type
,
DrupalDBStore
::
BAT_EVENT
);
...
...
@@ -657,48 +675,40 @@ function bat_api_services_events_index_calendar($unit_ids, $unit_types, $start_d
$ids
=
array_filter
(
explode
(
','
,
$unit_ids
));
// Get all units for a given type
$query
=
db_select
(
'bat_units'
,
'n'
)
->
fields
(
'n'
,
array
(
'unit_id'
,
'type'
,
'name'
));
// and optionally limit to specific ids if defined in API call
if
(
!
empty
(
$ids
))
{
$query
->
condition
(
'unit_id'
,
$ids
,
'IN'
);
}
// and types
if
(
!
empty
(
$unit_types
))
{
$query
->
condition
(
'type_id'
,
$unit_types
,
'IN'
);
}
$query
->
orderBy
(
'unit_id'
);
$bat_units
=
$query
->
execute
()
->
fetchAll
();
foreach
(
$unit_types
as
$unit_type
)
{
$entities
=
$controller
->
getReferencedIds
(
$unit_type
,
$unit_ids
);
// Create an array of unit objects - the default value is set to 0 since we want
// to know if the value in the database is actually 0. This will allow us to identify
// which events are represented by events in the database (i.e. have a value different to 0)
$units
=
array
();
foreach
(
$bat_units
as
$unit
)
{
$units
[]
=
new
Unit
(
$unit
->
unit_id
,
0
);
}
$childrens
=
array
();
if
(
!
empty
(
$units
))
{
$event_calendar
=
new
Calendar
(
$units
,
$event_store
);
// Create an array of unit objects - the default value is set to 0 since we want
// to know if the value in the database is actually 0. This will allow us to identify
// which events are represented by events in the database (i.e. have a value different to 0)
$units
=
array
();
foreach
(
$entities
as
$entity
)
{
$units
[]
=
new
Unit
(
$entity
[
'id'
],
0
);
}
$event_ids
=
$event_calendar
->
getEvents
(
$start_date_object
,
$end_date_object
);
if
(
!
empty
(
$units
))
{
$event_calendar
=
new
Calendar
(
$units
,
$event_store
);
// @TODO - this is an undeclared dependency of bat_event_ui
if
(
$bat_event_type
->
fixed_event_states
)
{
$event_formatter
=
new
FullCalendarFixedStateEventFormatter
(
$bat_event_type
,
$background
);
}
else
{
$event_formatter
=
new
FullCalendarOpenStateEventFormatter
(
$bat_event_type
,
$background
);
}
$event_ids
=
$event_calendar
->
getEvents
(
$start_date_object
,
$end_date_object
);
foreach
(
$event_ids
as
$unit_id
=>
$unit_events
)
{
foreach
(
$unit_events
as
$key
=>
$event
)
{
$events_json
[]
=
array
(
'id'
=>
(
string
)
$key
.
$unit_id
,
'bat_id'
=>
$event
->
getValue
(),
'resourceId'
=>
'S'
.
$unit_id
,
)
+
$event
->
toJson
(
$event_formatter
);
// @TODO - this is an undeclared dependency of bat_event_ui
if
(
$bat_event_type
->
fixed_event_states
)
{
$event_formatter
=
new
FullCalendarFixedStateEventFormatter
(
$bat_event_type
,
$background
);
}
else
{
$event_formatter
=
new
FullCalendarOpenStateEventFormatter
(
$bat_event_type
,
$background
);
}
foreach
(
$event_ids
as
$unit_id
=>
$unit_events
)
{
foreach
(
$unit_events
as
$key
=>
$event
)
{
$events_json
[]
=
array
(
'id'
=>
(
string
)
$key
.
$unit_id
,
'bat_id'
=>
$event
->
getValue
(),
'resourceId'
=>
'S'
.
$unit_id
,
)
+
$event
->
toJson
(
$event_formatter
);
}
}
}
}
...
...
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