Skip to content

Commit 6de9e37

Browse files
committed
Merge remote-tracking branch 'origin/feature/WN-174' into feature/WN-174
# Conflicts: # app/Classes/Repositories/WhatNowRepository.php # app/Models/WhatNowEntityStage.php # database/migrations/2023_01_20_094214_create_key_messages_table.php # database/migrations/2025_02_10_002000_update_enum_stage_in_whatnow_entity_stages_table.php # database/seeds/WhatNowTableSeeder.php
2 parents 793a6a2 + c5105f7 commit 6de9e37

23 files changed

+317
-172
lines changed

.env.bitbucket-pipelines

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ DB_DATABASE=redcross_local
1313
DB_USERNAME=preparecenter
1414
DB_PASSWORD=preparecenter
1515

16-
STATS_DB_HOST=0.0.0.0
17-
STATS_DB_PORT=3307
18-
STATS_DB_DATABASE=redcross_logs
19-
STATS_DB_USERNAME=preparecenter
20-
STATS_DB_PASSWORD=preparecenter
21-
2216
BROADCAST_DRIVER=log
2317
CACHE_DRIVER=file
2418
QUEUE_CONNECTION=sync

.env.example

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ DB_DATABASE=preparecenter
1313
DB_USERNAME=preparecenter
1414
DB_PASSWORD=preparecenter
1515

16-
STATS_DB_HOST=mysql_stats
17-
STATS_DB_PORT=3306
18-
STATS_DB_DATABASE=usage_logs
19-
STATS_DB_USERNAME=preparecenter
20-
STATS_DB_PASSWORD=preparecenter
21-
2216
BROADCAST_DRIVER=log
2317
CACHE_DRIVER=file
2418
QUEUE_CONNECTION=sync

app/Classes/Feeds/WhatNowFeed.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Classes\Serializers\CustomDataSerializer;
1010
use App\Classes\Transformers\WhatNowEntityTransformer;
1111
use App\Models\Organisation;
12+
use App\Models\Region;
1213
use App\Models\WhatNowEntity;
1314

1415
class WhatNowFeed implements JsonFeedInterface
@@ -18,6 +19,11 @@ class WhatNowFeed implements JsonFeedInterface
1819
*/
1920
protected $language;
2021

22+
/**
23+
* @var Region
24+
*/
25+
protected $region;
26+
2127
/**
2228
* @var Organisation
2329
*/
@@ -85,14 +91,23 @@ public function setOrganisation(Organisation $org)
8591
}
8692

8793
/**
88-
* @param string $lang
94+
* @param null $region
8995
* @return $this
9096
*/
91-
public function setLanguage($lang = 'en_US')
97+
public function setRegion(Region $region = null)
9298
{
93-
// @todo validate locale
94-
$this->language = $lang;
99+
$this->region = $region;
100+
return $this;
101+
}
95102

103+
/**
104+
* @param string $lang
105+
* @return $this
106+
*/
107+
public function setLanguage($lang = null)
108+
{
109+
$this->language = $lang ? substr($lang, 0, 2) : null;
110+
$this->transformer->setLang($this->language);
96111
return $this;
97112
}
98113

@@ -118,7 +133,8 @@ public function loadData()
118133
$data = $this->whatNowRepo->findItemsForOrgId(
119134
$this->organisation->id,
120135
$this->language,
121-
$this->filterEventTypes
136+
$this->filterEventTypes,
137+
$this->region->id ?? null
122138
);
123139

