Skip to content

Commit 25716be

Browse files
author
LDFOUR\luisd
committed
WN-174
I updated WhatNowTranslationRepository to save the key message content into the new tables.
1 parent 93342ac commit 25716be

File tree

6 files changed

+229
-3
lines changed

6 files changed

+229
-3
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace App\Classes\Repositories;
4+
5+
use App\Models\KeyMessage;
6+
7+
8+
class KeyMessageRepository implements KeyMessageRepositoryInterface
9+
{
10+
11+
/**
12+
* @var KeyMessage
13+
*/
14+
protected $keyMessageModel;
15+
16+
/**
17+
* @param KeyMessage $keyMessageModel
18+
*/
19+
public function __construct(KeyMessage $keyMessageModel)
20+
{
21+
$this->keyMessageModel = $keyMessageModel;
22+
}
23+
24+
/**
25+
* @param array $attributes
26+
* @return static
27+
*/
28+
public function newInstance(array $attributes = [])
29+
{
30+
return $this->keyMessageModel->newInstance($attributes);
31+
}
32+
33+
/**
34+
* @param array $columns
35+
* @return \Illuminate\Database\Eloquent\Collection|static[]
36+
*/
37+
public function all($columns = ['*'])
38+
{
39+
return $this->keyMessageModel->all($columns);
40+
}
41+
42+
/**
43+
* @param array $attributes
44+
* @return static
45+
*/
46+
public function create(array $attributes)
47+
{
48+
return $this->keyMessageModel->create($attributes);
49+
}
50+
51+
/**
52+
* @param $id
53+
* @param array $columns
54+
* @return mixed
55+
*/
56+
public function find($id, $columns = ['*'])
57+
{
58+
return $this->keyMessageModel->findOrFail($id, $columns);
59+
}
60+
61+
/**
62+
* @param $id
63+
* @return int
64+
*/
65+
public function destroy($id)
66+
{
67+
return $this->keyMessageModel->destroy($id);
68+
}
69+
70+
/**
71+
* @param $id
72+
* @param array $input
73+
* @return mixed
74+
*/
75+
public function updateWithIdAndInput($id, array $input)
76+
{
77+
return $this->keyMessageModel->where('id', $id)->update($input);
78+
}
79+
80+
81+
/**
82+
* @param $stageId
83+
* @return mixed
84+
*/
85+
public function findItemsByStageId($stageId)
86+
{
87+
return $this->keyMessageModel->where('stage_id', $stageId)->get();
88+
}
89+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Classes\Repositories;
4+
5+
interface KeyMessageRepositoryInterface extends RepositoryInterface
6+
{
7+
8+
/**
9+
* @param $stageId
10+
* @return mixed
11+
*/
12+
public function findItemsByStageId($stageId);
13+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace App\Classes\Repositories;
4+
5+
use App\Models\SupportingMessage;
6+
7+
class SupportingMessageRepository implements SupportingMessageRepositoryInterface
8+
{
9+
10+
/**
11+
* @var SupportingMessage
12+
*/
13+
protected $suppotingMessageModel;
14+
15+
/**
16+
* @param SupportingMessage $model
17+
*/
18+
public function __construct(SupportingMessage $model)
19+
{
20+
$this->suppotingMessageModel = $model;
21+
}
22+
23+
/**
24+
* @param array $attributes
25+
* @return static
26+
*/
27+
public function newInstance(array $attributes = [])
28+
{
29+
return $this->suppotingMessageModel->newInstance($attributes);
30+
}
31+
32+
/**
33+
* @param array $columns
34+
* @return \Illuminate\Database\Eloquent\Collection|static[]
35+
*/
36+
public function all($columns = ['*'])
37+
{
38+
return $this->suppotingMessageModel->all($columns);
39+
}
40+
41+
/**
42+
* @param array $attributes
43+
* @return static
44+
*/
45+
public function create(array $attributes)
46+
{
47+
return $this->suppotingMessageModel->create($attributes);
48+
}
49+
50+
/**
51+
* @param $id
52+
* @param array $columns
53+
* @return mixed
54+
*/
55+
public function find($id, $columns = ['*'])
56+
{
57+
return $this->suppotingMessageModel->findOrFail($id, $columns);
58+
}
59+
60+
/**
61+
* @param $id
62+
* @return int
63+
*/
64+
public function destroy($id)
65+
{
66+
return $this->suppotingMessageModel->destroy($id);
67+
}
68+
69+
/**
70+
* @param $id
71+
* @param array $input
72+
* @return mixed
73+
*/
74+
public function updateWithIdAndInput($id, array $input)
75+
{
76+
return $this->suppotingMessageModel->where('id', $id)->update($input);
77+
}
78+
79+
public function findItemsByKeyMessageId($keyMessageId)
80+
{
81+
return $this->suppotingMessageModel->where('key_message_id', $keyMessageId)->get();
82+
}
83+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Classes\Repositories;
4+
5+
interface SupportingMessageRepositoryInterface extends RepositoryInterface
6+
{
7+
8+
/**
9+
* @param $keyMessageId
10+
* @return mixed
11+
*/
12+
public function findItemsByKeyMessageId($keyMessageId);
13+
}

app/Classes/Repositories/WhatNowTranslationRepository.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ class WhatNowTranslationRepository implements WhatNowTranslationRepositoryInterf
1515
*/
1616
protected $whatNowTranslationModel;
1717

18+
/** @var KeyMessageRepositoryInterface */
19+
protected $keyMessageRepository;
20+
21+
/** @var SupportingMessageRepositoryInterface */
22+
protected $supportingMessageRepository;
23+
1824
/**
1925
* @param WhatNowEntityTranslation $whatNowTranslationModel
2026
*/
21-
public function __construct(WhatNowEntityTranslation $whatNowTranslationModel)
27+
public function __construct(WhatNowEntityTranslation $whatNowTranslationModel, KeyMessageRepositoryInterface $keyMessageRepository, SupportingMessageRepositoryInterface $supportingMessageRepository)
2228
{
2329
$this->whatNowTranslationModel = $whatNowTranslationModel;
30+
$this->keyMessageRepository = $keyMessageRepository;
31+
$this->supportingMessageRepository = $supportingMessageRepository;
2432
}
2533

2634
/**
@@ -73,11 +81,23 @@ public function addTranslations(WhatNowEntity $entity, array $translations)
7381
if (empty($transStage)) {
7482
if (! empty($content)) {
7583
try {
76-
$translation->stages()->create([
84+
$stage = $translation->stages()->create([
7785
'language_code' => $trans['lang'],
7886
'stage' => $stage,
79-
'content' => json_encode($content),
8087
]);
88+
foreach ($content as $message) {
89+
$keyMessage = $this->keyMessageRepository->create([
90+
'entities_stage_id' => $stage->id,
91+
'title' => $message['title'],
92+
]);
93+
94+
foreach ($message['content'] as $supportMessage) {
95+
$this->supportingMessageRepository->create([
96+
'key_message_id' => $keyMessage->id,
97+
'content' => $supportMessage,
98+
]);
99+
}
100+
}
81101
} catch (\Exception $e) {
82102
Log::error('ERROR', [$e->getMessage()]);
83103
}

app/Providers/RepositoryServiceProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,13 @@ public function register()
4242
'App\Classes\Repositories\WhatNowTranslationRepositoryInterface',
4343
'App\Classes\Repositories\WhatNowTranslationRepository'
4444
);
45+
$this->app->bind(
46+
'App\Classes\Repositories\KeyMessageRepositoryInterface',
47+
'App\Classes\Repositories\KeyMessageRepository'
48+
);
49+
$this->app->bind(
50+
'App\Classes\Repositories\SupportingMessageRepositoryInterface',
51+
'App\Classes\Repositories\SupportingMessageRepository'
52+
);
4553
}
4654
}

0 commit comments

Comments
 (0)