/
collection.class.php
64 lines (56 loc) · 2.04 KB
/
collection.class.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
<?
class Oxygen_Entity_Collection extends Oxygen_Entity_Controller {
public function plural($n) {
if($n === 1) return 'item';
else return 'items';
}
public function configure($x) {
$ks = array();
foreach($this->model->meta['keys'][0] as $k=>$v){
$ks[] = '{'.$k.':url}';
};
$key = implode('/',$ks);
$x[$key]->Oxygen_Entity_Controller($this->model);
}
public function rpc_getMore($offset) {
$this->model = $this->model->slice($offset, 25);
return array(
'count'=>count($this->section('data')),
'embed'=>$this->embed_table_rows($this->getHeaders())
);
}
public function humanize($name) {
$x = str_replace('_', ' ', $name);
$x = preg_replace('/\s(en|ru|lv)$/','(\\1)',$x);
$x = preg_replace('/id$/','ID',$x);
$x = explode('.',$x);
array_shift($x);
return ucfirst(implode(' ', $x));
}
public function getHeaders() {
$result = array();
foreach ($this->model->meta['keys'] as $key) {
foreach ($key as $column) {
$result[$column] = array(
'name' => $this->humanize($column),
'mode' => 'link'
);
}
}
foreach($this->model->meta['select']['select'] as $column) {
if(!isset($result[$column])) {
$result[$column] = array(
'name' => $this->humanize($column),
'mode' => 'show'
);
}
}
foreach($this->model->meta['select']['update'] as $column) {
if(isset($result[$column]) && $result[$column]['mode'] === 'show') {
$result[$column]['mode'] = 'edit';
}
}
return $result;
}
}
?>