1 |
6daefa8c
|
Petr Lukašík
|
<?php
|
2 |
|
|
class Names extends AppModel {
|
3 |
|
|
|
4 |
|
|
var $name = 'Names';
|
5 |
|
|
var $useTable = 'name';
|
6 |
|
|
var $primaryKey = 'id_name';
|
7 |
|
|
var $validate = array(
|
8 |
|
|
'id_name' => VALID_NOT_EMPTY,
|
9 |
|
|
'name' => VALID_NOT_EMPTY,
|
10 |
|
|
);
|
11 |
|
|
|
12 |
|
|
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
13 |
|
|
var $hasAndBelongsToMany = array(
|
14 |
|
|
'Line' =>
|
15 |
|
|
array('className' => 'Line',
|
16 |
|
|
'joinTable' => 'name_line',
|
17 |
|
|
'foreignKey' => 'id_name',
|
18 |
|
|
'associationForeignKey' => 'id_line',
|
19 |
|
|
'conditions' => '',
|
20 |
|
|
'fields' => '',
|
21 |
|
|
'order' => '',
|
22 |
|
|
'limit' => '',
|
23 |
|
|
'offset' => '',
|
24 |
|
|
'unique' => '',
|
25 |
|
|
'finderQuery' => '',
|
26 |
|
|
'deleteQuery' => '',
|
27 |
|
|
'insertQuery' => ''
|
28 |
|
|
),
|
29 |
|
|
|
30 |
|
|
);
|
31 |
|
|
var $hasMany = array(
|
32 |
|
|
'Tag' => array(
|
33 |
|
|
'className' => 'Tag',
|
34 |
|
|
'exclusive' => '',
|
35 |
|
|
'dependent' => '',
|
36 |
|
|
'foreignKey' => 'id_tag',
|
37 |
|
|
'conditions' => '',
|
38 |
|
|
'order' => '',
|
39 |
|
|
'limit' => '',
|
40 |
|
|
'finderSql' => ''
|
41 |
|
|
),
|
42 |
|
|
'NameLine' => array(
|
43 |
|
|
'className' => 'NameLine',
|
44 |
|
|
'exclusive' => '',
|
45 |
|
|
'dependent' => '',
|
46 |
|
|
'foreignKey' => 'id_name',
|
47 |
|
|
'conditions' => '',
|
48 |
|
|
'order' => '',
|
49 |
|
|
'limit' => '',
|
50 |
|
|
'finderSql' => ''
|
51 |
|
|
),
|
52 |
|
|
);
|
53 |
|
|
|
54 |
|
|
function vratLineSimpleStrukturu(&$name) {
|
55 |
|
|
$ret = array();
|
56 |
|
|
foreach ($name['NameLine'] as $index => $nameLine) {
|
57 |
|
|
$line = $nameLine['Line'];
|
58 |
|
|
$ret[]= array(
|
59 |
|
|
"transliteration" => $line['transliteration'],
|
60 |
|
|
"bach" => $line['Surface']['Transliteration']['Book']['book_abrev'].", ".
|
61 |
|
|
$line['Surface']['Transliteration']['chapter'],
|
62 |
|
|
"line_number" => $line['line_number'],
|
63 |
|
|
"id_name_line" => $nameLine['id_name_line']);
|
64 |
|
|
}
|
65 |
|
|
return $ret;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
function priradKTagum(&$lines, &$tags) {
|
69 |
|
|
//return;
|
70 |
|
|
// pr($tags);
|
71 |
|
|
// pr(count($name['NameLine']));
|
72 |
|
|
//pr(count($names['Line']));
|
73 |
|
|
foreach ($tags as $index_tag => $tag) {
|
74 |
|
|
foreach ($lines as $index_line => $line) {
|
75 |
|
|
if (mb_strpos($line['transliteration'],$tag['Tag']['tag'] )>0) {
|
76 |
|
|
//pr($line['transliteration']." ... ".$tag['Tag']['tag']);
|
77 |
|
|
$tags[$index_tag]['Lines'][] = $line;
|
78 |
|
|
unset($lines[$index_line]);
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
// pr("nove:");
|
83 |
|
|
// pr($tags);
|
84 |
|
|
// pr(count($name['NameLine']));
|
85 |
|
|
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
function upravSeznamy($lines, &$name) {
|
89 |
|
|
//pr($lines);
|
90 |
|
|
$count = count($lines);
|
91 |
|
|
$k = array_keys($lines);
|
92 |
|
|
//pr($k);
|
93 |
|
|
for ($i = 0; $i < $count - 1; $i++) {
|
94 |
|
|
for ($j = 0; $j < $count - 1; $j++) {
|
95 |
|
|
$str1 = $this->getNameLine($lines[$k[$j]]['transliteration'],$name['Names']['name']);
|
96 |
|
|
$str2 = $this->getNameLine($lines[$k[$j+1]]['transliteration'],$name['Names']['name']);
|
97 |
|
|
$str1 = trim($str1);
|
98 |
|
|
$str2 = trim($str2);
|
99 |
|
|
//pr("$str1, $str2: ".strcmp($str1, $str2));
|
100 |
|
|
if (strcmp($str1, $str2) > 0) {
|
101 |
|
|
$temp = $lines[$k[$j]];
|
102 |
|
|
$lines[$k[$j]] = $lines[$k[$j+1]];
|
103 |
|
|
$lines[$k[$j+1]] = $temp;
|
104 |
|
|
|
105 |
|
|
//$this->array_move ($j,$j+1, $lines );
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
return $lines;
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
function getNameLine($lineText, $name) {
|
113 |
|
|
$sp = "[:space:]";
|
114 |
|
|
$regExp = add_bracket($name);
|
115 |
|
|
$regExp2 = "[$sp]*[^$sp]*".$regExp."[^$sp]*[$sp]*";
|
116 |
|
|
if(eregi($regExp2, $lineText, $regs)) {
|
117 |
|
|
$lineText = $regs[0];
|
118 |
|
|
}
|
119 |
|
|
$ret = eregi_replace($regExp, "\\0", $lineText);
|
120 |
|
|
|
121 |
|
|
return $ret;
|
122 |
|
|
}
|
123 |
|
|
function array_move($which, $where, &$array)
|
124 |
|
|
{
|
125 |
|
|
$tmp = array_splice($array, $which, 1);
|
126 |
|
|
array_splice($array, $where, 0, $tmp);
|
127 |
|
|
//return $array;
|
128 |
|
|
}
|
129 |
|
|
}
|