-
Notifications
You must be signed in to change notification settings - Fork 0
/
Actions.php
99 lines (70 loc) · 3.07 KB
/
Actions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php namespace components\language; if(!defined('TX')) die('No direct access.');
class Actions extends \dependencies\BaseComponent
{
protected
$permissions = array(
'set_language' => 0
);
protected function set_language($data)
{
tx('Setting the application language', function()use($data){
tx('Sql')->table('language', 'Languages')->pk($data->language_id)->execute_single()->is('empty')
->success(function(){
throw new \exception\EmptyResult('Could not retrieve the language you were trying to set as application language. This could be because the given ID was invalid.');
})
->failure(function($language){
tx('Data')->session->tx->language->set($language->id);
});
});
tx('Url')->redirect('language_id=NULL');
}
protected function save_language($data)
{
tx('Saving a language', function()use($data){
$data->image_id = $data->image_id->otherwise(0);
//Save language.
tx('Sql')->table('language', 'Languages')->pk($data->id)->execute_single()->is('empty')
->success(function()use($data, &$language_id){
tx('Sql')->model('language', 'Languages')->set($data->having('valuta_symbol', 'decimal_mark', 'thousands_sep', 'code', 'shortcode', 'image_id'))->save();
$language_id = mysql_insert_id();
})
->failure(function($language)use($data, &$language_id){
$language->merge($data->having('valuta_symbol', 'decimal_mark', 'thousands_sep', 'code', 'shortcode', 'image_id'))->save();
$language_id = $language->id->get('int');
});
//Delete existing language info.
tx('Sql')->table('language', 'LanguageInfo')->where('language_id', $language_id)->execute()->each(function($row){
$row->delete();
});
//Save language info.
$data->info->each(function($info)use($data, $language_id){
$in_language_id = $info->key();
$info->each(function($val)use($info, $language_id, $in_language_id){
tx('Sql')->model('language', 'LanguageInfo')->set($info->having('title'))->merge(array('language_id' => $language_id, 'in_language_id' => $in_language_id))->save();
});
});
})->failure(function($info){
throw $info->exception;
});
tx('Url')->redirect('section=language/languages_list&language_id=NULL');
}
protected function delete_language($data)
{
tx('Deleting language.', function()use($data){
tx('Sql')->table('language', 'Languages')->pk($data->language_id)->execute_single()->not('set', function(){
throw new \exception\EmptyResult('Could not retrieve the language you were trying to delete. This could be because the ID was invalid.');
})
->delete();
tx('Sql')->table('language', 'LanguageInfo')->where('language_id', $data->language_id)->execute()->each(function($row){
$row->delete();
});
})
->failure(function($info){
tx('Controller')->message(array(
'error' => $info->get_user_message()
));
});
//It's useless to redirect, so exit here.
exit;
}
}