Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bat_api
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
bat_api
Commits
c29ef3aa
Commit
c29ef3aa
authored
9 years ago
by
Nicolò Caruso
Browse files
Options
Downloads
Patches
Plain Diff
Return units and events for fullcalendar scheduler
parent
dce83728
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bat_api.module
+129
-16
129 additions, 16 deletions
bat_api.module
bat_api.services.inc
+7
-0
7 additions, 0 deletions
bat_api.services.inc
with
136 additions
and
16 deletions
bat_api.module
+
129
−
16
View file @
c29ef3aa
...
@@ -261,46 +261,94 @@ function bat_api_services_resources() {
...
@@ -261,46 +261,94 @@ function bat_api_services_resources() {
),
),
);
);
$resources
[
'events2'
]
=
array
(
'operations'
=>
array
(
'index'
=>
array
(
'callback'
=>
'bat_api_services_events_index_calendar'
,
'help'
=>
t
(
'Returns an object containing availability information.'
),
'access arguments'
=>
array
(
'access availability index service'
),
'args'
=>
array
(
array
(
'name'
=>
'unit_ids'
,
'type'
=>
'string'
,
'description'
=>
t
(
'Unit IDs'
),
'source'
=>
array
(
'param'
=>
'unit_ids'
),
'optional'
=>
TRUE
,
),
array
(
'name'
=>
'unit_types'
,
'type'
=>
'string'
,
'description'
=>
t
(
'Unit Types'
),
'source'
=>
array
(
'param'
=>
'unit_types'
),
'optional'
=>
TRUE
,
),
array
(
'name'
=>
'start'
,
'type'
=>
'string'
,
'description'
=>
t
(
'Start date'
),
'source'
=>
array
(
'param'
=>
'start'
),
'optional'
=>
FALSE
,
),
array
(
'name'
=>
'end'
,
'type'
=>
'string'
,
'description'
=>
t
(
'End date'
),
'source'
=>
array
(
'param'
=>
'end'
),
'optional'
=>
FALSE
,
),
array
(
'name'
=>
'event_types'
,
'type'
=>
'string'
,
'description'
=>
t
(
'Type'
),
'source'
=>
array
(
'param'
=>
'event_types'
),
'optional'
=>
FALSE
,
),
),
),
),
);
return
$resources
;
return
$resources
;
}
}
function
bat_api_services_units_index_calendar
(
$unit_types
,
$unit_ids
,
$offset
,
$limit
)
{
function
bat_api_services_units_index_calendar
(
$unit_types
,
$unit_ids
,
$offset
,
$limit
)
{
$return
=
new
stdClass
();
$return
->
sessid
=
session_id
();
$ids
=
array_filter
(
explode
(
','
,
$unit_ids
));
$ids
=
array_filter
(
explode
(
','
,
$unit_ids
));
$types
=
array_filter
(
explode
(
','
,
$unit_types
));
$types
=
array_filter
(
explode
(
','
,
$unit_types
));
$query
=
db_select
(
'bat_units'
,
'n'
)
$query
=
db_select
(
'bat_units'
,
'n'
)
->
fields
(
'n'
,
array
(
'unit_id'
,
'type'
,
'
nam
e'
,
'
language'
,
'bookable'
,
'status'
,
'uid
'
));
->
fields
(
'n'
,
array
(
'unit_id'
,
'type
_id
'
,
'
typ
e'
,
'
name
'
));
if
(
!
empty
(
$ids
))
{
if
(
!
empty
(
$ids
))
{
$query
->
condition
(
'unit_id'
,
$ids
,
'IN'
);
$query
->
condition
(
'unit_id'
,
$ids
,
'IN'
);
}
}
if
(
!
empty
(
$types
))
{
if
(
!
empty
(
$types
))
{
$query
->
condition
(
'type'
,
$types
,
'IN'
);
$query
->
condition
(
'type
_id
'
,
$types
,
'IN'
);
}
}
$query
->
orderBy
(
'type'
);
$query
->
orderBy
(
'type'
);
$query
->
range
(
$offset
,
$limit
);
$query
->
range
(
$offset
,
$limit
);
$bat_units
=
$query
->
execute
()
->
fetchAll
();
$bat_units
=
$query
->
execute
()
->
fetchAll
();
$units
=
array
();
$units
=
array
();
foreach
(
$bat_units
as
$unit
)
{
if
(
!
isset
(
$units
[
$unit
->
type
]))
{
$units
[
$unit
->
type
]
=
array
(
'id'
=>
$unit
->
type
,
'title'
=>
$unit
->
type
,
);
}
$units
[
$unit
->
type
][
'children'
][]
=
array
(
$childrens
=
array
();
'id'
=>
$unit
->
unit_id
,
foreach
(
$bat_units
as
$unit
)
{
$childrens
[
$unit
->
type_id
][]
=
array
(
'id'
=>
'S'
.
$unit
->
unit_id
,
'title'
=>
$unit
->
name
,
'title'
=>
$unit
->
name
,
);
);
}
}
$return
->
units
=
$units
;
foreach
(
$childrens
as
$type_id
=>
$children
)
{
$unit_type
=
bat_type_load
(
$unit
->
type_id
);
return
$return
;
$units
[]
=
array
(
'id'
=>
$unit_type
->
type_id
,
'title'
=>
$unit_type
->
name
,
'children'
=>
$children
,
);
}
return
$units
;
}
}
/**
/**
...
@@ -485,3 +533,68 @@ function bat_api_services_events_index($unit_ids, $unit_types, $start_date, $end
...
@@ -485,3 +533,68 @@ function bat_api_services_events_index($unit_ids, $unit_types, $start_date, $end
return
$return
;
return
$return
;
}
}
function
bat_api_services_events_index_calendar
(
$unit_ids
,
$unit_types
,
$start_date
,
$end_date
,
$event_types
)
{
$unit_types
=
array_filter
(
explode
(
','
,
$unit_types
));
$types
=
array_filter
(
explode
(
','
,
$event_types
));
$events_json
=
array
();
foreach
(
$types
as
$type
)
{
$state_store
=
new
DrupalDBStore
(
$type
,
DrupalDBStore
::
BAT_STATE
);
$start_date_object
=
new
DateTime
(
$start_date
);
$end_date_object
=
new
DateTime
(
$end_date
);
$today
=
new
DateTime
();
if
(
!
user_access
(
'view past availability information'
)
&&
$today
>
$start_date_object
)
{
if
(
$today
>
$end_date_object
)
{
$return
->
events
=
array
();
return
$return
;
}
$start_date_object
=
$today
;
}
$ids
=
array_filter
(
explode
(
','
,
$unit_ids
));
$query
=
db_select
(
'bat_units'
,
'n'
)
->
fields
(
'n'
,
array
(
'unit_id'
,
'type'
,
'name'
));
if
(
!
empty
(
$ids
))
{
$query
->
condition
(
'unit_id'
,
$ids
,
'IN'
);
}
if
(
!
empty
(
$types
))
{
$query
->
condition
(
'type_id'
,
$unit_types
,
'IN'
);
}
$query
->
orderBy
(
'unit_id'
);
$bat_units
=
$query
->
execute
()
->
fetchAll
();
$units
=
array
();
foreach
(
$bat_units
as
$unit
)
{
if
(
$bat_unit
=
bat_unit_load
(
$unit
->
unit_id
))
{
$units
[]
=
new
Unit
(
$unit
->
unit_id
,
$bat_unit
->
getDefaultValue
(
$type
));
}
}
$index
=
1
;
if
(
!
empty
(
$units
))
{
$rc
=
new
Calendar
(
$units
,
$state_store
);
$events
=
$rc
->
getEvents
(
$start_date_object
,
$end_date_object
);
$event_formatter
=
new
FullCalendarEventFormatter
(
$type
);
foreach
(
$events
as
$unit_id
=>
$unit_events
)
{
foreach
(
$unit_events
as
$event
)
{
$events_json
[]
=
array
(
'id'
=>
(
string
)
$index
++
,
'resourceId'
=>
'S'
.
$unit_id
,
)
+
$event
->
toJson
(
$event_formatter
);
}
}
}
}
return
$events_json
;
}
This diff is collapsed.
Click to expand it.
bat_api.services.inc
+
7
−
0
View file @
c29ef3aa
...
@@ -65,6 +65,13 @@ function bat_api_default_services_endpoint() {
...
@@ -65,6 +65,13 @@ function bat_api_default_services_endpoint() {
),
),
),
),
),
),
'events2'
=>
array
(
'operations'
=>
array
(
'index'
=>
array
(
'enabled'
=>
'1'
,
),
),
),
'user'
=>
array
(
'user'
=>
array
(
'actions'
=>
array
(
'actions'
=>
array
(
'login'
=>
array
(
'login'
=>
array
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment