Commit b4e2a080 authored by nicola85's avatar nicola85

Code style

parent d68e43dd
......@@ -9,17 +9,17 @@ function hook_install() {
$resources = $rest->get('resources');
$resources['entity:bat_event'] = array(
'PATCH' => array(
'supported_formats' => array(
$resources['entity:bat_event'] = [
'PATCH' => [
'supported_formats' => [
'hal_json',
'json',
),
'supported_auth' => array(
],
'supported_auth' => [
'cookie',
),
),
);
],
],
];
$rest->set('resources', $resources)->save(TRUE);
}
......@@ -94,7 +94,7 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
$end_date = $request->query->get('end');
if ($unit_types == 'all') {
$unit_types = array();
$unit_types = [];
foreach (bat_unit_get_types() as $type => $info) {
$unit_types[] = $type;
}
......@@ -104,7 +104,7 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
}
if ($event_types == 'all') {
$types = array();
$types = [];
foreach (bat_event_get_types() as $type => $info) {
$types[] = $type;
}
......@@ -113,7 +113,7 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
$types = array_filter(explode(',', $event_types));
}
$events_json = array();
$events_json = [];
foreach ($types as $type) {
// Check if user has permission to view calendar data for this event type.
......@@ -138,7 +138,7 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
$today = new \DateTime();
if (!\Drupal::currentUser()->hasPermission('view past event information') && $today > $start_date_object) {
if ($today > $end_date_object) {
$return->events = array();
$return->events = [];
return $return;
}
$start_date_object = $today;
......@@ -149,12 +149,12 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
foreach ($unit_types as $unit_type) {
$entities = $this->getReferencedIds($unit_type, $ids);
$childrens = array();
$childrens = [];
// 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();
$units = [];
foreach ($entities as $entity) {
$units[] = new Unit($entity['id'], 0);
}
......@@ -173,11 +173,11 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
foreach ($event_ids as $unit_id => $unit_events) {
foreach ($unit_events as $key => $event) {
$events_json[] = array(
$events_json[] = [
'id' => (string) $key . $unit_id,
'bat_id' => $event->getValue(),
'resourceId' => 'S' . $unit_id,
) + $event->toJson($event_formatter);
] + $event->toJson($event_formatter);
}
}
}
......@@ -187,22 +187,22 @@ class CalendarEventsIndex extends ServiceDefinitionBase implements ContainerFact
return $events_json;
}
public function getReferencedIds($unit_type, $ids = array()) {
public function getReferencedIds($unit_type, $ids = []) {
$query = db_select('unit', 'n')
->fields('n', array('id', 'unit_type_id', 'type', 'name'));
->fields('n', ['id', 'unit_type_id', 'type', 'name']);
if (!empty($ids)) {
$query->condition('id', $ids, 'IN');
}
$query->condition('unit_type_id', $unit_type);
$bat_units = $query->execute()->fetchAll();
$units = array();
$units = [];
foreach ($bat_units as $unit) {
$units[] = array(
$units[] = [
'id' => $unit->id,
'name' => $unit->name,
'type_id' => $unit_type,
);
];
}
return $units;
......
......@@ -96,7 +96,7 @@ class EventsIndex extends ServiceDefinitionBase implements ContainerFactoryPlugi
$types = array_filter(explode(',', $event_types));
$events_json = array();
$events_json = [];
foreach ($types as $type) {
$database = Database::getConnectionInfo('default');
......@@ -110,7 +110,7 @@ class EventsIndex extends ServiceDefinitionBase implements ContainerFactoryPlugi
$today = new \DateTime();
if (!\Drupal::currentUser()->hasPermission('view past event information') && $today > $start_date_object) {
if ($today > $end_date_object) {
return array();
return [];
}
$start_date_object = $today;
......@@ -118,7 +118,7 @@ class EventsIndex extends ServiceDefinitionBase implements ContainerFactoryPlugi
$ids = explode(',', $target_ids);
$units = array();
$units = [];
foreach ($ids as $id) {
if ($target_entity = entity_load($target_entity_type, $id)) {
if (in_array($target_entity->type, $target_types) || empty($target_types)) {
......@@ -143,11 +143,11 @@ class EventsIndex extends ServiceDefinitionBase implements ContainerFactoryPlugi
foreach ($event_ids as $unit_id => $unit_events) {
foreach ($unit_events as $key => $event) {
$events_json[] = array(
$events_json[] = [
'id' => (string) $key . $unit_id,
'bat_id' => $event->getValue(),
'resourceId' => 'S' . $unit_id,
) + $event->toJson($event_formatter);
] + $event->toJson($event_formatter);
}
}
}
......
......@@ -89,7 +89,7 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
$event_states = $request->query->get('event_states');
if ($unit_types == 'all') {
$unit_types = array();
$unit_types = [];
foreach (bat_unit_get_types() as $type => $info) {
$unit_types[] = $type;
}
......@@ -100,7 +100,7 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
$states = array_filter(explode(',', $event_states));
$events_json = array();
$events_json = [];
// Get the event type definition from Drupal
$bat_event_type = bat_event_type_load($event_type);
......@@ -116,7 +116,7 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
$today = new \DateTime();
if (!\Drupal::currentUser()->hasPermission('view past event information') && $today > $start_date_object) {
if ($today > $end_date_object) {
$return->events = array();
$return->events = [];
return $return;
}
$start_date_object = $today;
......@@ -125,18 +125,18 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
foreach ($unit_types as $unit_type) {
$entities = $this->getReferencedIds($unit_type);
$childrens = array();
$childrens = [];
$units = array();
$units = [];
foreach ($entities as $entity) {
$target_entity = entity_load($target_entity_type, $entity['id']);
$units[] = new Unit($entity['id'], $target_entity->getEventDefaultValue($event_type));
}
if (!empty($units)) {
$dates = array(
$dates = [
$end_date_object->getTimestamp() => $end_date_object,
);
];
$calendar = new Calendar($units, $state_store);
......@@ -157,7 +157,7 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
$ed = clone($dates[$i + 1]);
$ed->sub(new \DateInterval('PT1M'));
$response = $calendar->getMatchingUnits($sd, $ed, $states, array(), FALSE, FALSE);
$response = $calendar->getMatchingUnits($sd, $ed, $states, [], FALSE, FALSE);
if (count(array_keys($response->getIncluded()))) {
$color = 'green';
......@@ -165,7 +165,7 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
else {
$color = 'red';
}
$events_json[] = array(
$events_json[] = [
'id' => $unit_type,
'resourceId' => $unit_type,
'start' => $sd->format('Y-m-d') . 'T' . $sd->format('H:i:00'),
......@@ -174,7 +174,7 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
'rendering' => 'background',
'blocking' => 0,
'title' => '',
);
];
}
}
}
......@@ -184,22 +184,22 @@ class MatchingUnitIndex extends ServiceDefinitionBase implements ContainerFactor
return array_values($events_json);
}
public function getReferencedIds($unit_type, $ids = array()) {
public function getReferencedIds($unit_type, $ids = []) {
$query = db_select('unit', 'n')
->fields('n', array('id', 'unit_type_id', 'type', 'name'));
->fields('n', ['id', 'unit_type_id', 'type', 'name']);
if (!empty($ids)) {
$query->condition('id', $ids, 'IN');
}
$query->condition('unit_type_id', $unit_type);
$bat_units = $query->execute()->fetchAll();
$units = array();
$units = [];
foreach ($bat_units as $unit) {
$units[] = array(
$units[] = [
'id' => $unit->id,
'name' => $unit->name,
'type_id' => $unit_type,
);
];
}
return $units;
......
......@@ -86,14 +86,14 @@ class UnitIndex extends ServiceDefinitionBase implements ContainerFactoryPluginI
$return_children = TRUE;
$create_event_access = FALSE;
if (bat_event_access(bat_event_create(array('type' => $event_type)), 'create', \Drupal::currentUser()) == AccessResult::allowed()) {
if (bat_event_access(bat_event_create(['type' => $event_type]), 'create', \Drupal::currentUser()) == AccessResult::allowed()) {
$create_event_access = TRUE;
}
$ids = array_filter(explode(',', $unit_ids));
if ($unit_types == 'all') {
$types = array();
$types = [];
foreach (bat_unit_get_types() as $type) {
$type_bundle = bat_type_bundle_load($type->bundle());
......@@ -112,36 +112,36 @@ class UnitIndex extends ServiceDefinitionBase implements ContainerFactoryPluginI
$target_entity_type = $bat_event_type->target_entity_type;
$units = array();
$units = [];
foreach ($types as $type) {
$entities = $this->getReferencedIds($type, $ids);
$childrens = array();
$childrens = [];
foreach ($entities as $entity) {
$childrens[$entity['type_id']][] = array(
$childrens[$entity['type_id']][] = [
'id' => 'S' . $entity['id'],
'title' => $entity['name'],
'create_event' => $create_event_access,
);
];
}
foreach ($childrens as $type_id => $children) {
$unit_type = bat_type_load($type_id);
if ($return_children) {
$units[] = array(
$units[] = [
'id' => $unit_type->id(),
'title' => $unit_type->label(),
'children' => $children,
);
];
}
else {
$units[] = array(
$units[] = [
'id' => $unit_type->id(),
'title' => $unit_type->label(),
);
];
}
}
}
......@@ -149,22 +149,22 @@ class UnitIndex extends ServiceDefinitionBase implements ContainerFactoryPluginI
return $units;
}
public function getReferencedIds($unit_type, $ids = array()) {
public function getReferencedIds($unit_type, $ids = []) {
$query = db_select('unit', 'n')
->fields('n', array('id', 'unit_type_id', 'type', 'name'));
->fields('n', ['id', 'unit_type_id', 'type', 'name']);
if (!empty($ids)) {
$query->condition('id', $ids, 'IN');
}
$query->condition('unit_type_id', $unit_type);
$bat_units = $query->execute()->fetchAll();
$units = array();
$units = [];
foreach ($bat_units as $unit) {
$units[] = array(
$units[] = [
'id' => $unit->id,
'name' => $unit->name,
'type_id' => $unit_type,
);
];
}
return $units;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment