<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Contents_add_share_count
 */


class Contents_add_share_count 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_get('con_id'));
        if (empty($con_id)) {
			$this->CI->apilib->make_error("데이터 고유 아이디가 넘어오지 않았습니다");
        }

		$this->CI->load->model(array('Contents_model', 'User_model'));

		$sessionuser = $this->CI->User_model->get_by_token($app_id, $token);
		//if ( ! element('user_id', $sessionuser)) {
		//	$this->CI->apilib->make_error("로그인 한 회원만 Like 할 수 있습니다");
		//}

		$contents = $this->CI->Contents_model->get_one($con_id);
		if ( ! element('con_id', $contents)) {
			$this->CI->apilib->make_error("존재하지 않는 컨텐츠입니다.");
		}

		$this->CI->Contents_model->update_share_count(element('con_id', $contents));

		$share_count = element('con_share_count', $contents) + 1;

		$arr = array(
			'result' => 'ok',
			'token' => $token,
			'app_id' => $app_id,
			'con_id' => $con_id,
			'share_count' => $share_count,
		);
		return $arr;

	}


}