124140
if ($data instanceof Collection) {

app/Classes/Repositories/RegionRepository.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
11
<?php
2-
32
namespace App\Classes\Repositories;
43

4+
use App\Models\Region;
5+
6+
57
class RegionRepository implements RegionRepositoryInterface
68
{
9+
/**
10+
* @var Region
11+
*/
12+
protected $regModel;
13+
14+
/**
15+
* @param Region $regionModel
16+
*/
17+
public function __construct(Region $regModel)
18+
{
19+
$this->regModel = $regModel;
20+
}
21+
22+
/**
23+
* @param array $attributes
24+
* @return static
25+
*/
26+
public function newInstance(array $attributes = [])
27+
{
28+
return $this->regModel->newInstance($attributes);
29+
}
30+
31+
32+
public function findBySlug($orgId, $slug)
33+
{
34+
$slug = strtolower($slug);
35+
$slug = str_replace(' ', '-', $slug);
36+
return $this->regModel->where('slug', $slug)->where('organisation_id', $orgId)->firstOrFail();
37+
}
738

839
public function mapTranslationInput($regionId, $language_code, $data)
940
{

app/Classes/Repositories/RegionRepositoryInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44

55
interface RegionRepositoryInterface
66
{
7+
/**
8+
* @param $regionName
9+
* @return mixed
10+
*/
11+
public function findBySlug($orgId, $slug);
712

813
}

app/Classes/Repositories/UsageLogRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getForEndpoint($endpoint, $fromDate = null, $toDate = null)
8686

8787
public function listByEndpoint($fromDate = null, $toDate = null)
8888
{
89-
$query = DB::connection('stats_mysql')->table('usage_logs')
89+
$query = DB::table('usage_logs')
9090
->select('endpoint', 'application_id', DB::raw('count(*) as hit_count'))
9191
->groupBy('application_id', 'endpoint')
9292
->orderBy('hit_count', 'desc');

app/Classes/Repositories/WhatNowRepository.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
class WhatNowRepository implements WhatNowRepositoryInterface
1010
{
1111
public const EVENT_STAGES = [
12-
'immediate',
1312
'warning',
13+
'immediate',
14+
'recover',
1415
'anticipated',
1516
'assess_and_plan',
1617
'mitigate_risks',
1718
'prepare_to_respond',
18-
'recover'
19+
20+
1921
];
2022

2123
/**
@@ -54,7 +56,7 @@ public function all($columns = ['*'])
5456
return $this->whatNowModel->all($columns);
5557
}
5658

57-
/**
59+
/**
5860
* @param array $attributes
5961
* @return WhatNowEntity
6062
*/
@@ -149,14 +151,18 @@ public function destroy($id)
149151
* @param null $lang
150152
* @param array $eventTypes
151153
*/
152-
public function findItemsForOrgId($orgId, $lang = null, array $eventTypes = [])
154+
public function findItemsForOrgId($orgId, $lang = null, array $eventTypes = [], $regId = null)
153155
{
154156
$query = $this->whatNowModel->where('org_id', $orgId);
155157

156158
if (count($eventTypes)) {
157159
$query->whereIn('event_type', $eventTypes);
158160
}
159161

162+
if ($regId) {
163+
$query->where('region_id', $regId);
164+
}
165+
160166
return $query->get();
161167
}
162168

app/Classes/Repositories/WhatNowRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface WhatNowRepositoryInterface extends RepositoryInterface
99
* @param null $lang
1010
* @param array $eventTypes
1111
*/
12-
public function findItemsForOrgId($orgId, $lang = null, array $eventTypes = []);
12+
public function findItemsForOrgId($orgId, $lang = null, array $eventTypes = [], $regionName = null);
1313

1414
/**
1515
* @param $orgId

app/Classes/Repositories/WhatNowTranslationRepository.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,23 @@ public function getLatestTranslations($id)
152152
* @param $id
153153
* @return \Illuminate\Database\Eloquent\Collection
154154
*/
155-
public function getLatestPublishedTranslations($id)
155+
public function getLatestPublishedTranslations($id, $lang = null)
156156
{
157157
$model = $this->whatNowTranslationModel;
158158

159-
return $model::fromQuery(DB::raw('SELECT wet1.*
160-
FROM whatnow_entity_translations wet1
161-
LEFT JOIN whatnow_entity_translations wet2 ON wet1.entity_id = wet2.entity_id AND wet1.language_code = wet2.language_code AND wet1.published_at < wet2.published_at
162-
WHERE wet2.published_at IS NULL AND wet1.entity_id = :entityId AND wet1.published_at IS NOT NULL'), ['entityId' => $id]);
159+
$query = 'SELECT wet1.*
160+
FROM whatnow_entity_translations wet1
161+
LEFT JOIN whatnow_entity_translations wet2 ON wet1.entity_id = wet2.entity_id AND wet1.language_code = wet2.language_code AND wet1.published_at < wet2.published_at
162+
WHERE wet2.published_at IS NULL AND wet1.entity_id = :entityId AND wet1.published_at IS NOT NULL';
163+
164+
$bindings = ['entityId' => $id];
165+
166+
if ($lang !== null) {
167+
$query .= ' AND wet1.language_code = :lang';
168+
$bindings['lang'] = $lang;
169+
}
170+
171+
return $model::fromQuery(DB::raw($query), $bindings);
163172
}
164173

165174
/**

app/Classes/Repositories/WhatNowTranslationRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getLatestTranslations($id);
2323
* @param $id
2424
* @return \Illuminate\Database\Eloquent\Collection
2525
*/
26-
public function getLatestPublishedTranslations($id);
26+
public function getLatestPublishedTranslations($id, $lang = null);
2727

2828
/**
2929
* @param array $ids

0 commit comments

Comments
 (0)