-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.php
135 lines (125 loc) · 4.33 KB
/
api.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Album;
class Controller_Api extends \Controller_Site_Api
{
protected $check_not_auth_action = array(
'get_list',
'get_member',
'get_slide',
);
public function before()
{
parent::before();
}
/**
* Get list
*
* @access public
* @return Response (html)
* @throws Exception in Controller_Base::controller_common_api
* @see Controller_Base::controller_common_api
*/
public function get_list()
{
$this->api_accept_formats = 'html';
$this->controller_common_api(function()
{
$member_id = (int)\Input::get('member_id', 0);
list($is_mypage, $member) = $member_id ? $this->check_auth_and_is_mypage($member_id, true) : array(null, false);
list($limit, $page) = $this->common_get_pager_list_params(conf('articles.limit', 'album'), conf('articles.limit_max', 'album'));
$data = Site_Model::get_albums($limit, $page, \Auth::check() ? $this->u->id : 0, $member, $is_mypage);
$this->set_response_body_api($data, '_parts/list');
});
}
/**
* Get list by member
*
* @access public
* @param int $member_id
* @return Response (html)
* @throws Exception in Controller_Base::controller_common_api
* @see Controller_Base::controller_common_api
*/
public function get_member($member_id = null)
{
$this->api_accept_formats = array('json', 'html');
$this->controller_common_api(function() use($member_id)
{
list($is_mypage, $member) = $member_id ? $this->check_auth_and_is_mypage($member_id, true) : array(null, false);
list($limit, $page) = $this->common_get_pager_list_params(conf('articles.limit', 'album'), conf('articles.limit_max', 'album'));
$params = array();
if ($select = (array)\Input::get('cols')) $params['select'] = $select;
if ($limit = \Input::get('limit')) $params['limit'] = $limit;
if (\Input::get('no_relateds')) $params['where'] = array(array('foreign_table', ''));
$data = Site_Model::get_albums($limit, $page, \Auth::check() ? $this->u->id : 0, $member, $is_mypage, $params, $this->format == 'json');
$this->set_response_body_api($data, $this->format == 'html' ? '_parts/list' : null);
});
}
/**
* Get note edit menu
*
* @access public
* @param int $id note id
* @return Response (html)
* @throws Exception in Controller_Base::controller_common_api
* @see Controller_Site_Api::api_get_menu_common
*/
public function get_menu($id = null)
{
return $this->api_get_menu_common('album', $id, true, 'image_item_');
}
/**
* Delete album
*
* @access public
* @param int $id target id
* @return Response(json)
* @throws Exception in Controller_Base::controller_common_api
* @see Controller_Base::controller_common_api
*/
public function post_delete($id = null)
{
return $this->api_delete_common('album', $id);
}
/**
* Update public_flag
*
* @access public
* @param int $id target id
* @return Response(html)
* @throws Exception in Controller_Base::controller_common_api
* @see Controller_Base::controller_common_api
*/
public function post_update_public_flag($id = null)
{
$this->api_accept_formats = 'html';
$this->controller_common_api(function() use($id)
{
$id = (int)$id;
if (\Input::post('id')) $id = (int)\Input::post('id');
$icon_only_flag = (int)\Input::post('icon_only_flag', 0);
$have_children_public_flag = (int)\Input::post('have_children_public_flag', 0);
$is_update_children_public_flag = (int)\Input::post('is_update_children_public_flag', 0);
$album = Model_Album::check_authority($id, $this->u->id, 'member');
if ($result = Site_Util::check_album_disabled_to_update($album->foreign_table))
{
throw new \DisableToUpdateException($result['message']);
}
list($public_flag, $model) = \Site_Util::validate_params_for_update_public_flag($album->public_flag);
\DB::start_transaction();
$album->update_public_flag_with_relations($public_flag, !empty($is_update_children_public_flag));
\DB::commit_transaction();
$data = array(
'model' => $model,
'id' => $id,
'public_flag' => $public_flag,
'is_mycontents' => true,
'without_parent_box' => true,
'view_icon_only' => $icon_only_flag,
'have_children_public_flag' => $have_children_public_flag,
'child_model' => 'album_image',
);
$this->set_response_body_api($data, '_parts/public_flag_selecter');
});
}
}