/
index.php
77 lines (73 loc) · 2.32 KB
/
index.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
<?php
/**
* @filesource modules/edocument/models/index.php
*
* @copyright 2016 Goragod.com
* @license https://www.kotchasan.com/license/
*
* @see https://www.kotchasan.com/
*/
namespace Edocument\Index;
use Gcms\Login;
use Kotchasan\Http\Request;
use Kotchasan\Language;
/**
* module=edocument
*
* @author Goragod Wiriya <admin@goragod.com>
*
* @since 1.0
*/
class Model extends \Kotchasan\Model
{
/**
* Query ข้อมูลสำหรับส่งให้กับ DataTable
* เฉพาะรายการที่มีสิทธิ์รับ
*
* @param array $params
*
* @return \Kotchasan\Database\QueryBuilder
*/
public static function toDataTable($params)
{
$where = array(
array('E.member_id', $params['member_id'])
);
if ($params['sender'] > 0) {
$where[] = array('A.sender_id', $params['sender']);
}
if ($params['urgency'] > -1) {
$where[] = array('A.urgency', $params['urgency']);
}
return static::createQuery()
->select('A.id', 'A.document_no', 'A.urgency', 'E.downloads', 'A.ext', 'A.topic', 'A.sender_id', 'A.last_update')
->from('edocument_download E')
->join('edocument A', 'INNER', array('A.id', 'E.document_id'))
->where($where)
->order('A.last_update DESC');
}
/**
* รับค่าจาก action (index.php)
*
* @param Request $request
*/
public function action(Request $request)
{
$ret = [];
// session, referer, member
if ($request->initSession() && $request->isReferer() && $login = Login::isMember()) {
if ($request->post('action')->toString() == 'detail') {
// แสดงรายละเอียดของเอกสาร
$document = \Edocument\View\Model::get($request->post('id')->toInt(), $login['id']);
if ($document) {
$ret['modal'] = Language::trans(\Edocument\View\View::create()->render($document, $login));
}
}
}
if (empty($ret)) {
$ret['alert'] = Language::get('Unable to complete the transaction');
}
// คืนค่าเป็น JSON
echo json_encode($ret);
}
}