1
|
<?php
|
2
|
class Transliteration extends AppModel {
|
3
|
|
4
|
var $name = 'Transliteration';
|
5
|
var $primaryKey = 'id_transliteration';
|
6
|
|
7
|
|
8
|
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
9
|
var $belongsTo = array(
|
10
|
'Book' =>
|
11
|
array('className' => 'Book',
|
12
|
'foreignKey' => 'id_book',
|
13
|
'conditions' => '',
|
14
|
'fields' => '',
|
15
|
'order' => '',
|
16
|
'counterCache' => ''
|
17
|
),
|
18
|
'Museum' =>
|
19
|
array('className' => 'Museum',
|
20
|
'foreignKey' => 'id_museum',
|
21
|
'conditions' => '',
|
22
|
'fields' => '',
|
23
|
'order' => '',
|
24
|
'counterCache' => ''
|
25
|
),
|
26
|
'Origin' =>
|
27
|
array('className' => 'Origin',
|
28
|
'foreignKey' => 'id_origin',
|
29
|
'conditions' => '',
|
30
|
'fields' => '',
|
31
|
'order' => '',
|
32
|
'counterCache' => ''
|
33
|
),
|
34
|
'BookType' =>
|
35
|
array('className' => 'BookType',
|
36
|
'foreignKey' => 'id_book_type',
|
37
|
'conditions' => '',
|
38
|
'fields' => '',
|
39
|
'order' => '',
|
40
|
'counterCache' => ''
|
41
|
),
|
42
|
|
43
|
);
|
44
|
/* var $hasMany = array(
|
45
|
'Reference' => array(
|
46
|
'className' => 'Reference',
|
47
|
'exclusive' => false,
|
48
|
'dependent' => true,
|
49
|
'foreignKey' => 'id_transliteration',
|
50
|
'conditions' => '',
|
51
|
'order' => 'Reference.series ASC',
|
52
|
'limit' => '',
|
53
|
'finderSql' => ''
|
54
|
)
|
55
|
);*/
|
56
|
|
57
|
function bindModelsForTables() {
|
58
|
$this->bindModel(
|
59
|
array(
|
60
|
'hasMany' => array(
|
61
|
'Surface' => array(
|
62
|
'className' => 'Surface',
|
63
|
'foreignKey' => 'id_transliteration',
|
64
|
)
|
65
|
)
|
66
|
)
|
67
|
);
|
68
|
$this->Surface->unbindModel( array('belongsTo' => array('Transliteration')));
|
69
|
|
70
|
$this->Surface->bindModel(
|
71
|
array(
|
72
|
'hasMany' => array(
|
73
|
'Line' => array(
|
74
|
'className' => 'Line',
|
75
|
'foreignKey' => 'id_surface',
|
76
|
)
|
77
|
),
|
78
|
'belongsTo' => array(
|
79
|
'SurfaceType' => array(
|
80
|
'className' => 'SurfaceType',
|
81
|
'foreignKey' => 'id_surface_type',
|
82
|
),
|
83
|
'ObjectType' => array(
|
84
|
'className' => 'ObjectType',
|
85
|
'foreignKey' => 'id_object_type',
|
86
|
)
|
87
|
),
|
88
|
)
|
89
|
);
|
90
|
}
|
91
|
|
92
|
function organizeLines($trans) {
|
93
|
$ret = array();
|
94
|
foreach ($trans as $surface) {
|
95
|
$ret[$surface['ObjectType']['object_type']]
|
96
|
[$surface['SurfaceType']['surface_type']]
|
97
|
['id_surface'] = $surface['id_surface'];
|
98
|
|
99
|
foreach ($surface['Line'] as $line) {
|
100
|
|
101
|
$ret[$surface['ObjectType']['object_type']]
|
102
|
[$surface['SurfaceType']['surface_type']]
|
103
|
['lines']
|
104
|
[$line['id_line']] =
|
105
|
array(
|
106
|
'line_number' => $line['line_number'],
|
107
|
'transliteration' => $line['transliteration'],
|
108
|
);
|
109
|
}
|
110
|
}
|
111
|
return $ret;
|
112
|
}
|
113
|
|
114
|
function saveSReferences($data = null, $validate = true, $fieldList = array()) {
|
115
|
//pr($_REQUEST);
|
116
|
//return;
|
117
|
$connection = new DB_Sql();
|
118
|
$POST = $_REQUEST;
|
119
|
$id_transliteration = $_REQUEST['data']['Transliteration']['id_transliteration'];
|
120
|
if (!empty($POST['series']) && is_array($POST['series'])) {
|
121
|
$dotaz = "DELETE FROM lit_reference WHERE id_transliteration = '$id_transliteration'";
|
122
|
$connection->query($dotaz);
|
123
|
foreach(array_keys($POST['series']) as $id) {
|
124
|
$dotaz = "INSERT INTO lit_reference(series, number, plate, id_transliteration) VALUES ('".
|
125
|
pg_escape_string($POST['series'][$id])."', '".
|
126
|
pg_escape_string($POST['number'][$id])."', '".
|
127
|
pg_escape_string($POST['page'][$id])."', '".
|
128
|
pg_escape_string($id_transliteration)."');";
|
129
|
$connection->query($dotaz);
|
130
|
}
|
131
|
}
|
132
|
|
133
|
return $this->save($data, $validate, $fieldList);
|
134
|
//pr($this->invalidFields());
|
135
|
}
|
136
|
|
137
|
function saveTexts($request) {
|
138
|
$Line = new Line();
|
139
|
foreach ($request['data'] as $object) {
|
140
|
foreach ($object as $surface) {
|
141
|
foreach ($surface['lines'] as $line) {
|
142
|
$Line->create();
|
143
|
$Line->save($line);
|
144
|
}
|
145
|
}
|
146
|
}
|
147
|
|
148
|
return true;
|
149
|
}
|
150
|
}
|