91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Contents_bookmark
|
|
*/
|
|
|
|
|
|
class Contents_bookmark extends CI_Controller
|
|
{
|
|
|
|
private $CI;
|
|
|
|
function __construct()
|
|
{
|
|
$this->CI = & get_instance();
|
|
|
|
}
|
|
|
|
function main()
|
|
{
|
|
|
|
if ( ! $this->CI->input->post_get('token')) {
|
|
$this->CI->apilib->make_error("토큰 값이 넘어오지 않았습니다");
|
|
}
|
|
$token = $this->CI->input->post_get('token');
|
|
|
|
|
|
$app_id = (int) trim($this->CI->input->post_get('app_id'));
|
|
if (empty($app_id)) {
|
|
$this->CI->apilib->make_error("어플 아이디가 넘어오지 않았습니다");
|
|
}
|
|
|
|
$con_id = (int) trim($this->CI->input->post('con_id'));
|
|
if (empty($con_id)) {
|
|
$this->CI->apilib->make_error("데이터 고유 아이디가 넘어오지 않았습니다");
|
|
}
|
|
|
|
$this->CI->load->model(array('Contents_model', 'User_model', 'Contents_bookmark_model'));
|
|
|
|
$sessionuser = $this->CI->User_model->get_by_token($app_id, $token);
|
|
if ( ! element('user_id', $sessionuser)) {
|
|
$this->CI->apilib->make_error("로그인 한 회원만 북마크 할 수 있습니다");
|
|
}
|
|
|
|
$contents = $this->CI->Contents_model->get_one($con_id);
|
|
if ( ! element('con_id', $contents)) {
|
|
$this->CI->apilib->make_error("존재하지 않는 컨텐츠입니다.");
|
|
}
|
|
|
|
$bookmarkwhere = array(
|
|
'con_id' => $con_id,
|
|
'user_id' => element('user_id', $sessionuser),
|
|
);
|
|
$bookmark = $this->CI->Contents_bookmark_model->get_one('', '', $bookmarkwhere);
|
|
if (element('bookmark_id', $bookmark)) {
|
|
$this->CI->Contents_bookmark_model->delete(element('bookmark_id', $bookmark));
|
|
$type = 'N';
|
|
}
|
|
if ( ! element('bookmark_id', $bookmark)) {
|
|
$insertdata = array(
|
|
'con_id' => element('con_id', $contents),
|
|
'app_id' => $app_id,
|
|
'user_id' => element('user_id', $sessionuser),
|
|
'target_user_id' => element('user_id', $contents),
|
|
'bookmark_at' => cdate('Y-m-d H:i:s'),
|
|
);
|
|
$bookmark_id = $this->CI->Contents_bookmark_model->insert($insertdata);
|
|
$type = 'Y';
|
|
}
|
|
|
|
$cwhere = array(
|
|
'con_id' => element('con_id', $contents),
|
|
);
|
|
$bookmark_count = $this->CI->Contents_bookmark_model->count_by($cwhere);
|
|
|
|
$arr = array(
|
|
'result' => 'ok',
|
|
'token' => $token,
|
|
'app_id' => $app_id,
|
|
'con_id' => $con_id,
|
|
'type' => $type,
|
|
'bookmark_count' => $bookmark_count,
|
|
);
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
}
|