/
orgs.php
112 lines (107 loc) · 3.65 KB
/
orgs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace CADB\App\api;
$Acl = "authenticated";
class orgs extends \CADB\Controller {
public function process() {
$this->params['output'] = 'json';
$context = \CADB\Model\Context::instance();
$fields = \CADB\Organize::getFieldInfo(1);
$this->fields = array();
foreach($fields as $f => $v) {
$this->fields[] = array('field' => 'f'.$f, 'subject' => $v['subject'],'type'=>$v['type'],'multiple'=>( $v['multiple'] ? true : false ),'cid'=>$v['cid']);
}
if($this->params['q'] && !mb_detect_encoding($this->params['q'],'UTF-8',true)) {
$this->params['q'] = mb_convert_encoding($this->params['q'],'utf-8','euckr');
}
if($this->params['oid']) {
$this->organize = \CADB\Organize::getOrganizeByOid($this->params['oid']);
if($this->organize) {
if(!$this->organize['f7']) {
$this->organize['f7'] = '정보없음';
}
$this->fields['owner'] = array('subject' => '운영자','type'=>'int','multiple'=>false);
if(\CADB\Privilege::checkOrganizes($this->organize)) {
$this->organize['owner'] = 1;
} else {
$this->organize['owner'] = 0;
}
$agreement = \CADB\Agreement::getAgreementsByOid($this->params['oid']);
$this->fields['nid'] = array('subject' => '단체협약','type'=>'int','multiple'=>true);
$this->organize['nid'] = array();
if($agreement && is_array($agreement)) {
foreach($agreement as $ag) {
$this->organize['nid'][] = array(
'nid'=>$ag['nid'],
'did'=>$ag['did'],
'subject'=>$ag['subject']
);
}
}
$this->result = array(
'found'=>true
);
} else {
$this->result = array(
'found'=>false,
'error'=>'존재하지 않는 노조입니다.'
);
}
} else {
foreach($this->params as $k => $v) {
if(preg_match("/^p[0-9]+$/i",$k) || $k == 'pdepth') {
$this->search_mode = 'depth';
$args[$k] = $v;
} else if(preg_match("/^o[0-9]+$/i",$k)) {
$this->search_mode = 'args';
$args[$k] = $v;
}
}
if(!$this->params['page']) $this->params['page'] = 1;
\CADB\Organize::setMode($this->search_mode);
$total_cnt = \CADB\Organize::totalCnt($this->params['q'],$args);
$total_page = (int)( ( $total_cnt - 1 ) / ($this->params['limit'] ? $this->params['limit'] : 20) ) + 1;
$this->fields['owner'] = array('subject' => '운영자','type'=>'int','multiple'=>false);
$this->fields['nid'] = array('subject' => '단체협약','type'=>'int','multiple'=>true);
if($total_cnt && $this->params['page'] <= $total_page) {
$this->organize = \CADB\Organize::getList($this->params['q'],$this->params['page'],($this->params['limit'] ? $this->params['limit'] : 20),$args);
for($i=0; $i<count($this->organize); $i++) {
if(\CADB\Privilege::checkOrganizes($this->organize[$i])) {
$this->organize[$i]['owner'] = 1;
} else {
$this->organize[$i]['owner'] = 0;
}
$this->organize[$i]['nid'] = array();
$agreement = \CADB\Agreement::getAgreementsByOid( $this->organize[$i]['oid'], $this->organize[$i]['vid'] );
if($agreement && is_array($agreement)) {
foreach($agreement as $ag) {
$this->organize[$i]['nid'][] = array(
'nid'=>$ag['nid'],
'did'=>$ag['did'],
'subject'=>$ag['subject']
);
}
}
}
$this->result = array(
'orgs'=> array(
'total_cnt'=>$total_cnt,
'total_page'=>$total_page,
'page'=>$this->params['page'],
'count'=>@count($this->organize)
)
);
} else {
$this->result = array(
'orgs'=> array(
'total_cnt'=>$total_cnt,
'total_page'=>$total_page,
'page'=>$this->params['page'],
'count'=>0,
'error'=>'검색결과가 없습니다.'
)
);
}
}
}
}
?>