Skip to content
This repository was archived by the owner on Jan 1, 2021. It is now read-only.

Commit 959e9d4

Browse files
committed
Added language to title mappings.
1 parent 65a6ebc commit 959e9d4

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

app/Http/Controllers/API/MappingsController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ public function find(MappingFindRequest $request)
6060
}
6161

6262
$type = $request->query("type");
63+
$language = $request->query("language", "en");
6364

6465
$titles = [];
6566
$years = [];
6667

6768
if ($type == "title" || $type == "all" || $type == null)
6869
{
69-
$titles = Mapping::where("tmdbid", "=", $tmdbid)->where("info_type", "=", "title")->get()->toArray();
70+
$titles = Mapping::where("tmdbid", "=", $tmdbid)->where("info_type", "=", "title")->whereHas("title_info", function($query) use($language){
71+
$query->where("language", "=", $language);
72+
})->get()->toArray();
7073
}
7174

7275
if ($type == "year" || $type == "all" || $type == null)
@@ -100,11 +103,12 @@ public function add(MappingAddRequest $request) {
100103
if ($type == "title")
101104
{
102105
$aka_title = $request->get("aka_title");
106+
$title_language = $request->get("language", "en");
103107
$aka_clean_title = Helper::clean_title($aka_title);
104108
$existing = Mapping::whereHas("title_info", function($query) use($aka_clean_title){
105109
$query->where("aka_clean_title", "=", $aka_clean_title);
106110
})->first();
107-
$info = new TitleInfo(["aka_title" => $aka_title, "aka_clean_title" => $aka_clean_title]);
111+
$info = new TitleInfo(["aka_title" => $aka_title, "aka_clean_title" => $aka_clean_title, "language" => $title_language]);
108112
}
109113
else
110114
{

app/Http/Requests/MappingRequests.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function rules()
3434
'type' => array(
3535
"required",
3636
Rule::in(['title', 'year']),
37+
),
38+
'language' => array(
39+
Rule::in(['en', 'fr', 'es', 'de', 'it', 'da', 'nl', 'ja', 'ru', 'pl', 'vi', 'sv', 'no', 'fi', 'tr', 'pt', 'nl', 'el', 'ko', 'hu'])
3740
)
3841
];
3942

@@ -64,7 +67,8 @@ public function messages()
6467
"aka_year.required" => "The alternative year is required with type 'year'.",
6568
"aka_year.regex" => "The alternative year has to be a valid movie year.",
6669
"aka_title.required" => "The alternative title is required with type 'title'",
67-
"aka_title.regex" => "The alternative title must be at least 3 letters long"
70+
"aka_title.regex" => "The alternative title must be at least 3 letters long",
71+
"language.in" => "The language must be a valid ISO639-1 code."
6872
];
6973
}
7074

@@ -98,6 +102,9 @@ public function rules()
98102
"sometimes",
99103
"required",
100104
Rule::in(['title', 'year', 'all']),
105+
),
106+
'language' => array(
107+
Rule::in(['en', 'fr', 'es', 'de', 'it', 'da', 'nl', 'ja', 'ru', 'pl', 'vi', 'sv', 'no', 'fi', 'tr', 'pt', 'nl', 'el', 'ko', 'hu'])
101108
)
102109
];
103110

@@ -116,6 +123,7 @@ public function messages()
116123
'tmdbid.regex' => 'The format of the tmdbid given is invalid!',
117124
"type.required" => "The type of mappings to return is required.",
118125
"type.in" => "The type of mapping has to be on of 'title', 'year' or 'all'.",
126+
"language.in" => "The language must be a valid ISO639-1 code."
119127
];
120128
}
121129

app/Mapping.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class TitleInfo extends Model {
107107

108108
protected $connection = 'mappings_mysql';
109109

110-
protected $fillable = array('aka_title', "aka_clean_title");
110+
protected $fillable = array('aka_title', "aka_clean_title", "language");
111111

112112
/**
113113
* Indicates if the model should be timestamped.

0 commit comments

Comments
 (0)